During our monthly call we had a great feature request related to returning errors. There's consensus in GraphQL around modelling errors in the schema (https://sachee.medium.com/200-ok-error-handling-in-graphql-7ec869aec9bc).
We can provide a way for "raising" errors anywhere in the resolver context and then strawberry would catch these exception and then strawberry would handle the exception and return the error for you.
Some ideas for API:
@strawberry.type
class SomeError:
message: str = "π΅"
@strawberry.type
class Mutation:
@strawberry.mutation
def send_email(self, email: str) -> bool | SomeError:
raise StrawberryException(SomeError())
@strawberry.type
class SomeError(Exception):
message: str = "π΅"
@strawberry.type
class Mutation:
@strawberry.mutation
def send_email(self, email: str) -> bool | SomeError:
raise SomeError() # this can be deeply nested
@strawberry.error_type
class SomeError:
message: str = "π΅"
@strawberry.type
class Mutation:
@strawberry.mutation
def send_email(self, email: str) -> bool | SomeError:
raise SomeError() # this can be deeply nested
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