v1
Transforms
Prefix

Prefix Transform

The prefix transform allows you to add prefixes to existing GraphQL types and root operations (under Query/Mutation). Prefix transform is similar to Rename Transform in that it allows you to modify names to avoid conflicts, simplify complicated names, and change the appearance of your query. In contrast with the Rename Transform, Prefix Transform is simpler and only allows you to append a prefix to the existing name.

You can use it to easily “namespace” APIs in your unified API and avoid conflicts.

How to use?

You can import createPrefixTransform to create an instance of the transform. The value option is the prefix that you want to add to the types and fields of the subgraph. In the example below, we add Countries_ to the types and fields of the subgraph.

mesh.config.ts
import {
  createPrefixTransform,
  defineConfig,
  loadGraphQLHTTPSubgraph
} from '@graphql-mesh/compose-cli'
 
export const composeConfig = defineConfig({
  subgraphs: [
    {
      sourceHandler: loadGraphQLHTTPSubgraph('Countries', {
        endpoint: 'https://countries.trevorblades.com'
      }),
      transforms: [
        createPrefixTransform({
          value: 'Countries_'
        })
      ]
    }
  ]
})