apollographql / apollographql/federation
Maximum call stack error on recursive `@requires` directives
- Dominant language
- TypeScript
- Stars
- 725
- Forks
- 276
- Avg merge
- 1h 47m
- Merged PRs (30d)
- 1
Description
### Issue Description
This is low priority.
When writing a subgraph schema and you happen to requires a field that also requires _that_ field, you end up with a composition failure due to a maximum call stack size.
Ideally this should be a composition error to provide clear reasoning as to why it was happening.
### Link to Reproduction
https://codesandbox.io/p/sandbox/apollo-gateway-ckyqqj
### Reproduction Steps
Given subgraph a:
```
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@key", "@external", "@requires"])
type Query {
f: [Foo!]!
}
type Foo @key(fields: "id") {
id: ID!
bar: Bar! @requires(fields:"baz { b }")
baz: Baz! @external
}
type Bar {
a: String!
}
type Baz {
b: String! @external
}
```
And subgraph b:
```
extend schema
@link(url: "https://specs.apollo.dev/federation/v2.3", import: ["@key", "@external", "@requires"])
type Foo @key(fields:"id"){
id: ID!
bar: Bar! @external
baz: Baz! @requires(fields:"bar { a }")
}
type Bar {
a: String! @external
}
type Baz {
b: String!
}
```
And trying to compose via Rover, you'll get:
```
rover supergraph compose --config supergraph.yaml > schema.graphqls
⌛ resolving SDL for subgraphs defined in supergraph.yaml
🎶 composing supergraph with Federation v2.5.4
error[E029]: Encountered 1 build error while trying to build a supergraph.
Caused by:
UNKNOWN: RangeError: Maximum call stack size exceeded
The subgraph schemas you provided are incompatible with each other. See https://www.apollographql.com/docs/federation/errors/ for more information on resolving build errors.
```
And similar for the code example.
Contributor guide
Research direction
Run the provided subgraph schemas through the documented Rover supergraph compose command and confirm the recursive @requires case reproduces the maximum call stack error. Trace the composition path involved in resolving these directives; done means the same schemas produce a clear composition error explaining the recursion instead of a stack overflow.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- backend-api-design
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 52/100