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?

standup75
  • 4,734
  • 6
  • 28
  • 49

0 Answers0