graphql-python / graphql-python/graphene
Conversion to snake_case fails on nested inputs
- Lenguaje dominante
- Python
- Estrellas
- 8.2k
- Forks
- 818
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Descripción
* **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)
Guía de contribución
No hay ninguna guía de contribución indexada para este repositorio
Línea de trabajo
Comienza con la reproducción de RegisterPlaceInput, PlaceInput y PostalAddressInput, y rastrea cómo se convierten los valores anidados de InputObjectType. Reproduce la salida camelCase del nivel más profundo, luego añade cobertura de regresión y verifica que cada clave anidada se convierta a snake_case.
Escrito por el modelo de indexación a partir del texto del issue.
Evaluación
- Stack tecnológico
- graphql, python
- Área
- api, backend
- Tipo de issue
- Error
- Dificultad
- 3/5
- Tiempo estimado
- 1-2 días
- Estado de actividad
- Estancado
- Claridad
- Bastante claro
- Aptitud para principiantes
- 45/100