apollographql / apollographql/federation
Allow reference to field without optional arguments in @external definition
- Dominant language
- TypeScript
- Stars
- 725
- Forks
- 276
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 1
Description
Lets say I have this schema today which does compose ✅
* I have one field `Location.photo` that accepts zero arguments today
* I can reference that in another subgraph with `@external`
* I can also request the value to the resolver with `@requires`
Subgraph 1
```graphql
type Query {
locations: [Location]
}
type Location @key(fields: "id") {
id: ID!
name: String!
photo: String!
}
```
Subgraph 2
```graphql
type Location @key(fields: "id") {
id: ID!
photo: String! @external
banner: String @requires(fields: "photo")
}
```
Now lets say I want to add a new optional argument to the `Location.photo` field. If I make this optional or specify a default this is not a breaking change for clients and would be accepted in a monograph as valid, however with composition this now fails
Subgraph 1
```graphql
type Query {
locations: [Location]
}
type Location @key(fields: "id") {
id: ID!
name: String!
photo(smallVersion: Boolean): String! # New optional arg shouldn't break existing clients
}
```
Subgraph 2 ❌ (fails composition)
```graphql
type Location @key(fields: "id") {
id: ID!
photo: String! @external
banner: String @requires(fields: "photo")
}
```
In order to fix this I need to go to every subgraph reference and update those as well
Subgraph 1
```graphql
type Query {
locations: [Location]
}
type Location @key(fields: "id") {
id: ID!
name: String!
photo(smallVersion: Boolean): String! # New optional arg shouldn't break existing clients
}
```
Subgraph 2 ✅ (passes composition)
```graphql
type Location @key(fields: "id") {
id: ID!
photo(smallVersion: Boolean): String! @external # Need to update reference here and in every subgraph (blocking composition pipeline)
banner: String @requires(fields: "photo")
}
```
## What I would like to happen
Instead it would be nice if composition recognized when we are only referencing fields with optional arguments and not including them will not break any operations.
## Caveat
There is a bit of a work around today which I am not sure is intentional or not, but you can actually add the reference first to the `@external` field only and this will not break composition, then you can go and add it to the source field.
Contributor guide
Research direction
Reproduce the issue with the two-subgraph schemas shown in the report, first with a zero-argument field and then with an optional argument added to the source field. Trace the composition validation for the @external reference and add a regression case covering the expected successful composition. Done means optional arguments can be added without updating every reference, while required arguments still remain validated.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- graphql, typescript
- Domain
- api, backend-api-design
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100