Replace Config Transform - is a transform for GraphQL Mesh that allows you to replace or modify the configurations of your GraphQL schema based on specified rules. This can be useful for adding descriptions, deprecating fields, changing default values, and other aspects of the schema.
Before you can use the Replace Config Transform, you need to install it along with GraphQL Mesh if you haven't already done so. You can install these using npm or yarn.
npm install @dmamontov/graphql-mesh-replace-config-transform
or
yarn add @dmamontov/graphql-mesh-replace-config-transform
To make TypeScript recognize the Replace Config Transform, you need to add an alias in your tsconfig.json.
Add the following paths configuration under the compilerOptions in your tsconfig.json file:
{
"compilerOptions": {
"paths": {
"replace-config": ["./node_modules/@dmamontov/graphql-mesh-replace-config-transform"]
}
}
}
You need to include the Replace Config Transform in your GraphQL Mesh configuration file (usually .meshrc.yaml). Below is an example configuration that demonstrates how to use this transform:
transforms:
- replaceConfig:
- typeName: PersonalDataInput
fields: [ phone ]
replacers:
- description: 'Filter by phone'
- type: String
- deprecated: true
- nullable: false
- default: 79998887766
- extensions:
custom: true
- directive: constraint
args:
pattern: "^7\\d{10}$"
! This transform does not add directive and extension logic.
This transform allows you to change the following parameters in various parts of your GraphQL schema:
- description: Available for Input, Composite, Enums.
- type: Available for Input, Composite. (Use at your own risk. Replacing the type will not affect the result.)
- deprecated: Available for Input, Composite, Enums.
- nullable: Available for Input, Composite.
- default: Available only for Input.
- extensions: Available for Input, Composite, Enums.
- directive: Available for Input, Composite, Enums.
Remember, always test your configurations in a development environment before applying them in production to ensure that everything works as expected.