strawberry icon indicating copy to clipboard operation
strawberry copied to clipboard

A union of interface and something else is not resolvable

Open MeRuslan opened this issue 2 years ago • 5 comments

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.

MeRuslan avatar May 12 '22 16:05 MeRuslan

here's a gist reproducing the issue: https://play.strawberry.rocks/?gist=6fab0f0ce462e08155d2f5d791431e74

removing (or updating) the assertion we have might fix this :)

patrick91 avatar May 12 '22 16:05 patrick91

a better gist https://play.strawberry.rocks/?gist=d7f2dd2ad9d2fcececf5b6d17fd52b34

nrbnlulu avatar Aug 12 '22 08:08 nrbnlulu

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.

benzolium avatar Aug 12 '22 10:08 benzolium

may be related: https://github.com/graphql/graphql-spec/issues/215

nrbnlulu avatar Aug 16 '22 12:08 nrbnlulu

@patrick91 can you close this?

I think Generic would be a solution here.

nrbnlulu avatar Aug 26 '22 12:08 nrbnlulu