This is documentation for v13, which is no longer actively maintained.
For up-to-date documentation, see the latest stable version.
For up-to-date documentation, see the latest stable version.
Queries
The query type in GraphQL represents a read-only view of all of our entities and ways to retrieve them. A query type is required for every GraphQL server.
SDL
type Query { books: [Book!]! author(id: Int!): Author}
Clients can query one or more fields through the query type.
GraphQL
query { books { title author } author(id: 1) { name }}
Queries are expected to be side-effect free and are therefore parallelized by the execution engine.
Usage
A query type can be defined like the following.
C#
public class Query{ public Book GetBook() { return new Book { Title = "C# in depth", Author = "Jon Skeet" }; }}
public class Startup{ public void ConfigureServices(IServiceCollection services) { services .AddGraphQLServer() .AddQueryType<Query>(); }}
C#public class Query{ public Book GetBook() { return new Book { Title = "C# in depth", Author = "Jon Skeet" }; }}
public class QueryType : ObjectType<Query>{ protected override void Configure(IObjectTypeDescriptor<Query> descriptor) { descriptor .Field(f => f.GetBook()) .Type<BookType>(); }}
public class BookType : ObjectType<Book>{ protected override void Configure(IObjectTypeDescriptor<Book> descriptor) { descriptor .Field(f => f.Title) .Type<StringType>();
descriptor .Field(f => f.Author) .Type<StringType>(); }}
public class Startup{ public void ConfigureServices(IServiceCollection services) { services .AddGraphQLServer() .AddQueryType<QueryType>(); }}
Warning: Only one query type can be registered using
AddQueryType(). If we want to split up our query type into multiple classes, we can do so using type extensions.
A query type is just a regular object type, so everything that applies to an object type also applies to the query type (this is true for all root types).
Last updated on February 17, 2026 by Michael Staib