Catch the highlights of GraphQLConf 2023! Click for recordings. Or check out our recap blog post.
Docs
Transforms
Renaming

Renaming

Renaming transforms are constructed with a renamer function that returns a string. The transform executes the renamer on each schema element within its scope and applies the revised names to gateway schema elements. If a renamer returns undefined, the name will be left unchanged. Additional options may control whether built-in types and scalars are renamed, see linked API docs.

import { stitchSchemas } from '@graphql-tools/stitch'
import {
  RenameInputObjectFields,
  RenameInterfaceFields,
  RenameObjectFieldArguments,
  RenameObjectFields,
  RenameRootFields,
  RenameRootTypes,
  RenameTypes,
  wrapSchema
} from '@graphql-tools/wrap'
 
const subschema = {
  schema: originalSchema,
  transforms: [
    new RenameTypes(name => `New${name}`),
    new RenameRootTypes(name => `New${name}`),
    new RenameRootFields((operationName, fieldName, fieldConfig) => `new_${fieldName}`),
    new RenameObjectFields((typeName, fieldName, fieldConfig) => `new_${fieldName}`),
    new RenameObjectFieldArguments((typeName, fieldName, argName) => `new_${argName}`),
    new RenameInterfaceFields((typeName, fieldName, fieldConfig) => `new_${fieldName}`),
    new RenameInputObjectFields((typeName, fieldName, inputFieldConfig) => `new_${fieldName}`)
  ]
}
 
const gateway = stitchSchemas({
  subschemas: [schema]
})