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:

transforms:
- federation:
types:
# Ensure the root queries of this schema show up the combined schema
- name: Query
config:
extend: true
- name: Product
config:
# extend Product {
extend: true
# Product @key(fields: "id") {
keyFields:
- id
fields:
# id: Int! @external
- name: id
external: true
resolveReference:
targetSource: accounts
targetMethod: user
args:
id: root.id

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

./userResolveReference.js

// So we can point to an existing query field to resolve that entity
module.exports = (root, context) => context.accounts.api.user({ id: root.id })

  • 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)