Using GraphQL @key directive

System Information
  • Strapi Version: 3.0.6
  • Operating System: Ubuntu 16
  • Database: MongoDB 4.2
  • Node Version: 12.x
  • NPM Version: 6.14.12
  • Yarn Version: 1.22.5

Hi everyone,

we want to integrate Strapi in our Apollo Federation Gateway in order to have a single GraphQL endpoint for all of our services.
We set the federation: true flag in config/plugins.js. So far, so good. Strapi is now successfully registered in our gateway.

However, we are not able to extend the schema of Strapi models from other services, since we are having problems using the @key directive in Strapi.

We have setup a schema.graphql.js for a model, as mentioned in the docs:

module.exports = {
  definition: `
    type TestMe @key(fields: "hello") {
      hello: String
    }
  `,
};

This throws the following error:

[2021-05-31T11:54:36.109Z] error Error: Unknown directive "key".

Alright, we thought we might need to define the directive first.

module.exports = {
  definition: `
    directive @key(fields: String!) on OBJECT | INTERFACE

    type TestMe @key(fields: "hello") {
      hello: String
    }
  `,
};

Now we get this error:

[2021-05-31T11:55:03.477Z] error GraphQLSchemaValidationError: Directive "key" already exists in the schema. It cannot be redefined.

We would really appreciate the smallest hint on how to resolve or approach this. Maybe someone has experience with extending the Strapi GraphQL schema.

Best Regards
Hendrik