Skip to main content

Apollo Federation Transform

federation transform allows to add the resolvers and directives to conform to the federation specification. Much of the federation sourcecode could be reused ensuring it is compliant to 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
targetSource: accounts
targetMethod: user

Add Reference Resolver as a Code File#

If you want 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) => context.accounts.api.user({ id: })

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)
          • required (type: String)
      • resolveReference - One of:
        • String
        • object:
          • targetSource (type: String, required)
          • targetMethod (type: String, required)
          • args (type: JSON, required)
          • returnData (type: String)
          • resultSelectedFields (type: JSON)
          • resultSelectionSet (type: String)
          • resultDepth (type: Int)