Docs
Getting Started
Adding Transforms

Adding Transforms

Another strategy to avoid conflicts while combining schemas is to modify one or more of the subschemas using transforms. Transforming allows a schema to be groomed in such ways as adding namespaces, renaming types, or removing fields (to name a few) prior to stitching it into the combined gateway schema. These transforms should be added directly to subschema config:

import { FilterRootFields, RenameTypes } from '@graphql-tools/wrap'
 
const postsSubschema = {
  schema: postsSchema,
  transforms: [
    new FilterRootFields((operation, rootField) => rootField !== 'postsByUserId'),
    new RenameTypes(name => `Post_${name}`)
  ]
}

In the example above, we transform the postsSchema by removing the postsByUserId root field and adding a Post_ prefix to all types in the schema. These modifications will only be present in the combined gateway schema.

Note that when automatically merging types, all transforms are applied prior to merging. That means transformed types will merge based on their transformed names within the combined gateway schema.