Document transform is a feature that allows you to modify documents before they are used by plugins.
Document transform is a feature that allows you to modify documents before they are used by
plugins. You can use functions passed to the documentTransforms option to make changes to GraphQL
documents.
Basic Usage
Document transform has transform function.
Let’s specify an object containing those functions as the documentTransforms option as follows:
import type { CodegenConfig } from '@graphql-codegen/cli'const config: CodegenConfig = { schema: 'https://localhost:4000/graphql', documents: ['src/**/*.tsx'], generates: { './src/gql/': { preset: 'client', documentTransforms: [ { transform: ({ documents }) => { // Make some changes to the documents return documents } } ] } }}export default config
For instance, to remove a @localOnlyDirective directive from documents, you can write the
following code:
If you want to change the behavior of a document transform at runtime, you can simply prepare a
function that generates the document transform and write the configuration in its argument.