Skip to content

Commit be1f7d7

Browse files
authored
Merge pull request #644 from frsv/issue-643_fields_capitalizes_incorrectly
Change .title method to .capitalize in to_camel_case() in str_convertes.py
2 parents 38db32e + 9dde259 commit be1f7d7

File tree

2 files changed

+4
-3
lines changed

2 files changed

+4
-3
lines changed

graphene/utils/str_converters.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
import re
22

33

4-
# From this response in Stackoverflow
4+
# Adapted from this response in Stackoverflow
55
# http://stackoverflow.com/a/19053800/1072990
66
def to_camel_case(snake_str):
77
components = snake_str.split('_')
88
# We capitalize the first letter of each component except the first one
9-
# with the 'title' method and join them together.
10-
return components[0] + "".join(x.title() if x else '_' for x in components[1:])
9+
# with the 'capitalize' method and join them together.
10+
return components[0] + ''.join(x.capitalize() if x else '_' for x in components[1:])
1111

1212

1313
# From this response in Stackoverflow

graphene/utils/tests/test_str_converters.py

+1
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ def test_camel_case():
1616
assert to_camel_case('snakes_on_a_plane') == 'snakesOnAPlane'
1717
assert to_camel_case('snakes_on_a__plane') == 'snakesOnA_Plane'
1818
assert to_camel_case('i_phone_hysteria') == 'iPhoneHysteria'
19+
assert to_camel_case('field_i18n') == 'fieldI18n'
1920

2021

2122
def test_to_const():

0 commit comments

Comments
 (0)