apollographql / apollographql/federation
KEY_FIELDS_MISSING_ON_BASE incorrect error message
- Dominant language
- TypeScript
- Stars
- 725
- Forks
- 276
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 1
Description
The issue: when a subgraph has an `@key` directive that selects a field that doesn't exist on the base, and the base also has a `@key` directive that selects a field that doesn't exist on itself, 2 errors are returned, one for each service. However, the error returned for service B says `[serviceB] Product -> A @key selects featuredItem, but Product.featuredItem was either created or overwritten by serviceB, not serviceB` I think the federation metadata in this specific case is the issue. The `namedType` in `keyFieldsMissingOnBase.ts` also corresponds to service A, not service B. The location returned here, for example is the location of `Product` in service A.
I wrote a test for composeAndValidate to illustrate this issue. In the attached example, the expected snapshot is the actual result.
```
it.only('maya test', () => {
const serviceA = {
typeDefs: gql`
type Product @key(fields: "featuredItem") {
sku: String!
}
type Query {
product: Product
}
`,
name: 'serviceA',
};
const serviceB = {
typeDefs: gql`
type test {
field: String
}
extend type Product @key(fields: "featuredItem") {
featuredItem: String!
}
`,
name: 'serviceB',
};
const compositionResult = composeAndValidate([serviceA, serviceB]);
assertCompositionFailure(compositionResult);
expect(compositionResult.errors).toMatchInlineSnapshot(`
Array [
Object {
"code": "KEY_FIELDS_MISSING_EXTERNAL",
"locations": Array [
Object {
"column": 3,
"line": 7,
},
],
"message": "[serviceB] Product -> A @key directive specifies the \`featuredItem\` field which has no matching @external field.",
},
Object {
"code": "KEY_FIELDS_MISSING_ON_BASE",
"locations": Array [
Object {
"column": 1,
"line": 2,
},
],
"message": "[serviceA] Product -> A @key selects featuredItem, but Product.featuredItem was either created or overwritten by serviceB, not serviceA",
},
Object {
"code": "KEY_FIELDS_MISSING_ON_BASE",
"locations": Array [
Object {
"column": 1,
"line": 2,
},
],
"message": "[serviceB] Product -> A @key selects featuredItem, but Product.featuredItem was either created or overwritten by serviceB, not serviceB",
},
]
`);
});
```
I can add more to this issue on Monday. Wanted to flag it b/c @michael-watson discovered it.
Contributor guide
Assessment
This issue has not been assessed yet.