Cannot Use Apollo Federation with Multiple Dgraph Instances


Report a GraphQL Bug

What edition and version of Dgraph are you using?

Edition:

  • SlashGraphQL
  • Dgraph (community edition/Dgraph Cloud)

Dgraph version 21.03.2 on Docker

When I’m setting up a simple project involving federating between two separate Dgraph instances using Apollo Federation and the Rover CLI, I find the CLI is unable to generate a supergraph due to conflicting type definitions, resulting in me being unable to set up the gateway.

Have you tried reproducing the issue with the latest release?

Yes

Steps to reproduce the issue (paste the query/schema if possible)

  1. Set up two Dgraph instances, one running with the following sample sdl:
type User @key(fields: "userId") {
    userId: ID!
    username: String
}

and one with the following:

type Review {
    id: ID!
    review: String
}

extend type User @key(fields: "userId") {
    userId: ID! @external
    reviews: [Review]
}
  1. Create a supergraph.yml file with the following:
subgraphs:
  user:
    routing_url: <user graphql url>
    schema:
      subgraph_url: <user graphql url>
  reviews:
    routing_url: <review graphql url>
    schema:
      subgraph_url: <review graphql url>

  1. Use the Rover CLI to create a supergraph for federating between the two instances:
rover supergraph compose --config ./supergraph.yml  

Expected behaviour and actual result.

I expect rover to be able to compose a supergraph that will be able to correctly correlate the User extension in the second sdl with the original User definition in the first sdl. Instead, I receive the following list of errors:

error[E029]: Encountered 10 build errors while trying to build a supergraph.

Caused by:
    ENUM_MISMATCH: The `UserHasFilter` enum does not have identical values in all services. Groups of services with identical values are: [reviews], [user]
    ENUM_MISMATCH: The `UserOrderable` enum does not have identical values in all services. Groups of services with identical values are: [reviews], [user]
    UNKNOWN: Field "UserAggregateResult.count" can only be defined once.
    UNKNOWN: There can be only one type named "UserAggregateResult".
    UNKNOWN: There can be only one type named "AddUserInput".
    UNKNOWN: There can be only one type named "UserPatch".
    UNKNOWN: There can be only one type named "UserRef".
    UNKNOWN: Field "Mutation.addUser" can only be defined once.
    UNKNOWN: Field "Mutation.updateUser" can only be defined once.
    UNKNOWN: Field "Mutation.deleteUser" can only be defined once.
    
              The subgraph schemas you provided are incompatible with each other. See https://www.apollographql.com/docs/federation/errors/ for more information on resolving build errors.

From what I can tell, this is due to Dgraph taking the extension in the Review instance and creating the full litany of Dgraph types, queries, and mutations for it, which in turn creates collisions due to the same definitions occurring in the User instance.

Is there something wrong with my schemas, or does Dgraph not work with Apollo Federation in this manner?