Schema and resolvers 🧩
Learn how the schema and resolvers work together to form a complete GraphQL API.
The schema defined the contract of your GraphQL API. But the resolvers are the actual implementation of that contract.
The schema
The schema is the blueprint of your GraphQL API. It defines the types and fields of your API, and how they relate to each other.
The resolvers
The resolvers are the actual implementation of the schema. They are functions that return the data for each field in the schema.
Based on our basic schema:
type User {
id: ID!
name: String!
posts: [Post!]!
}
type Query {
users: [User!]!
}We would write resolver to match this schema.
const resolvers = {
Query: {
users: () => {
return [{ id: 1, name: 'John Doe' }]
},
},
}