阿波罗联盟抛出错误:标记为@external 但未在基础服务上定义

时间:2021-06-10 10:37:05

标签: node.js graphql apollo apollo-federation

我正在使用阿波罗联邦并在尝试创建类似于计算字段 (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)

我有两个服务:UsersPayments。在 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 类型获得订阅。

1 个答案:

答案 0 :(得分:0)

确保将两个 graphql 模式放在同一个网关中。在我的应用程序中有 2 个不同的网关,我将它们放在 2 个不同的网关中。以上代码运行良好。

相关问题