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.
RenameTypes
: renames all element types.RenameRootTypes
: renames the root Query, Mutation, and Subscription types.RenameRootFields
: renames fields on the root Query, Mutation, and Subscription objects.RenameObjectFields
: renames fields of Object types.RenameObjectFieldArguments
: renames field arguments of Object types.RenameInterfaceFields
: renames fields of Interface types.RenameInputObjectFields
: renames input fields of InputObject types.
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]
})