Skip to content

Commit 63c9a4d

Browse files
committed
Simplified fields implementation
1 parent 025df39 commit 63c9a4d

File tree

3 files changed

+23
-40
lines changed

3 files changed

+23
-40
lines changed

graphql/type/definition.py

Lines changed: 2 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -210,10 +210,6 @@ def define_field_map(type, field_map):
210210
'function which returns such a mapping.'
211211
).format(type)
212212

213-
if not isinstance(field_map, collections.OrderedDict):
214-
field_map = collections.OrderedDict(sorted(list(field_map.items())))
215-
216-
result_field_map = collections.OrderedDict()
217213
for field_name, field in field_map.items():
218214
assert_valid_name(field_name)
219215
field_args = getattr(field, 'args', None)
@@ -223,19 +219,11 @@ def define_field_map(type, field_map):
223219
'{}.{} args must be a mapping (dict / OrderedDict) with argument names as keys.'.format(type,
224220
field_name)
225221
)
226-
args = collections.OrderedDict()
227-
if not isinstance(field_args, collections.OrderedDict):
228-
field_args = collections.OrderedDict(sorted(list(field_args.items())))
229222

230223
for arg_name, arg in field_args.items():
231224
assert_valid_name(arg_name)
232-
args[arg_name] = arg
233-
234-
field.args = args
235225

236-
result_field_map[field_name] = field
237-
238-
return result_field_map
226+
return field_map
239227

240228

241229
def define_interfaces(type, interfaces):
@@ -574,15 +562,10 @@ def _define_field_map(self):
574562
'function which returns such a mapping.'
575563
).format(self)
576564

577-
if not isinstance(fields, collections.OrderedDict):
578-
fields = collections.OrderedDict(sorted(list(fields.items())))
579-
580-
field_map = collections.OrderedDict()
581565
for field_name, field in fields.items():
582566
assert_valid_name(field_name)
583-
field_map[field_name] = field
584567

585-
return field_map
568+
return fields
586569

587570

588571
class GraphQLInputObjectField(object):

graphql/type/introspection.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22

33
from ..language.printer import print_ast
44
from ..utils.ast_from_value import ast_from_value
5-
from .definition import (GraphQLArgument, GraphQLArgument,
6-
GraphQLEnumType, GraphQLEnumValue, GraphQLField,
5+
from .definition import (GraphQLArgument, GraphQLEnumType,
6+
GraphQLEnumValue, GraphQLField,
77
GraphQLInputObjectType,
88
GraphQLInterfaceType, GraphQLList, GraphQLNonNull,
99
GraphQLObjectType, GraphQLScalarType,

graphql/type/tests/test_definition.py

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -307,25 +307,25 @@ def test_does_not_mutate_passed_field_definitions():
307307
}
308308

309309

310-
def test_sorts_fields_and_argument_keys_if_not_using_ordered_dict():
311-
fields = {
312-
'b': GraphQLField(GraphQLString),
313-
'c': GraphQLField(GraphQLString),
314-
'a': GraphQLField(GraphQLString),
315-
'd': GraphQLField(GraphQLString, args={
316-
'q': GraphQLArgument(GraphQLString),
317-
'x': GraphQLArgument(GraphQLString),
318-
'v': GraphQLArgument(GraphQLString),
319-
'a': GraphQLArgument(GraphQLString),
320-
'n': GraphQLArgument(GraphQLString)
321-
})
322-
}
323-
324-
test_object = GraphQLObjectType(name='Test', fields=fields)
325-
ordered_fields = test_object.get_fields()
326-
assert list(ordered_fields.keys()) == ['a', 'b', 'c', 'd']
327-
field_with_args = test_object.get_fields().get('d')
328-
assert list(field_with_args.args.keys()) == ['a', 'n', 'q', 'v', 'x']
310+
# def test_sorts_fields_and_argument_keys_if_not_using_ordered_dict():
311+
# fields = {
312+
# 'b': GraphQLField(GraphQLString),
313+
# 'c': GraphQLField(GraphQLString),
314+
# 'a': GraphQLField(GraphQLString),
315+
# 'd': GraphQLField(GraphQLString, args={
316+
# 'q': GraphQLArgument(GraphQLString),
317+
# 'x': GraphQLArgument(GraphQLString),
318+
# 'v': GraphQLArgument(GraphQLString),
319+
# 'a': GraphQLArgument(GraphQLString),
320+
# 'n': GraphQLArgument(GraphQLString)
321+
# })
322+
# }
323+
324+
# test_object = GraphQLObjectType(name='Test', fields=fields)
325+
# ordered_fields = test_object.get_fields()
326+
# assert list(ordered_fields.keys()) == ['a', 'b', 'c', 'd']
327+
# field_with_args = test_object.get_fields().get('d')
328+
# assert list(field_with_args.args.keys()) == ['a', 'n', 'q', 'v', 'x']
329329

330330

331331
def test_does_not_sort_fields_and_argument_keys_when_using_ordered_dict():

0 commit comments

Comments
 (0)