Skip to Content
Mesh
v1TransformsFederation Transform

Federation Transform

If the GraphQL source is not a Federated Subgraph , you may use this Federation Transform to provide necessary annotations and directive to convert the GraphQL source to a Federated Subgraph conforming to the Federation specification.

💡

If you want to add @key directive in your subgraph, you need to be aware of Type Merging

How to use?

Let’s say you have the following subgraph;

type Product { id: ID! name: String! price: Float! } type Query { productById(id: ID!): Product }

And you want to add @key directive to the Product type. Then you can add the following configuration to your mesh.config.ts file. But you need resolveReference to be able to resolve the reference, which is equivalent of __resolveReference resolver in regular Federation.

mesh.config.ts
import { createFederationTransform, defineConfig, loadGraphQLHTTPSubgraph } from '@graphql-mesh/compose-cli' export const composeConfig = defineConfig({ subgraphs: [ { sourceHandler: loadGraphQLHTTPSubgraph('myApi', { endpoint: 'http://localhost:4001/my-api' }), transforms: [ createFederationTransform({ // Schema Coordinates (Type or Type.field) Product: { // Directive name key: { // Directive arguments fields: 'id', // Reference resolver (only for @key directive) resolveReference: { fieldName: 'productById' } } }, // You can also add other directives Query: { extends: true } }) ] } ] })

Config keys use Spec Schema Coordinates for types and fields (Product, Query.productById). Argument form Type.field(arg:) and directive forms @name are not keys on this transform today; pass directive options on the type or field entry. See the Schema Coordinates RFC .

Learn more  about other directives in Federation 

Last updated on