Question "In short, how to use GraphQL from the application to the application itself?" can be understood in two ways.
1) How to execute query document (ie. string) manualy?
If you want to directly execute a query you may use IRequestExecutor
. If you look at HttpGetMiddleware
you can see that this is how queries are executed. To get IRequestExecutor
take IRequestExecutorResolver
from the DI.
// From DI
IRequestExecutorResolver resolver = ...;
// See next snippet
IQueryRequest request = ...;
IRequestExecutor executor = await resolver.GetRequestExecutorAsync();
IExecutionResult result = await executor.ExecuteAsync(request);
Type IQueryRequest
represents a GraphQL request. In can be created using IQueryRequestBuilder
. If your resolvers user "special" dependencies you have to explicitly specify them shen creating the request. To check what counts as "special" dependenceis check DefaultHttpRequestInterceptor
. The same goes for if you are adding extra "special" dependencies in your own interceptor.
IQueryRequest request = new QueryRequestBuilder().SetQuery("query text as string").SetVariableValues(/* if your query needs varaibles */).Create();
2) How to use GraphQL client for .NET?
StrawberryShake is a .NET GraphQL client made by ChilliCream. This will can generate you .NET types for your queries and invoke queries through network. Esentially you can query from the GraphQL server on it's endpoint as any other public client even if you are doing it from the same process. I won't elaborate on this as the link I included shows you basic example (whereas directly using IRequestExecutor
is not described in docs).