graphql-query icon indicating copy to clipboard operation
graphql-query copied to clipboard

Singular union type is not supported for composite type with `graphql_fields`

Open kyle-kc opened this issue 6 months ago • 2 comments

Describe the bug When using a singular union type with graphql_fields (i.e. a field with a union type with only one sub-type within the union), the field is rendered only with the fields within the singular type, not using an ... on statement for composite types. This breaks if you're querying a composite type but only want one potential return type.

To Reproduce Steps to reproduce the behavior: Create the following classes:

class ClassA:
    x: int

class ClassB:
    y: Union[ClassA]

Then call ClassB.graphql_fields(). This renders as:

y {
    x
}

Expected behavior It should render as

y {
    ... on ClassA {
        x
    }
}

kyle-kc avatar Jul 31 '24 15:07 kyle-kc