Skip to content

Commit 87eb526

Browse files
committed
coerce_string should return a unicode string always.
* For some reason, once string coercion was changed to unicode, I noticed some stuff in Schema going awry. This led me to realize that types in a Schema weren't being ordered. They should be though, so I changed the schema.type_map() to return an OrderedDict. This removed the need for `sort_lists` in the schema tests. So I got rid of those too. Closes #21
1 parent eaf229c commit 87eb526

File tree

5 files changed

+314
-368
lines changed

5 files changed

+314
-368
lines changed

graphql/core/type/scalars.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from six import text_type
12
from ..language.ast import (
23
BooleanValue,
34
FloatValue,
@@ -61,13 +62,15 @@ def parse_float_literal(ast):
6162

6263
def coerce_string(value):
6364
if isinstance(value, bool):
64-
return 'true' if value else 'false'
65-
return str(value)
65+
return u'true' if value else u'false'
66+
67+
return text_type(value)
6668

6769

6870
def parse_string_literal(ast):
6971
if isinstance(ast, StringValue):
7072
return ast.value
73+
7174
return None
7275

7376
GraphQLString = GraphQLScalarType(name='String',

graphql/core/type/schema.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import OrderedDict
12
from .definition import (
23
GraphQLInputObjectType,
34
GraphQLInterfaceType,
@@ -70,7 +71,7 @@ def get_directive(self, name):
7071
return None
7172

7273
def _build_type_map(self):
73-
type_map = {}
74+
type_map = OrderedDict()
7475
for type in (self.get_query_type(), self.get_mutation_type(), IntrospectionSchema):
7576
type_map = type_map_reducer(type_map, type)
7677

tests/core_execution/test_variables.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -612,4 +612,4 @@ def test_when_argument_provided_cannot_be_parsed(self):
612612
'data': {
613613
'fieldWithDefaultArgumentValue': '"Hello World"'
614614
}
615-
})
615+
})

0 commit comments

Comments
 (0)