Skip to content

Unions that list each other fail with a StackOverflowError #886

Open

Description

@oryan-block

Two unions that list each other fail the schema build with a StackOverflowError:

type Query {
    results: [Result!]!
}

union Result = Book | Media

union Media = Movie | Result

Same for a union that lists itself (union Result = Book | Result).

SchemaParser#getLeafUnionObjects expands nested unions recursively and doesn't keep track of the ones it already expanded. On master this only happens when some field returns the inner union, or for the self-member case. Otherwise the scanner fails first with "No object type found". After #866 the scanner gets past that, so the first schema above overflows too.

The spec doesn't allow unions as members at all, so I think either flattening each union once (both would be Book | Movie) or failing with an error that names the unions is fine. Probably the error, since nobody asked for cycles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions