Skip to Content
Mesh

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.

By default, GraphQL-specified scalars and protected custom scalars (for example from graphql-scalars) are not prefixed. Use force to opt into prefixing those protected custom scalars when migrating schemas that already prefix them. Specified scalars (Int/Float/String/Boolean/ID) always stay unprefixed.

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_', // Opt into prefixing protected custom scalars such as DateTime force: ['DateTime'] }) ] } ] })
Last updated on