Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Singular union type is not supported for composite type with graphql_fields #44

Open
kyle-kc opened this issue Jul 31, 2024 · 2 comments
Assignees
Labels
help wanted Extra attention is needed

Comments

@kyle-kc
Copy link

kyle-kc commented Jul 31, 2024

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
    }
}
@denisart
Copy link
Owner

Yes, it works like that by default. I think that this need fix

Thank for your feedback about this feature! I haven't tested it much.

@denisart denisart self-assigned this Jul 31, 2024
@denisart denisart added the bug Something isn't working label Jul 31, 2024
@denisart
Copy link
Owner

denisart commented Aug 1, 2024

I understood why it was done this way.

Because Union[ClassA] it is defined as a type ClassA.
See https://docs.python.org/3/library/typing.html#typing.Union

@denisart denisart added help wanted Extra attention is needed and removed bug Something isn't working labels Aug 1, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
help wanted Extra attention is needed
Projects
None yet
Development

No branches or pull requests

2 participants