graphql-python / graphql-python/graphene

non-reversible case conversion

Ouverte
#1,204 2 commentaires 0 réactions 0 personnes assignées Voir sur GitHub
🐛 bug
Langage dominant
Python
Étoiles
8.2k
Forks
818
Métriques de merge des PR
Aucune PR mergée en 30 j

Description

* **What is the current behavior?**
```python
>>> from graphene.utils.str_converters import to_snake_case
>>> from graphene.utils.str_converters import to_camel_case

>>> to_camel_case("my_variable_1")
'myVariable1'

>>> to_snake_case("myVariable1")
'my_variable1'
```

* **What is the expected behavior?**
```python
>>> from graphene.utils.str_converters import to_snake_case
>>> from graphene.utils.str_converters import to_camel_case

>>> to_camel_case("my_variable_1")
'myVariable1'

>>> to_snake_case("myVariable1")
'my_variable_1'
```

* **What is the motivation / use case for changing the behavior?**

Being able to convert objects/properties back and forth between server and client.
Also useful for introspecting and debugging use cases.

In my particular case, I receive an object on my server that the client got from the api and I want to associate it with the source which I now need an extra mapping for since the conversion is one-directional.

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

Version: graphene-django 2.10.0

* **Other information** (e.g. detailed explanation, stacktraces, related issues, suggestions how to fix, links for us to have context, eg. stackoverflow)

This is where in graphene it is happening: https://github.com/graphql-python/graphene/issues/1204

My current workaround is to add an underscore in case of trailing numbers:
```python
input = re.sub(r'(.*)(\d+)$', r'\1_\2', input)
```

I have 2 solution suggestions:
1. Adding an underscore in case of trailing numbers.
2. Not removing the underscore in case of trailing numbers (like `_1`).

Guide de contribution

Aucun guide de contribution indexé pour ce dépôt

Piste de recherche

Commencez dans graphene.utils.str_converters et reproduisez les exemples documentés de to_camel_case et to_snake_case. Comparez les deux traitements proposés des nombres finaux, puis définissez le comportement aller-retour attendu et vérifiez que la conversion préserve le caractère souligné avant le nombre final.

Rédigé par le modèle d'indexation à partir du texte de l'issue.

Évaluation

Stack technique
python
Domaine
api
Type d'issue
Bug
Difficulté
2/5
Temps estimé
1-3 heures
Activité
À l'abandon
Clarté
Plutôt claire
Accessibilité débutants
35/100

Recevez les nouvelles issues par e-mail

Un résumé court des issues GitHub adaptées aux débutants.