|
| 1 | +from collections import OrderedDict |
1 | 2 | from py.test import raises
|
2 | 3 | from graphql.core.type import (
|
3 | 4 | GraphQLSchema,
|
@@ -275,3 +276,45 @@ def test_does_not_mutate_passed_field_definitions():
|
275 | 276 | 'field1': GraphQLInputObjectField(GraphQLString),
|
276 | 277 | 'field2': GraphQLInputObjectField(GraphQLString),
|
277 | 278 | }
|
| 279 | + |
| 280 | + |
| 281 | +def test_sorts_fields_and_argument_keys_if_not_using_ordered_dict(): |
| 282 | + fields = { |
| 283 | + 'b': GraphQLField(GraphQLString), |
| 284 | + 'c': GraphQLField(GraphQLString), |
| 285 | + 'a': GraphQLField(GraphQLString), |
| 286 | + 'd': GraphQLField(GraphQLString, args={ |
| 287 | + 'q': GraphQLArgument(GraphQLString), |
| 288 | + 'x': GraphQLArgument(GraphQLString), |
| 289 | + 'v': GraphQLArgument(GraphQLString), |
| 290 | + 'a': GraphQLArgument(GraphQLString), |
| 291 | + 'n': GraphQLArgument(GraphQLString) |
| 292 | + }) |
| 293 | + } |
| 294 | + |
| 295 | + test_object = GraphQLObjectType(name='Test', fields=fields) |
| 296 | + ordered_fields = test_object.get_fields() |
| 297 | + assert list(ordered_fields.keys()) == ['a', 'b', 'c', 'd'] |
| 298 | + field_with_args = test_object.get_fields().get('d') |
| 299 | + assert [a.name for a in field_with_args.args] == ['a', 'n', 'q', 'v', 'x'] |
| 300 | + |
| 301 | + |
| 302 | +def test_does_not_sort_fields_and_argument_keys_when_using_ordered_dict(): |
| 303 | + fields = OrderedDict([ |
| 304 | + ('b', GraphQLField(GraphQLString)), |
| 305 | + ('c', GraphQLField(GraphQLString)), |
| 306 | + ('a', GraphQLField(GraphQLString)), |
| 307 | + ('d', GraphQLField(GraphQLString, args=OrderedDict([ |
| 308 | + ('q', GraphQLArgument(GraphQLString)), |
| 309 | + ('x', GraphQLArgument(GraphQLString)), |
| 310 | + ('v', GraphQLArgument(GraphQLString)), |
| 311 | + ('a', GraphQLArgument(GraphQLString)), |
| 312 | + ('n', GraphQLArgument(GraphQLString)) |
| 313 | + ]))) |
| 314 | + ]) |
| 315 | + |
| 316 | + test_object = GraphQLObjectType(name='Test', fields=fields) |
| 317 | + ordered_fields = test_object.get_fields() |
| 318 | + assert list(ordered_fields.keys()) == ['b', 'c', 'a', 'd'] |
| 319 | + field_with_args = test_object.get_fields().get('d') |
| 320 | + assert [a.name for a in field_with_args.args] == ['q', 'x', 'v', 'a', 'n'] |
0 commit comments