strawberry-graphql / strawberry-django

Strawberry GraphQL Django extension
https://strawberry.rocks/docs/django
MIT License
411 stars 118 forks source link

Provide ValidationError code in OperationMessage #356

Closed zvyn closed 1 year ago

zvyn commented 1 year ago

I propose to extend the OperationMessage by a code attribute that is set to the ValidationError.code if a ValidationError was raised.

Feature Request Type

Description

The Django ValidationError has a code attribute which can be set on initialization. This feature is already used by Django internally and part of the official API for most validators.

Our use-case: For a project with optional client-side localization we want to provide predictable error codes that can be translated by the client without parsing the human-friendly message string. I'm sure there are other use-cases as well.

I can work on a pull request for this in case you are interested!

Upvote & Fund

Fund with Polar

bellini666 commented 1 year ago

I like this :)

Feel free to work on this and open a PR, I'll gladly review it when it is submitted.