Skip to content

Interface Using a Union Fails when Implemented #382

Closed as duplicate
Closed as duplicate

Description

@MFoster

Currently using graphql-spring-boot 5.10.0

I have an interface that defines two properties. Both properties are defined with a type that is a union, this is done so that it can be implemented and overridden with a concrete type that is one of the union types defined in the schema. Here is a simplified version of the schema to illustrate this structure in GQL.

union SortResponse = NodeSortResponse
union Result = Node

interface SearchResponse {
    results: [Result!]!
    order: SortResponse
}

type Node {
    id: ID!
    title: String
}
type NodeSortResponse {
    field: NodeSortField
    direction: SortDirection
}
type NodeSearchResponse implements SearchResponse {
    results: [Node!]!
    order: NodeSortResponse
}

The exception is thrown in SchemaParser.kt on line 349. It fails the conditional that it is an acceptable output type. The property for unionDefinitions doesn't have the union in its list.

Activity

  1. oliemansm commented on Apr 4, 2020

    @oliemansm
    Member

    The unions you defined here don't actually seem to be doing a union though? So I'd expect something like union Result = Node | OtherNode. That might be why it's not added to the unionDefinitions. This seems to be a graphql-java-tools issue though, so I'll transfer this issue to that project.

  2. vojtapol commented on Apr 16, 2020

    @vojtapol
    Member

    I think we do not properly handle the case where a union only has a single type. I think we should just throw an error as it does not seem to be a valid grammar.

    https://graphql.org/learn/schema/#union-types

  3. lqc commented on Mar 14, 2021

    @lqc

    You are looking at an example, not the spec:

    "A Union type must include one or more unique member types."

    Having a union with a single type is useful because you can also extend unions.

  4. oryan-block commented on Oct 3, 2026

    @oryan-block
    Collaborator

    Closing as a duplicate of #597. Same root cause: a union referenced only from interface fields is never discovered by the scanner. Workaround until it is fixed: includeUnusedTypes(true) plus dictionary entries for the union members.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions