strawberry
strawberry copied to clipboard
A union of interface and something else is not resolvable
Strawberry cannot process a type of Union[strawberry_interface, strawberry_type]
System Information
Macos, latest strawberry (0.111.2 at the moment)
Additional Context
Sample code:
from typing import Union
import strawberry
@strawberry.interface
class Node:
id: strawberry.ID
@strawberry.type
class Error:
message: str
@strawberry.type
class Query:
users: Union[Node, Error]
schema = strawberry.Schema(query=Query)
Fails with
TypeError: Query fields cannot be resolved.
here's a gist reproducing the issue: https://play.strawberry.rocks/?gist=6fab0f0ce462e08155d2f5d791431e74
removing (or updating) the assertion we have might fix this :)
a better gist https://play.strawberry.rocks/?gist=d7f2dd2ad9d2fcececf5b6d17fd52b34
Is it actually a bug? According to spec:
- A Union type must include one or more unique member types.
- The member types of a Union type must all be Object base types; Scalar, Interface and Union types must not be member types of a Union. Similarly, wrapping types must not be member types of a Union.
may be related: https://github.com/graphql/graphql-spec/issues/215
@patrick91 can you close this?
I think Generic would be a solution here.