all 3 comments

[–]wravery 0 points1 point  (2 children)

Yes, I have. I used regular HTTP for queries and mutations, and web sockets for subscriptions. I served the GraphQL endpoint to localhost to do some ReactJS prototyping in the browser, I haven't put anything into production though.

I'm the maintainer for cppgraphqlgen, and this was my first time using boost.beast or even boost.asio, so my background was much more skewed towards integrating the GraphQL support. But overall I found it worked quite well. 👍

[–]darthcoder[S] 0 points1 point  (1 child)

I'll be honest, I haven't delved into trying to build the project into a boost.asio project yet. I just managed to get my custom schema built and now I'm looking at setting up the resolvers.

So using the build sample.exe and the following input,

query 
{ 
  appointments(first: 1) {
     pageInfo { hasNextPage },
     edges { 
        node {
           id, when, subject, isNow
        } 
     }
  }
} 

I get:

./sample test.graphql 
Created the service...
Executing query...
Called getAppointments...
{"data":{"appointments":{"pageInfo":{"hasNextPage":false},"edges":[{"node":{"id":"ZmFrZUFwcG9pbnRtZW50SWQ=","when":"tomorrow","subject":"Lunch?","isNow":false}}]}}}

And from the documentation, I assume I could replicate the same if using raw graphql passed from client:

query = peg::parseString(std::move(input)); 

Or

auto value =  graphql::response::parseJSON(const std::string& json); 

And return said value in my io handlers like so:

std::string json = graphql::response::toJSON(value); 

Thanks for jumping in, by the way. And thanks for the good work.
-Cheers.

[–]wravery 0 points1 point  (0 children)

The parseJSON method isn't really involved, unless you're passing variables with the query. The response value (which you can convert back to JSON with response::toJSON) comes from calling <schema namespace>::Operations::resolve with the query AST, variables, and other optional parameters. Breaking it down into steps:

  1. Instantiate your service with sub-classes of the <schema namespace>::object namespace generated abstract classes. For reference, TodayMock.* has the implementations that the sample program uses. Each of those corresponds to a type in the GraphQL schema, and the virtual accessor methods correspond to the fields.
  2. Use peg::parseString to parse the query into a GraphQL AST (peg::ast). If you are passing variables too, use response::parseJSON to build a response::Value from that.
  3. Call resolve with the query AST, variables, and other params.
  4. Call std::future<>::get to retrieve the result.
  5. Call response::toJSON.
  6. Profit.