Execute Queries NReco.GraphQL documentation
IGraphQLAdapter exposes two simple methods to execute a graphql query, by query-string:
var query = @"query { customers{ id name } }"; var queryResult = graphqlAdapter.ExecuteToJsonAsync(query, default(CancellationToken));or by composing GraphQLQuery structure that contains query, operation name ("query") and variables
var query = @" query($id:String) { customers(id: $id){ id name } } "; var variables = @" {\"id\":\"9574\"} "; var graphqlResult = await graphqlAdapter.ExecuteToJsonAsync( new GraphQLQuery { Query = query, OperationName = "query", Variables = variables.ToInputs() }, default(CancellationToken) );
The result will be exactly the same shape as the query. This is essential to GraphQL, because you always get back what you expect, and the server knows exactly what fields the client is asking for.
{ "data": { "customers": [ { "id": "9574", "name": "Alfreds Futterkiste" } } }