GraphQL Schema
In Payload the schema is controlled by your collections and globals. All you need to do is run the generate command and the entire schema will be created for you.
Schema generation script
Install @payloadcms/graphql
as a dev dependency:
Run the following command to generate the schema:
Custom Field Schemas
For array
, block
, group
and named tab
fields, you can generate top level reusable interfaces. The following group field config:
will generate:
The above example outputs all your definitions to a file relative from your payload config as ./graphql/schema.graphql
. By default, the file will be output to your current working directory as schema.graphql
.
Adding an npm script
Payload will automatically try and locate your config, but might not always be able to find it. For example, if you are working in a /src
directory or similar, you need to tell Payload where to find your config manually by using an environment variable.
If this applies to you, create an npm script to make generating types easier:
Now you can run pnpm generate:graphQLSchema
to easily generate your schema.