It would be nice to be able to make a generic union type to allow Success | Failure union types
currently this won't work:
@strawberry.type(model.Error, all_fields=True)
class ErrorType:
pass
T = TypeVar("T")
Result = strawberry.union("Result", (T, ErrorType))
As noted by @doctor#7942 on Discord (couldn't mention in the issue) it's possible to achieve desired results using Pydantic as follows:
from typing import TypeVar, Union
class Error:
pass
T = TypeVar("T")
TOrError = Union[T, Error]
int_or_error: TOrError[int] = 42
A reproducible example made by @patrick91 on Strawberry Playground
Pay now to fund the work behind this issue.
Get updates on progress being made.
Maintainer is rewarded once the issue is completed.
You're funding impactful open source efforts
You want to contribute to this effort
You want to get funding like this too