graphql-python / graphql-python/graphene

non-reversible case conversion

Offen
#1,204 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
🐛 bug
Vorherrschende Sprache
Python
Sterne
8.2k
Forks
818
PR-Merge-Kennzahlen
Keine gemergten PRs in 30 T.

Beschreibung

* **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`).

Beitragsleitfaden

Für dieses Repository ist kein Beitragsleitfaden indexiert

Bewertung

Dieses Issue wurde noch nicht bewertet.

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.