graphql-python / graphql-python/graphene
Conversion to snake_case fails on nested inputs
- Lingua principale
- Python
- Stelle
- 8.2k
- Fork
- 818
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
* **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)
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Inizia riproducendo RegisterPlaceInput, PlaceInput e PostalAddressInput e traccia il modo in cui vengono convertiti i valori InputObjectType annidati. Riproduci l'output camelCase al livello più profondo, quindi aggiungi la copertura di regressione e verifica che ogni chiave annidata venga convertita in snake_case.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- graphql, python
- Ambito
- api, backend
- Tipo di issue
- Bug
- Difficoltà
- 3/5
- Tempo stimato
- 1-2 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 45/100