.netgraphqlhotchocolate

Is it possible to use Hot Chocolate execution engine directly, without a web server?


Is it possible to run and call Hot Chocolate execution engine directly, without hosting it as a web server and calling it by HTTP?

I imagine something like this:

var query = ... ;// a GraphQl query string
var engine = new HotChocolate.Engine();
engine.Execute(query);

Solution

  • You can use approach described in the article about integration tests.

        var query = ... ;// a GraphQl query string
    
        IQueryExecutor executor = Schema.Create(c =>
        {
            c.RegisterQueryType<Query>();
        })
        .MakeExecutable();
    
        IReadOnlyQueryRequest request =
            QueryRequestBuilder.New()
                .SetQuery(query)
                .Create();
    
        IExecutionResult result = await executor.ExecuteAsync(request);