Repository navigation
Fail with a clear error when unions contain themselves - #902
Conversation
Both tests fail with a StackOverflowError.
getLeafUnionObjects expanded nested unions recursively without tracking which ones it was already expanding, so a union that lists itself, directly or through another union, overflowed the stack. It now keeps the path of unions it is expanding and throws a SchemaError that names the cycle and points at the member that closes it.
|
|
PASS+NOTES |



Fixes #886
Checklist
Description
Unions that list each other, or a union that lists itself, failed the build with a
StackOverflowError:SchemaParser#getLeafUnionObjectsflattens nested unions recursively and didn't keep track of the unions it was already expanding. It now passes down the path of unions it's in, and when a member is already on that path it throws aSchemaErrorthat names the cycle and points at the member that closes it:I went with the error instead of flattening each union once, since the spec doesn't allow union members at all and nobody asked for cycles. These schemas never built, so nothing that builds today breaks. Only the current path is checked, so two nested unions that share a member without a cycle still build.
mvn clean verifypasses, also against graphql-java 25.1. Also built the schema above through the public API: master overflows, with this change it fails with the error above. Through the same harness, the existing nested union case (union Media = Movie) and a shared member (Result = Media | Shelf, both listingBook) still build and return both aBookand aMovie.