【问题标题】:Why am I seeing the _entities request in one service when the entity is native to another?当实体是另一个实体的本机时,为什么我会在一个服务中看到 _entities 请求?
【发布时间】:2020-09-09 06:40:57
【问题描述】:

我正在努力实现与 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}

这失败了,因为据我所知,产品服务不应该为 User 类型提供等效的 __resolveReference (它扩展了);只需输入Product

这在文档中非常不清楚,我将尝试在 Product 中为用户的存根提供一种存根引用解析器。

【问题讨论】:

  • 好的,我现在可以看到产品服务确实必须为User 实现一种存根,这确实有意义。

标签: apollo-federation


【解决方案1】:

是的,确实,您必须为服务架构扩展的每种类型提供__resolveReference(或等效项)。回想起来,这是有道理的,因为它提供了原始值的“内核”以向下传递到解析器树。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-10-11
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多