API
Extend the GraphQL Schema
Learn how to add custom types, queries, and mutations to the Webiny GraphQL API using the GraphQLSchemaFactory.
- how to add custom GraphQL types, queries, and mutations
- how to register resolvers with dependency injection
- how to handle errors in GraphQL responses using the Result pattern
Overview
Webiny exposes a GraphQL API for all its core applications. You can extend it with your own types, queries, and mutations by implementing the GraphQLSchemaFactory interface. The factory receives a schema builder, you call addTypeDefs() and addResolver() on it, and Webiny merges your additions into the running schema.
The GraphQL layer stays thin: resolvers delegate to use cases and services that carry the business logic.
Adding a Custom Query
Create an extension file and implement GraphQLSchemaFactory.Interface:
Then register it in webiny.config.tsx:
How It Works
addTypeDefs()— accepts a GraphQL SDL string (use the/* GraphQL */tag for editor syntax highlighting). Extend built-in types withextend type Queryorextend type Mutation.addResolver()— registers a resolver for a path in the schema (e.g."Query.listCmsEntries"). Thedependenciesarray lists the DI tokens that Webiny injects into theresolverfactory in the same order.- Result pattern — all use cases return a
Resultobject. Checkresult.isFail()before accessingresult.value, and return the error from the GraphQL response so clients receive structured error information.
Adding a Custom Mutation
The same pattern applies for mutations — extend Mutation instead of Query:
Deploying Changes
After creating or modifying a GraphQL extension, deploy the API:
During development, use watch mode for automatic redeployment: