You can add your own GraphQL queries and mutations to Payload, making use of all the types that Payload has defined for you.
To do so, add your queries and mutations to the main Payload config as follows:
Config Path | Description |
---|---|
graphQL.queries | Function that returns an object containing keys to custom GraphQL queries |
graphQL.mutations | Function that returns an object containing keys to custom GraphQL mutations |
The above properties each receive a function that is defined with the following arguments:
GraphQL
This is Payload's GraphQL dependency. You should not install your own copy of GraphQL as a dependency due to underlying restrictions based on how GraphQL works. Instead, you can use the Payload-provided copy via this argument.
payload
This is a copy of the currently running Payload instance, which provides you with existing GraphQL types for all of your Collections and Globals - among other things.
Both graphQL.queries
and graphQL.mutations
functions should return an object with properties equal to your newly written GraphQL queries and mutations.
payload.config.js
: