federation transform

federation transform allows you to add resolvers and directives to conform to the federation specification. Much of the federation source code could be reused to ensure that it is compliant to the specification. This transform uses the graphql-transform-federation package.

Usage

Add the following configuration to your Mesh config file:

{
  "transforms": [
    {
      "federation": {
        "types": [
          {
            "name": "Query",
            "config": {
              "extend": true
            }
          },
          {
            "name": "Product",
            "config": {
              "extend": true,
              "key": {
                "Fields": [
                  "id"
              ],
            },
              "fields": [
                {
                  "name": "id",
                  "external": true
                }
              ],
              "resolveReference": {
                "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": "https://my-site.com/userResolveReference.js"
}

./userResolveReference.js

// So we can point to an existing query field to resolve that entity
export default function (root, context, info)  {
  return context.accounts.Query.user({ root, args: { id: root.id }, context, info })
}

Config API Reference