如何解决阿波罗联盟抛出错误:标记为@external 但未在基础服务上定义
我正在使用阿波罗联邦并在尝试创建类似于计算字段 (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
服务中,我存储有关用户的信息,并在 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
类型获得订阅。
解决方法
确保将两个 graphql 模式放在同一个网关中。在我的应用程序中有 2 个不同的网关,我将它们放在 2 个不同的网关中。以上代码运行良好。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。