Core GraphQL Terminology
Before writing a serious GraphQL application, you need to understand the vocabulary used by the specification and ecosystem.
Schema
The schema defines what clients are allowed to query and what data types and operations are available.
Type
A type describes the shape of data. Examples include User, Product, Order, and Post.
Field
A field is a property or operation exposed by a type.
type User {
id: ID!
name: String!
email: String!
}
Here id, name, and email are fields.
Query
A query is a read operation. It retrieves data without being intended to modify server state.
Mutation
A mutation represents an operation that changes server-side state, such as creating, updating, or deleting data.
Subscription
A subscription represents a long-lived operation used for receiving events or updates, commonly through a real-time transport.
Resolver
A resolver is a function responsible for obtaining or computing the value of a field.
Selection set
The fields enclosed inside { } after an object field form a selection set.
user {
id
name
}
Argument
An argument supplies input to a field.
user(id: "42")
Scalar
A scalar represents a leaf value such as String, Int, Float, Boolean, or ID.
These concepts build on each other. A schema defines types, types contain fields, fields can accept arguments, clients select fields in operations, and resolvers provide the values during execution.
Defines the API contractProduces field valuesRead operationState-changing operationReal-time operation- The schema is the central contract of a GraphQL API.
- Types describe data structures.
- Fields belong to types.
- Resolvers provide field values during execution.
- Queries, mutations, and subscriptions represent different operation categories.
What is a resolver primarily responsible for?