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.
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.