v1
Transforms
Rename

Rename Transform

The rename transform allows you to rename:

  • GraphQL types
  • GraphQL fields
  • GraphQL field arguments

The rename transform helps you avoid conflicting names, simplify complicated names and make queries look more like mutations.

How to use?

You can import createRenameTransform to create an instance of the transform. You can use regular JavaScript functions to rename types, fields, and field arguments.

mesh.config.ts
import {
  createRenameTransform,
  defineConfig,
  loadGraphQLHTTPSubgraph
} from '@graphql-mesh/compose-cli'
 
export const composeConfig = defineConfig({
  subgraphs: [
    {
      sourceHandler: loadGraphQLHTTPSubgraph('Countries', {
        endpoint: 'https://countries.trevorblades.com'
      }),
      transforms: [
        createRenameTransform({
          // Rename types
          typeRenamer(opts) {
            if (opts.typeName === 'Country') {
              return 'MyCountry'
            }
            return ''
          },
          // Rename fields
          fieldRenamer(opts) {
            if (opts.typeName === 'Country' && opts.fieldName === 'name') {
              return 'countryName'
            }
            return ''
          },
          // Rename field arguments
          argRenamer(opts) {
            if (
              opts.typeName === 'Country' &&
              opts.fieldName === 'name' &&
              opts.argName === 'lang'
            ) {
              return 'language'
            }
            return ''
          }
        })
      ]
    }
  ]
})