2

i'm using apollo federation and meet with error, when trying to make something similar to computed fields (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)

I have two services: Users and Payments. In users service i store information about users, and in payments information about payments connected to user.

Users service graph:

type User @key(fields: "id") {
        id: Int!
        name: String!
        surname: String!
        type: USER_TYPE!
        parentId: Int
    }

Payments service graph:

type UserSubscriptionInfo {
     nextChargeAmount: Int
     ......etc
}

extend type User @key(fields: "id") {
     id: Int! @external
     parentId: Int @external
     subscription: UserSubscriptionInfo @requires(fields: "parentId")
}

Based on parentId from User type i would like to get subscription, by extending User type.

Marcin Warzybok
  • 357
  • 4
  • 16
  • I am facing same issue. Can you provide me a different solution if u have? Because both my graphql schemas are in same gateway. – Swetha Oct 14 '21 at 18:02

2 Answers2

1

Make sure you put both graphql schemas in the same gateway. In my app there was 2 different gateways and i put them in 2 different gateways. Above code is working perfectly.

Marcin Warzybok
  • 357
  • 4
  • 16
0

Check also if the extended class has @GqlKey('id') in its class

For example :


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