graphql-python / graphql-python/graphene

non-reversible case conversion

Open
#1,204 2 comments 0 reactions 0 assignees View on GitHub
🐛 bug
Dominant language
Python
Stars
8.2k
Forks
818
PR merge metrics
No merged PRs in 30d

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

Contributor guide

No contributing guide indexed for this repository

Research direction

Start in graphene.utils.str_converters and reproduce the documented to_camel_case and to_snake_case examples. Compare the two suggested treatments of trailing numbers, then define the expected round-trip behavior and verify that the conversion preserves the underscore before the final number.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.