Open fireteam99 opened 1 year ago
Unions have names in graphql, that's why strawberry.union
exists. It allows us to specify the unions name (Pet
in your example). Unfortunately there is no way to extract the unions name from Pet = Union[Cat, Dog]
, since Pet
is a variable and it's name is not accessible to us :)
Feel free to reopen if I missed something :)
Thanks for the explanation @DoctorJohn! Would it be worth adding this to the documentation?
Good point @fireteam99, while checking the documentation I noticed that I actually missed something: We support union creation without strawberry.union
by just using typing.Union
. In this case the graphql union name is generated based on the types passed as union arguments. Considering this it should be possible for strawberry to support the code you posted.
Reopening the issue (sorry for closing it, didn't remember we had that feature when answering earlier).
No worries thanks for re-opening!
Feature Request Type
Description
It seems like python (
typing
) union types don't work with the lazy annotations documented here: https://strawberry.rocks/docs/types/lazy. If i have two types that need to import from each other: Kennel and Pet(union of Cat and Dog) . I will get the following error if I try to do a lazy annotation on the union type.throws:
As mentioned by @patrick91 you work around this issue by swapping
typing
'sUnion
withstrawberry.union
.Discord convo: https://discord.com/channels/689806334337482765/1036814233234579526/1036814233234579526
Upvote & Fund