在自己尝试解决问题后,我尝试了文档中的示例,但遇到了类似的问题,文档是错误的,还是我在做一些愚蠢的事情?
我要执行的示例是此页面中的示例:https ://www.apollographql.com/docs/apollo-server/federation/introduction/
相关的代码是:
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 }),
})
请注意,我故意将解析器留空,我只是想编译架构。
这是我得到的错误:
GraphQLSchemaValidationError: Field "User.id" can only be defined once. Field "Product.upc" can only be defined once.
有人可以帮我解决这个问题吗?