WHAT YOU'LL LEARN
  • 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
anchor

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
anchor

Create an extension file and implement GraphQLSchemaFactory.Interface:

extensions/listCmsEntriesGraphQL.ts

Then register it in webiny.config.tsx:

webiny.config.tsx

How It Works
anchor

  • addTypeDefs() — accepts a GraphQL SDL string (use the /* GraphQL */ tag for editor syntax highlighting). Extend built-in types with extend type Query or extend type Mutation.
  • addResolver() — registers a resolver for a path in the schema (e.g. "Query.listCmsEntries"). The dependencies array lists the DI tokens that Webiny injects into the resolver factory in the same order.
  • Result pattern — all use cases return a Result object. Check result.isFail() before accessing result.value, and return the error from the GraphQL response so clients receive structured error information.

Adding a Custom Mutation
anchor

The same pattern applies for mutations — extend Mutation instead of Query:

extensions/logMyClickGraphQL.ts

Deploying Changes
anchor

After creating or modifying a GraphQL extension, deploy the API:

During development, use watch mode for automatic redeployment: