apollographql / apollographql/federation
Is this a known issue in defining an object type with @key in two services?
- Dominant language
- TypeScript
- Stars
- 725
- Forks
- 276
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 1
Description
We have a goal/requirement to have an object type defined in two services while having a third service to extend the object type. To meet this requirement, we made the object type an entity by adding @key.
But we encountered the following error in bringing up the apollo federation:
apollo-gateway: This data graph is missing a valid configuration. [Construct_1-service] Product -> Value types cannot be entities (using the `@key` directive). Please ensure that the `Product` type is extended properly or remove the `@key` directive if this is not an entity.
I wonder why the above error occurred. Is there any way(like defining the schema another way) to get round the error while still having the object type defined in two services? I tried multiple schema changes, but unfortunately, none of them seemed to have worked.
The following shows the schema definitions in four services that resulted in the invalid configuration error in apollo-gateway.
The four services are Company, Construct_1, Construct_2 and Sales.
1) The relevant schema in service Company:
type Company @key(fields: "cName") {
cName: String!
address: String!
...
}
2) The schema in service Construct_1:
extend type Company @key(fields: "cName") {
cName: String! @external
products: [Product!]!
}
type Product @key(fields: "id") {
id: String!
name: String!
}
3) The schema in service Construct_2:
extend type Company @key(fields: "cName") {
cName: String! @external
otherProducts: [Product!]!
}
type Product @key(fields: "id") {
id: String!
name: String!
}
4) The schema in service Sales:
extend type Product @key(fields: "id") {
id: String! @external
saleStatus: String!
}
--
Is this a known issue in apollo federation?
How to resolve it? Is it possible to resolve it by changing the schema?
Contributor guide
Research direction
Start by reproducing the federation composition using the Company, Construct_1, Construct_2, and Sales schema definitions shown in the issue, then inspect the reported value-type and @key validation error. Done means determining whether the requested shared Product type can compose validly and documenting the schema configuration or limitation that resolves the error.
Written by the indexing model from the issue text.
Assessment
- Domain
- api, distributed-systems
- Issue type
- Bug
- Difficulty
- 5/5
- Estimated time
- Over a week
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 25/100