The Guild LogoThe Guild Monogram

GraphQL Code Generator

Generate anything from GraphQL schema / operations!

Contact Us

How to extend the GraphQL Schema?#

Each plugin can also specify addToSchema field, and to extend the GraphQLSchema with more types:

module.exports = { plugin: (schema, documents, config) => { const typesMap = schema.getTypeMap() return Object.keys(typesMap).join('\n') }, addToSchema: ` type MyType { field: String } directive @myDirective on OBJECT ` }

It's useful when you wish to add things like declarative @directive to your GraphQLSchema, which affects only the output of the codegen.

For example, let's add a custom @directive that tells the codegen to ignore a specific type:

module.exports = { plugin: (schema, documents, config, info) => { const typesMap = schema.getTypeMap() return Object.keys(typesMap) .filter(typeName => { const type = typesMap[typeName] const astNode = type.astNode if (astNode && astNode.directives && astNode.directives.find(d => === 'ignore')) { return false } return true }) .join('\n') }, addToSchema: ` directive @ignore on OBJECT ` }