Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fields' names are snake_case in SerializerMutation errors #556

Closed
kamilkijak opened this issue Nov 22, 2018 · 6 comments
Closed

Fields' names are snake_case in SerializerMutation errors #556

kamilkijak opened this issue Nov 22, 2018 · 6 comments

Comments

@kamilkijak
Copy link

kamilkijak commented Nov 22, 2018

When serializer is not valid, SerializerMutation returns errors where fields' names are snake_case (default DRF behaviour). I believe that it's easier for the client to use pascalCase which is used for the input of mutation.

Simplified example:

  • serializers.py
    from rest_framework import serializers
    
    class UserSerializer(serializers.ModelSerializer):
        class Meta:
            model = User
            fields = ('birth_date', )
    
        def validate_birth_date(self, value):
            age = calculate_age(value)
            if int(age) < 18:
                raise serializers.ValidationError(
                    'Sorry, you must be at least 18 years old.'
                )
            return value
  • schema.py
    from graphene_django.rest_framework.mutation import SerializerMutation
    
    class UserMutation(SerializerMutation):
        class Meta:
            serializer_class = UserSerializer
  • GraphQL mutation
    mutation CreateUser {
      signUp(input: {birthDate: "2010-01-01"}) {
        birthDate
        errors {
          field
          messages
        }
      }
    }
  • Response with birth_date in errors (instead of birthDate)
    {
      "data": {
        "signUp": {
          "birthDate": null,
          "errors": [
            {
              "field": "birth_date",
              "messages": [
                "Sorry, you must be at least 18 years old."
              ]
            }
          ]
        }
      }
    }
@kamilkijak kamilkijak changed the title ields in SerializerMutation errors Fields' names are snake_case in SerializerMutation errors Nov 22, 2018
@BossGrand
Copy link
Member

Where do serializes come from?

@kamilkijak
Copy link
Author

kamilkijak commented Mar 27, 2019

From django-rest-framework, I updated the issue as well.

@stale
Copy link

stale bot commented Jun 11, 2019

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jun 11, 2019
@kamilkijak
Copy link
Author

@BossGrand just a friendly ping to not to let the bot close this issue :-)

@stale stale bot removed the wontfix label Jun 14, 2019
@jkimbo
Copy link
Member

jkimbo commented Jun 14, 2019

@kamilkijak will this PR fix your issue: #514 ?

@jkimbo
Copy link
Member

jkimbo commented Jul 13, 2019

This issue should be fixed in v2.4.0 by setting the CAMELCASE_ERRORS setting: http://docs.graphene-python.org/projects/django/en/latest/settings/#camelcase-errors

@jkimbo jkimbo closed this as completed Jul 13, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants