我正在使用Apollo联邦,当尝试创建类似于计算字段的内容时遇到错误(https://www.apollographql.com/docs/federation/entities/# extending-an-entity-with-computed-fields-advanced):
Error: A valid schema couldn't be composed. The following composition errors were found:client-api-gateway_1
[Payments MS] User.parentId -> marked @external but parentId is not defined on the base service of User (Users MS)
我有两项服务:Users
和Payments
。在users
服务中,i存储关于用户的信息,并且在payments
中,存储关于连接到用户的支付的信息。Users
服务图:
type User @key(fields: "id") {
id: Int!
name: String!
surname: String!
type: USER_TYPE!
parentId: Int
}
Payments
服务图:
type UserSubscriptionInfo {
nextChargeAmount: Int
......etc
}
extend type User @key(fields: "id") {
id: Int! @external
parentId: Int @external
subscription: UserSubscriptionInfo @requires(fields: "parentId")
}
基于用户类型parentId
,我希望通过扩展User
类型获得订阅。
2条答案
按热度按时间l7wslrjt1#
确保你把两个graphql模式放在同一个网关中。在我的应用程序中有2个不同的网关,我把它们放在2个不同的网关中。上面的代码工作得很完美。
xxb16uws2#
还要检查扩展类的类中是否有
@GqlKey('id')
例如: