@apollo/federation throws an error with the example from the docs
Asked Answered
R

0

6

After running into an issue trying things out on my own, I tried the example from the docs and I ran into a similar issue, is the doc wrong, or am I doing something stupid?

The example I am trying to execute is the one from this page: https://www.apollographql.com/docs/apollo-server/federation/introduction/

The relevant piece of code is:

const server = new ApolloServer({
  schema: buildFederatedSchema([{
    typeDefs: gql`
      extend type Query {
        me: User
      }

      type User @key(fields: "id") {
        id: ID!
        username: String!
      }
    `,
    resolvers: [],
  }, {
    typeDefs: gql`
      extend type Query {
        topProducts(first: Int = 5): [Product]
      }

      type Product @key(fields: "upc") {
        upc: String!
        name: String!
        price: Int
      }
    `,
    resolvers: [],
  }, {
    typeDefs: gql`
      type Review {
        body: String
        author: User @provides(fields: "username")
        product: Product
      }

      extend type User @key(fields: "id") {
        id: ID! @external
        reviews: [Review]
      }

      extend type Product @key(fields: "upc") {
        upc: String! @external
        reviews: [Review]
      }
    `,
    resolvers: [],
  }]),
  context: ({ req }) => ({ user: req.user }),
})

Note that I left the resolvers empty on purpose, I am just trying to compile the schema.

Here is the error I get:

GraphQLSchemaValidationError: Field "User.id" can only be defined once. Field "Product.upc" can only be defined once.

Can someone help me out with that?

Rainwater answered 3/7, 2019 at 0:0 Comment(2)
Did you end up solving this? I have similar issue as well.Doykos
I'm running into the same problem and opened a bug report github.com/apollographql/apollo-server/issues/3554Plainlaid

© 2022 - 2024 — McMap. All rights reserved.