2

我正在使用 apollo federation 并遇到错误,当尝试制作类似于计算字段的东西时(https://www.apollographql.com/docs/federation/entities/#extending-an-entity-with-computed-fields-高级):

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类型来获得订阅。

4

1 回答 1

1

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

于 2021-06-18T11:11:31.070 回答