我正在努力实现与 Apollo GraphQL 联邦兼容的服务;我提供的服务是用 Lacinia(Clojure 的 GraphQL 库)编写的。
我有一项定义用户的服务:
type User @key(fields: "id") {
id: String!
name: String!
}
type Query {
user_by_id(id:String!) : User
}
schema { query: Query }
还有一个定义产品和扩展用户的第二个:
type User @extends @key(fields: "id") {
id: String! @external
favorite_products: [Product]
}
type Product @key(fields: "upc") {
upc: String!
name: String!
price: Int!
}
type Query {
product_by_upc(upc: String!) : Product
}
schema { query: Query }
当我执行跨越服务的查询时:
{
user_by_id(id: "me") {
id
name
favorite_products {
upc
name
price
}
}
}
我失败了;以下请求被发送到products
服务:
INFO products.server - {:query "query($representations:[_Any!]!){_entities(representations:$representations){...on User{favorite_products{upc name price}}}}", :vars {:representations [{:__typename "User", :id "me"}]}, :line 52}
这失败了,因为据我所知,产品服务不应该提供等效于__resolveReference
for 类型User
(它扩展了);只需键入Product
.
这在文档中非常不清楚,我将尝试在 Product 中为用户的存根提供一种存根引用解析器。