Hello everyone!
I have the following idea:
I took the example from the docs, trying to add the error to the response, but it didn't work.
Approach 1: @relay.connection(relay.ListConnection[Fruit] | Error)
import strawberry
from strawberry import relay
from strawberry.types import Info
from typing import Iterable
@strawberry.type
class Fruit(relay.Node):
...
@classmethod
def resolve_nodes(cls, *, info, node_ids, required = False):
return [
all_fruits[int(nid)] if required else all_fruits.get(nid)
for nid in node_ids
]
all_fruits = { ... }
@strawberry.type
class Error:
message: str
@strawberry.type
class Query:
node: relay.Node = relay.node()
@relay.connection(relay.ListConnection[Fruit] | Error)
def fruits(self) -> Iterable[Fruit]:
# return all the fruits or an error
...
schema = strawberry.Schema(query=Query)
This one raises RelayWrongAnnotationError: Wrong annotation used on field "fruits". It should be annotated with a "Connection" subclass.
Approach 2: -> Iterable[Fruit] | Error
...
@strawberry.type
class Query:
node: relay.Node = relay.node()
@relay.connection(relay.ListConnection[Fruit])
def fruits(self) -> Iterable[Fruit] | Error:
# return all the fruits or an error
...
...
In this case, a different exception is raises: TypeError: Query fields cannot be resolved. issubclass() arg 1 must be a class
.
Am I doing it wrong?
By the way, I had similar issues with strawberry-django-plus
, but they were quite different:
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