apollo-federation - 当实体是另一个实体的本机时,为什么我会在一个服务中看到 _entities 请求?
问题描述
我正在努力实现与 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 中为用户的存根提供一种存根引用解析器。
解决方案
是的,确实,您必须为__resolveReference
服务模式扩展的每种类型提供(或等效的)。回想起来,这是有道理的,因为它提供了原始值的“内核”以向下传递到解析器树。
推荐阅读
- android - 如何解决错误“LifecycleOwners must call register before they are STARTED”
- python - _gdbm.error: 数据库需要恢复——在获取 api 数据时存储空间不足
- c# - 传递给此方法或属性的值之一超出范围 - Word 2010 vsto 插件的 Range.ExportFragment 问题
- ruby-on-rails - 确定传入的 CSV 数据和现有的大型数据集 Mongo 集合之间的差异
- reactjs - 如何在 React 中使用 Hooks 将对象存储在 Cookie 中
- plotly - Plotly JS:使用 valueformat 的语言环境数字格式
- powerbi - 同一列 DAX 中两个时间戳之间的时间差
- debugging - CoGroupByKey 在大数据上总是失败(PythonSDK)
- r - 选择特定列,其中列名在另一个 df in r
- java - 不为跳过的项目调用 Spring Batch SkipListener