• Docs
  • Transforms
  • Apollo Federation

Apollo Federation Transform

The federation transform allows the resolvers and directives to conform to the federation specification. Much of the federation source code could be reused, ensuring it is compliant with the specification. This transform uses graphql-transform-federation package.

yarn add @graphql-mesh/transform-federation

How to use?

Add the following configuration to your Mesh config file:

  - federation:
        # Ensure the root queries of this schema show up the combined schema
        - name: Query
            extend: true
        - name: Product
            # extend Product {
            extend: true
            # Product @key(fields: "id") {
              - id
              # id: Int! @external
              - name: id
                  external: true
              queryFieldName: user

Add Reference Resolver as a Code File

To add more complex business logic, you can point to a code file that exports a resolver function.

resolveReference: ./userResolveReference.js
// So we can point to an existing query field to resolve that entity
module.exports = (root, context, info) => {
  return context.accounts.Query.user({ root, args: { id: root.id }, context, info })
You can check out our example that uses Federation as a merging strategy.
  • types (type: Array of Object, required):
    • name (type: String, required)
    • config (type: Object):
      • keyFields (type: Array of String, required)
      • extend (type: Boolean)
      • fields (type: Array of Object, required):
        • name (type: String, required)
        • config (type: Object, required):
          • external (type: Boolean)
          • provides (type: String)
          • requires (type: String)
      • resolveReference - One of:
        • String
        • object:
          • queryFieldName (type: String, required) - Name of root field name that resolves the reference
          • keyArg (type: String) - If the root field name has multiple args, you need to define which argument should receive the key
Last updated on August 25, 2022