apollographql / apollographql/federation

@key missing on entity extension should fail validation

Open
#190 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
TypeScript
Stars
725
Forks
276
Avg merge
1h 47m
Merged PRs (30d)
1

Description

Per the [federation specification - Entity Referencing](https://www.apollographql.com/docs/apollo-server/federation/entities/#referencing), in order to extend an entity in a different service, the extending service must `define a stub of it to make its own schema valid`.

### Intended outcome
The validation should fail with a validation error informing that the extending service must specify the `@key` directive on the type extension referencing/extending the base type.
### Actual outcome
The validation passes if an extending type does not specify the `@key` directive on the extension.
### How to reproduce the issue:
Example, Service A definition:
```graphql
# Service A
type Query {
hello:String
}
type Product @key(fields: "sku") {
sku: String!
upc: String!
color: Color!
}
type Color {
id: ID!
value: String!
}
```
and Service B definition:
```graphql
# Service B
extend type Product { # missing @key directive
sku: String! @external
price: Int! @requires(fields: "sku")
}
```
should fail validation but it currently passes (on `main`) instead of raising an error.
This [commit](https://github.com/tinnou/federation/commit/b5cf57e1dd53cbdc29599bca2055e702184943e0) implements a test that reproduces the issue.

Contributor guide

Open the contributing guide

Research direction

Start with the Service A and Service B schemas in the issue and examine the reproduction test from commit b5cf57e1dd53cbdc29599bca2055e702184943e0. Trace the federation validation entry point for an entity extension, then run that reproduction to confirm that omitting @key now produces a validation error.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.