webiny-custom-graphql-api

Adds custom GraphQL queries and mutations to Webiny APIs using GraphQLSchemaFactory.

8.0k|673|Updated Jan 9, 2018
One-click install
npx skills add https://github.com/webiny/webiny-js --skill webiny-custom-graphql-api
Or copy as Structured Prompt for Agent
Please help me install this Agent Skill.
Skill: webiny-custom-graphql-api
Source: https://github.com/webiny/webiny-js/tree/main/skills/user-skills/api/graphql-api
Command: npx skills add https://github.com/webiny/webiny-js --skill webiny-custom-graphql-api

SYSTEM DOCUMENTATION & REQUIREMENTS

What problem does it solve?

Extending a Webiny project's GraphQL API with custom queries, mutations, and business logic requires knowing the correct factory pattern, DI conventions, and registration steps—mistakes like missing file extensions or wrong export styles cause build failures.

Core Features & Use Cases

  • Custom Queries and Mutations: Implement GraphQLSchemaFactory.Interface to add type definitions and resolvers via the schema builder.
  • Per-Resolver Dependency Injection: Inject request-scoped services like identity, tenancy, and CMS use-cases directly into resolvers.
  • Namespaced Schemas and Dynamic Inputs: Build namespaced mutation patterns and generate GraphQL input fields dynamically from CMS models.
  • Use Case: You need a whoAmI endpoint or a createEntity mutation backed by a UseCase—this Skill provides the full pattern from schema definition to <Api.Extension> registration and deployment.

Quick Start

Add a custom GraphQL query to my Webiny API that returns the current user's identity using GraphQLSchemaFactory.

Frequently Asked Questions about webiny-custom-graphql-api

High-intent search queries and answers about installing and using this skill.

FAQPage Schema
How do I add a custom GraphQL query to a Webiny API?

Implement GraphQLSchemaFactory.Interface, use builder.addTypeDefs to extend the Query type, and builder.addResolver to attach resolver logic. Export with GraphQLSchemaFactory.createImplementation as a default export and register it via an Api.Extension component.

How do I inject services into Webiny GraphQL resolvers?

Pass DI abstraction tokens in the resolver's dependencies array within addResolver. Dependencies are resolved per-request from the request-scoped container, giving resolvers access to services like IdentityContext and UseCases.

Why does my Webiny extension build fail when registering a GraphQL schema?

Build failures occur when the Extension src prop omits the .ts file extension or when the schema file uses a named export instead of a default export. Always use the full path with .ts and export default the createImplementation call.

Can I generate GraphQL input fields from a Webiny CMS model?

Yes, use renderInputFields with createFieldTypePluginRecords and ListModelsUseCase to dynamically build input type definitions from a CMS model's fields. This requires constructor-level DI for PluginsContainer and ListModelsUseCase.

How do I create namespaced mutations in Webiny GraphQL?

Define a namespace type like MyPackageMutation in one schema and extend the root Mutation with it, then have other schemas extend that namespace type. Add a pass-through resolver returning an empty object for the namespace path.