我正在使用 Apollo Federation 2 个月,但实际上我被卡住了。我不知道如何在我的两个 graphql 服务之间传递变量。
我有一个网站(网站 graphql 服务),其中包含订单(orders graphql 服务)。我有一个查询来查找网站,对于这些网站,我想要一些日期范围内的订单统计信息。这里的typedef(网站):
type Query {
websites(orderFilter: OrderFilterInput): [Website!]
}
type Website @key(fields: "id") {
id: ID!
name: String!
url: String!
orderSummary(orderFilter: OrderSummaryFilterInput): OrderSummary
}
input OrderSummaryFilterInput {
beginDate: Date
endDate: Date
}
extend type OrderSummary @key(fields: "websiteId") {
websiteId: String! @external
}
解析器:
orderSummary: (website, { orderSummaryFilter }) => {
console.log("orderSummaryFilter", orderSummaryFilter); // filters are OK
// HOW CAN I PASS orderFilterSummary to my order graphql service here ????
return { __typename: "OrderSummary", websiteId: website.id };
}
并订购graphql服务
类型定义部分:
type OrderSummary @key(fields: "websiteId") {
websiteId: String!
count: Int
amount: Int
}
解析器部分:
// order gql service
OrderSummary: {
__resolveReference(website, args, info) {
console.log("website id :", website.id); // I ve got my website ID
// HOW TO GET OrderSummaryFilter here ????
},
},
如何在 order graphql resolver 中访问 order summary filter 变量?谢谢你。