graphql-python / graphql-python/graphene

non-reversible case conversion

Aperta
#1,204 2 commenti 0 reazioni 0 assegnatari Vedi su GitHub
🐛 bug
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?**
```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`).

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Valutazione

Questa issue non è ancora stata valutata.

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.