Fields' names are snake_case in SerializerMutation errors
See original GitHub issueWhen 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." ] } ] } } }
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:6 (3 by maintainers)
Top Results From Across the Web
Graphene Documentation - Read the Docs
These errors have two fields: field, a string containing the name of the invalid form field, and messages, a list of strings with...
Read more >unable to create a SerializerMutation without errors, but data ...
I do not why but when I try to create new data using serializermutation, data is created but graphiql return an error. Here...
Read more >1. Naming rules - GraphQL Rules
Use camelCase for GraphQL fields and arguments. 1.2. Use UpperCamelCase for GraphQL types. 1.3. Use CAPITALIZED_WITH_UNDERSCORES to name ENUM types. 1.4. Avoid ...
Read more >Mutations - Graphene-Python
These errors have two fields: field , a string containing the name of the invalid ... from graphene_django.rest_framework.mutation import SerializerMutation ...
Read more >Snake case property names - Json.NET
This sample uses a T:Newtonsoft.Json.Serialization.SnakeCaseNamingStrategy specified using a contract resolver to snake case serialized property names.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
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@kamilkijak will this PR fix your issue: https://github.com/graphql-python/graphene-django/pull/514 ?