`schema` field
The schema
field should point to your GraphQLSchema
- there are multiple ways you can specify it and load your GraphQLSchema
.
You can specify either a string
pointing to your schema, or string[]
point to multiple schemas, and they will be merged.
#
How to use it?#
Root levelYou can specify the schema
field in your root level config, as follow:
#
Output-file levelOr, you can specify it per-output file level. This way you can
#
Multiple schemas and client-side schemaYou can also specify schema
on both levels: root and output-file, and then GraphQL Code Generator will merge both schemas into one:
It's also useful if you have a remote schema coming from a server, and a client-side schema that available in your client-side.
#
Available formatsThe following can be specified as a single value, or as an array with mixed values.
#
URLYou can specify a URL to load your GraphQLSchema
from:
#
Supported Configurationheaders
#
You can also specify custom HTTP headers to be sent with the request:
Note that spacing and indentation is very important in YAML, so please make sure it matches the examples above.
customFetch
#
You can specify a custom fetch function for the HTTP request, using the module name you wish to use:
method
#
You can specify a HTTP method to use for the introspection query. default is POST
.
#
JSONYou can point to a local .json
file that contains GraphQL Introspection JSON.
.graphql
files#
Local You can point to a single .graphql
file that contains AST string of your schema:
Or, you can point to multiple files using a glob expression (codegen will merge the schema files for you):
You can also specify multiple patterns:
And, you can specify files to exclude/ignore, using the !
sign:
All provided glob expressions are evaluated together. The usage is similar to
.gitignore
.
#
Supported ConfigurationskipGraphQLImport
#
By default, codegen skips graphql-import
in favor of loading all files using glob expressions.
If you are using graphql-import
syntax in your schema definitions, you can tell codegen to use those import statements:
commentDescriptions
#
This will convert all deprecated form of Graphql comments (marked with #
) into a GraphQL descriptions (marked with "
) during the parsing phase.
assumeValidSDL
#
Set to true to assume the SDL is valid, and skip any SDL syntax validations.
#
Code FilesYou can use code files and the codegen will try to extract the GraphQL schema from it, based on gql
tag:
The codegen will try to load the file as an AST and look for explicit GraphQL strings, but if it can't find those, it will try to require
the file and looks for operations in the default export.
#
Supported ConfigurationnoRequire
#
You can disable the require
if it causes errors for you (for example, because of different module system or missing deps):
noPluck
#
You can disable the AST lookup phase, and tell codegen to skip and directly try to require
each file:
assumeValid
#
Set this to true
in order to tell codegen to skip AST validation.
#
JavaScript exportYou can also specify a code file that exports your GraphQLSchema
object as named export schema
or as default export.
You can also import from TypeScript files, but don't forget to specify require field.
#
StringYou can specify your schema directly as an AST string in your config file. It's very useful for testing.
#
GitHubYou can load your schema file from a remote GitHub file, using the following syntax:
You can load from a JSON file,
.graphql
file or from a code file containinggql
tag syntax.
#
GitYou can load your schema file from a Git repository, using the following syntax:
You can load from a JSON file,
.graphql
file or from a code file containinggql
tag syntax.
#
Apollo EngineYou can load your schema from Apollo Engine, with the following syntax:
#
Custom Schema LoaderIf your schema has a different or complicated way of loading, you can point to a single code file, that does that work for you.
Your custom loader should export a default function that returns GraphQLSchema
object, or an identifier called schema
. For example:
The second parameter passed to the loader function is a config object that includes a
pluginContext
property. This value is passed to any executed plugins, so it can be modified by the loader to pass any additional information to those plugins.