Im currently trying to call a field on graphql-query from code, without using the http layer. In a test case I had success using this snippet inside of a field resolver. The breakpoint hits.
var newContext = new ResolveFieldContext(context);
var query = context.ParentType;
var ticketQueryField = query.GetField("getTickets");
await (Task) ticketQueryField.Resolver.Resolve(context);
So I think its possible to fill the copied ResolveFieldContext with my real needed fields/arguments and call it like this. But its very ... complicated to fill the ResolveFieldContext by hand. So maybe there is a easier way to create the context. Like:
var newContext = new ResolveFieldContext("query test { getTickets(id: 1) { number, title } }");
That would be really awesome and in my real scenario there a more then just field which I want to access with the generated query.
Why I want to use the Graph like this? The Batch-Loader which we are using inside the GraphQL-Types are perfect for our needs.
You can execute a GraphQL query without http by using the
DocumentExecutordirectly, and providing your ownDocumentWriterif you want the data in a specific format. There is an extension method which returns JSON, but you can write your own.https://github.com/graphql-dotnet/graphql-dotnet/blob/master/src/GraphQL.NewtonsoftJson/DocumentWriter.cs
This is an example test base class for testing queries: https://github.com/graphql-dotnet/graphql-dotnet/blob/master/src/GraphQL.Tests/BasicQueryTestBase.cs
This is a console example that returns JSON, not using http.