Repository navigation
Commit 29c87af
Discover unions and interfaces used only by interface fields
An implementation may narrow an interface field to one member of the
field's union (or one implementor of its interface), which is valid
GraphQL. The scanner only discovers types through object fields and
"implements" clauses, so a union referenced only from an interface field
was never added to the definitions. The schema build then failed in
createInterfaceObject with "Expected type 'TestUnion' to be a
GraphQLOutputType, but it wasn't!", and the union was logged as unused.
Once nothing else is left to scan, the discovery loop now also walks the
field types of every discovered interface and adds any union or
interface that hasn't been found yet. The existing loops then require
classes for the union's members and the interface's implementors, as
they do for types reached through object fields. Running this step last
keeps the discovery order unchanged for every type reachable some other
way, so a union whose members are only found by scanning dictionary
types is still found after those types are scanned. Unions only used by
interface fields no longer need a dummy field or includeUnusedTypes(true)
to be built.
The step is skipped when includeUnusedTypes is on. The unused types loop
already picks these unions and interfaces up one at a time, scanning in
between, so a member that is only reachable through another member's
class is still found there. Checking all members at once would reject
schemas that build today with the includeUnusedTypes workaround.
Fixes #597, the same problem as #382.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>1 parent 54aae49 commit 29c87af
2 files changed
Lines changed: 526 additions & 0 deletions
File tree
- src
- main/kotlin/graphql/kickstart/tools
- test/kotlin/graphql/kickstart/tools
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
86 | 86 | | |
87 | 87 | | |
88 | 88 | | |
| 89 | + | |
| 90 | + | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
89 | 94 | | |
90 | 95 | | |
91 | 96 | | |
| |||
273 | 278 | | |
274 | 279 | | |
275 | 280 | | |
| 281 | + | |
| 282 | + | |
| 283 | + | |
| 284 | + | |
| 285 | + | |
| 286 | + | |
| 287 | + | |
| 288 | + | |
| 289 | + | |
| 290 | + | |
| 291 | + | |
| 292 | + | |
| 293 | + | |
| 294 | + | |
| 295 | + | |
| 296 | + | |
| 297 | + | |
| 298 | + | |
| 299 | + | |
| 300 | + | |
276 | 301 | | |
277 | 302 | | |
278 | 303 | | |
| |||
0 commit comments