NodeJS Apollo联盟抛出错误:标记为@external,但未在的基本服务上定义

pod7payv  于 2023-01-12  发布在  Node.js
关注(0)|答案(2)|浏览(105)

我正在使用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)

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

l7wslrjt

l7wslrjt1#

确保你把两个graphql模式放在同一个网关中。在我的应用程序中有2个不同的网关,我把它们放在2个不同的网关中。上面的代码工作得很完美。

xxb16uws

xxb16uws2#

还要检查扩展类的类中是否有@GqlKey('id')
例如:

@ObjectType({
  description: 'Extended Class',
})
@GqlKey('id') // <- Check if this extention exist 
export class ClassName{
  @Field(() => ID)
  @Expose()
  id: string;
  ...
}

相关问题