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 {
  wrapSchema,
  RenameTypes,
  RenameRootTypes,
  RenameRootFields,
  RenameObjectFields,
  RenameObjectFieldArguments,
  RenameInterfaceFields,
  RenameInputObjectFields
} from '@graphql-tools/wrap'
import { stitchSchemas } from '@graphql-tools/stitch'
 
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]
})