graphql-python / graphql-python/graphene

Conversion to snake_case fails on nested inputs

Open
#1,537 0 comments 0 reactions 0 assignees View on GitHub
🐛 bug
Dominant language
Python
Stars
8.2k
Forks
818
PR merge metrics
No merged PRs in 30d

Description

* **What is the current behavior?**
I have double nested inputs, the first two levels are properly converted to snake_case, the third one (deepest) is not.

* **If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem** via
a github repo, https://repl.it or similar.

```python
import graphene
from django.contrib.auth import get_user_model

from ..models import Place, PostalAddress

User = get_user_model()

class OwnerInput(graphene.InputObjectType):
first_name = graphene.String(required=True)
last_name = graphene.String(required=True)

class PostalAddressInput(graphene.InputObjectType):
street_address = graphene.String(required=True)
address_locality = graphene.String(required=True)
address_region = graphene.String(required=True)
postal_code = graphene.String(required=True)
address_country = graphene.String(required=True)

class PlaceInput(graphene.InputObjectType):
latitude = graphene.Float(required=True)
longitude = graphene.Float(required=True)
postal_address = graphene.Field(PostalAddressInput, required=True)

class RegisterPlaceInput(graphene.InputObjectType):
owner = graphene.Field(OwnerInput, required=True)
place = graphene.Field(PlaceInput, required=True)

class RegisterPlaceMutation(graphene.Mutation):
class Arguments:
input = graphene.Argument(RegisterPlaceInput, required=True)

success = graphene.Boolean(
description="Indicates whether the operation was successful."
)

def mutate(root, info, input):
print(input)
owner_data = input['owner'] #Converted to snake
place_data = input['place'] #converted to snake at the lower level
postal_address_data = place_data['postal_address'] # remains camel

postal_address = PostalAddress.objects.create(**postal_address_data) #fails as data not in the right shape

place = Place.objects.create(
latitude=place_data['latitude'],
longitude=place_data['longitude'],
postal_address=postal_address,
)

return RegisterPlaceMutation(success=True)

class Mutation(graphene.ObjectType):
register_place = RegisterPlaceMutation.Field()
```

print gives :
```
>> {'owner': {'first_name': 'JOHN', 'last_name
': 'DOE'}, 'place': {'latitude': 48.9230953, 'longitude': 2.0303184, 'postal_address': {'streetAddress': 'Skalitzer Strasse 99', 'addressLocality': 'Berlin', 'addressRegion': 'Berlin', 'post
alCode': '10997', 'addressCountry': 'DE'}}}
```

* **What is the expected behavior?**
All nested object keys are converted to snake_case.

* **What is the motivation / use case for changing the behavior?**
snake_case conversion should be consistent independently of the shape of the input

* **Please tell us about your environment:**

- Version: 3.3
- Platform: with graphene_django 3.2 - (unsure if it's relevant)

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.