Apollo Federation Gateway Unknown Directive error @search

Dgraph version 21.03.0

When setting up a simple Apollo Federation project, I have found that Apollo Federation errors on the @search directive.

Have you tried reproducing the issue with the latest release?

Yes. 21.03.0

What is the hardware spec (RAM, OS)?

Running the docker image on Macbook Pro. 16GB RAM, 8 core CPU

Steps to reproduce the issue (command/config used to run Dgraph).

Using the following sdl, in dgraph apollo federation gateway is able to compose the schema successfully

type Equipment @key(fields: "id") {
  id: ID!
  name:String!
  events:[Event]
}
type Event @key(fields: "id") {
  id:ID!
  name:String
  timestamp:DateTime
  value:String
}

If I then add a search directive on the Event.timestamp like this

type Equipment @key(fields: "id") {
  id: ID!
  name:String!
  events:[Event]
}
type Event @key(fields: "id") {
  id:ID!
  name:String
  timestamp:DateTime @search
  value:String
}

Apollo gateway gives the following error

            throw new apollo_graphql_1.GraphQLSchemaValidationError(errors);
                  ^

GraphQLSchemaValidationError: Unknown directive "search".
    at ApolloGateway.createSchema (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/@apollo/gateway/dist/index.js:207:19)
    at ApolloGateway.<anonymous> (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/@apollo/gateway/dist/index.js:178:32)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/@apollo/gateway/dist/index.js:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:94:5) {
  errors: [
    GraphQLError: Unknown directive "search".
        at Object.Directive (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/graphql/validation/rules/KnownDirectives.js:61:29)
        at Object.enter (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/graphql/language/visitor.js:324:29)
        at visit (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/graphql/language/visitor.js:242:26)
        at Object.validateSDL (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/graphql/validation/validate.js:93:22)
        at buildSchemaFromDefinitionsAndExtensions (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/@apollo/federation/dist/composition/compose.js:150:25)
        at Object.composeServices (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/@apollo/federation/dist/composition/compose.js:221:30)
        at Object.composeAndValidate (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/@apollo/federation/dist/composition/composeAndValidate.js:13:41)
        at ApolloGateway.createSchema (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/@apollo/gateway/dist/index.js:199:49)
        at ApolloGateway.<anonymous> (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/@apollo/gateway/dist/index.js:178:32)
        at Generator.next (<anonymous>) {
      locations: [ { line: 14, column: 15 } ]
    }
  ]
}
error Command failed with exit code 1.

Here is the apollo gateway index.js file

const { ApolloServer } = require('apollo-server');
const { ApolloGateway } = require("@apollo/gateway");

const gateway = new ApolloGateway({
    serviceList: [
        { name: 'core', url: 'http://localhost:8080/graphql' }
    ],
});

const server = new ApolloServer({
    gateway,

    subscriptions: false,
});

server.listen().then(({ url }) => {
    console.log(`🚀 Server ready at ${url}`);
});

Hi,

Apollo Federation is giving errors because search directive is not defined in the schema provided.
On receiving GraphQL schema from Users, Dgraph generates a schema which adds definition for all Dgraph specific directives. This generated schema can then be used with Apollo Federation.

Linking related discuss post: Dgraph Directives reference (for other tools)?

Does this mean that Dgraph only works with Apollo Federation Gateway running in Managed mode?

According to the The gateway - Apollo Federation - Apollo GraphQL Docs the Federation Gateway will fetch the schema from the service on startup, and does not need to be provided manually.

Hey @Geoff.Nunan

I tried to reproduce it but things are working fine for me.
I first started a Dgraph GraphQL service and applied the given schema.
Then I started the Gateway and there was no issue reported.

Did you do something different than this?
How are applying your schema?
Can you tell exact steps to reproduce so that we might help you better?

Load the following schema into dgraph. I am using the v21.03.0 docker container running locally

type Equipment @key(fields: "id") {
  id: ID!
  name:String!
  events:[Event]
}
type Event @key(fields: "id") {
  id:ID!
  name:String
  timestamp:DateTime @search
  value:String
}

Then, using the following index.js for the graphql gateway, start the gateway with node index.js

const { ApolloServer } = require('apollo-server');
const { ApolloGateway } = require("@apollo/gateway");

const gateway = new ApolloGateway({
    serviceList: [
        { name: 'core', url: 'http://localhost:8080/graphql' }
    ],
});

const server = new ApolloServer({
    gateway,

    subscriptions: false,
});

server.listen().then(({ url }) => {
    console.log(`🚀 Server ready at ${url}`);
});

I get the following error

GraphQLSchemaValidationError: Unknown directive "search".
    at ApolloGateway.createSchema (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/@apollo/gateway/dist/index.js:207:19)
    at ApolloGateway.<anonymous> (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/@apollo/gateway/dist/index.js:178:32)
    at Generator.next (<anonymous>)
    at fulfilled (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/@apollo/gateway/dist/index.js:5:58)
    at processTicksAndRejections (node:internal/process/task_queues:94:5) {
  errors: [
    GraphQLError: Unknown directive "search".
        at Object.Directive (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/graphql/validation/rules/KnownDirectives.js:61:29)
        at Object.enter (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/graphql/language/visitor.js:324:29)
        at visit (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/graphql/language/visitor.js:242:26)
        at Object.validateSDL (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/graphql/validation/validate.js:93:22)
        at buildSchemaFromDefinitionsAndExtensions (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/@apollo/federation/dist/composition/compose.js:150:25)
        at Object.composeServices (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/@apollo/federation/dist/composition/compose.js:221:30)
        at Object.composeAndValidate (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/@apollo/federation/dist/composition/composeAndValidate.js:13:41)
        at ApolloGateway.createSchema (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/@apollo/gateway/dist/index.js:199:49)
        at ApolloGateway.<anonymous> (/Users/geoffreynunan/Documents/GitHub/Libre-server/node_modules/@apollo/gateway/dist/index.js:178:32)
        at Generator.next (<anonymous>) {
      locations: [ { line: 15, column: 22 } ]
    }
  ]
}

If I remove the @search directive from the dgraph schema, the gateway starts successfully

I am applying the graphql schema to dgraph by posting it to http://localhost:8080/admin/schema