Simple Usage
Executor
provides a simple way to execute GraphQL queries. The following example shows how to execute a simple query that returns a scalar value. This uses the instance method Executor.Execute
with default pipeline.
[Fact]
public async Task Simple_Scalar()
{
/* Given */
var schema = await new ExecutableSchemaBuilder()
.Add("Query", new ()
{
{ "version: String!", b => b.ResolveAs("1.0") }
})
.Build();
ExecutableDocument query = """
{
version
}
""";
/* When */
var result = await new Executor(schema)
.Execute(new GraphQLRequest
{
Query = query
});
/* Then */
result.ShouldMatchJson("""
{
"data": {
"version": "1.0"
}
}
""");
}
The Executor
instance is created with Schema
. The Schema
is used to resolve the query and the Query
is the query document to execute passed into the Execute
method as GraphQL request document. GraphQLRequest object contains also possible operation name and variables.