Queries
To perform a query you need to have a root Query object that is an ObjectGraphType
.
Queries should only fetch data and never modify it. You can only have a single root
Query object. By default queries are executed in parallel.
query {
hero {
id
name
}
}
If you have only a single query, you can use shorthand syntax.
hero {
id
name
}
To provide an Operation
name for your query, you add it after the query
keyword.
An Operation
name is optional if there is only a single operation in the request.
query MyHeroQuery {
hero {
id
name
}
}
You can also provide that operation name to the ExecutionOptions
.
var schema = new Schema { Query = new StarWarsQuery() };
var json = await schema.ExecuteAsync(_ =>
{
_.OperationName = "MyHeroQuery";
_.Query = @"
query MyHeroQuery {
hero {
id
name
}
}
";
});
public class StarWarsQuery : ObjectGraphType
{
public StarWarsQuery()
{
Field<DroidType>("hero")
.Resolve(context => new Droid { Id = "1", Name = "R2-D2" });
}
}