Skip to content

Commit dd8c275

Browse files
committed
Improved fields and args to use OrderedDict instead of dict
1 parent 38965cc commit dd8c275

File tree

4 files changed

+60
-50
lines changed

4 files changed

+60
-50
lines changed
Lines changed: 32 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
from collections import OrderedDict
2+
13
from graphql.type import (
24
GraphQLArgument,
35
GraphQLBoolean,
@@ -11,47 +13,47 @@
1113
from ..utils import resolve_maybe_thunk
1214

1315

14-
connection_args = {
15-
'before': GraphQLArgument(GraphQLString),
16-
'after': GraphQLArgument(GraphQLString),
17-
'first': GraphQLArgument(GraphQLInt),
18-
'last': GraphQLArgument(GraphQLInt),
19-
}
16+
connection_args = OrderedDict((
17+
('before', GraphQLArgument(GraphQLString)),
18+
('after', GraphQLArgument(GraphQLString)),
19+
('first', GraphQLArgument(GraphQLInt)),
20+
('last', GraphQLArgument(GraphQLInt)),
21+
))
2022

2123

2224
def connection_definitions(name, node_type, resolve_node=None, resolve_cursor=None, edge_fields=None, connection_fields=None):
23-
edge_fields = edge_fields or {}
24-
connection_fields = connection_fields or {}
25+
edge_fields = edge_fields or OrderedDict()
26+
connection_fields = connection_fields or OrderedDict()
2527
edge_type = GraphQLObjectType(
2628
name + 'Edge',
2729
description='An edge in a connection.',
28-
fields=lambda: dict({
29-
'node': GraphQLField(
30+
fields=lambda: OrderedDict((
31+
('node', GraphQLField(
3032
node_type,
3133
resolver=resolve_node,
3234
description='The item at the end of the edge',
33-
),
34-
'cursor': GraphQLField(
35+
)),
36+
('cursor', GraphQLField(
3537
GraphQLNonNull(GraphQLString),
3638
resolver=resolve_cursor,
3739
description='A cursor for use in pagination',
38-
)
39-
}, **resolve_maybe_thunk(edge_fields))
40+
)),
41+
), **resolve_maybe_thunk(edge_fields))
4042
)
4143

4244
connection_type = GraphQLObjectType(
4345
name + 'Connection',
4446
description='A connection to a list of items.',
45-
fields=lambda: dict({
46-
'pageInfo': GraphQLField(
47+
fields=lambda: OrderedDict((
48+
('pageInfo', GraphQLField(
4749
GraphQLNonNull(page_info_type),
4850
description='The Information to aid in pagination',
49-
),
50-
'edges': GraphQLField(
51+
)),
52+
('edges', GraphQLField(
5153
GraphQLList(edge_type),
5254
description='A list of edges.',
53-
)
54-
}, **resolve_maybe_thunk(connection_fields))
55+
)),
56+
), **resolve_maybe_thunk(connection_fields))
5557
)
5658

5759
return edge_type, connection_type
@@ -61,22 +63,22 @@ def connection_definitions(name, node_type, resolve_node=None, resolve_cursor=No
6163
page_info_type = GraphQLObjectType(
6264
'PageInfo',
6365
description='Information about pagination in a connection.',
64-
fields=lambda: {
65-
'hasNextPage': GraphQLField(
66+
fields=lambda: OrderedDict((
67+
('hasNextPage', GraphQLField(
6668
GraphQLNonNull(GraphQLBoolean),
6769
description='When paginating forwards, are there more items?',
68-
),
69-
'hasPreviousPage': GraphQLField(
70+
)),
71+
('hasPreviousPage', GraphQLField(
7072
GraphQLNonNull(GraphQLBoolean),
7173
description='When paginating backwards, are there more items?',
72-
),
73-
'startCursor': GraphQLField(
74+
)),
75+
('startCursor', GraphQLField(
7476
GraphQLString,
7577
description='When paginating backwards, the cursor to continue.',
76-
),
77-
'endCursor': GraphQLField(
78+
)),
79+
('endCursor', GraphQLField(
7880
GraphQLString,
7981
description='When paginating forwards, the cursor to continue.',
80-
),
81-
}
82+
)),
83+
))
8284
)

graphql_relay/mutation/mutation.py

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import OrderedDict
12
from promise import Promise
23
from graphql.type import (
34
GraphQLArgument,
@@ -13,14 +14,19 @@
1314

1415

1516
def mutation_with_client_mutation_id(name, input_fields, output_fields, mutate_and_get_payload):
16-
augmented_input_fields = dict(resolve_maybe_thunk(input_fields),
17-
clientMutationId=GraphQLInputObjectField(
18-
GraphQLNonNull(GraphQLString))
19-
)
20-
augmented_output_fields = dict(resolve_maybe_thunk(output_fields),
21-
clientMutationId=GraphQLField(
22-
GraphQLNonNull(GraphQLString))
23-
)
17+
augmented_input_fields = OrderedDict(
18+
resolve_maybe_thunk(input_fields),
19+
clientMutationId=GraphQLInputObjectField(
20+
GraphQLNonNull(GraphQLString)
21+
)
22+
)
23+
augmented_output_fields = OrderedDict(
24+
resolve_maybe_thunk(output_fields),
25+
clientMutationId=GraphQLField(
26+
GraphQLNonNull(GraphQLString)
27+
)
28+
)
29+
2430
input_type = GraphQLInputObjectType(
2531
name + 'Input',
2632
fields=augmented_input_fields,
@@ -44,8 +50,8 @@ def on_resolve(payload):
4450

4551
return GraphQLField(
4652
output_type,
47-
args={
48-
'input': GraphQLArgument(GraphQLNonNull(input_type)),
49-
},
53+
args=OrderedDict((
54+
('input', GraphQLArgument(GraphQLNonNull(input_type))),
55+
)),
5056
resolver=resolver
5157
)

graphql_relay/node/node.py

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from collections import OrderedDict
12
from graphql_relay.utils import base64, unbase64
23

34
from graphql.type import (
@@ -23,24 +24,24 @@ def node_definitions(id_fetcher, type_resolver=None, id_resolver=None):
2324
node_interface = GraphQLInterfaceType(
2425
'Node',
2526
description='An object with an ID',
26-
fields=lambda: {
27-
'id': GraphQLField(
27+
fields=lambda: OrderedDict((
28+
('id', GraphQLField(
2829
GraphQLNonNull(GraphQLID),
2930
description='The id of the object.',
3031
resolver=id_resolver,
31-
),
32-
},
32+
)),
33+
)),
3334
resolve_type=type_resolver
3435
)
3536
node_field = GraphQLField(
3637
node_interface,
3738
description='Fetches an object given its ID',
38-
args={
39-
'id': GraphQLArgument(
39+
args=OrderedDict((
40+
('id', GraphQLArgument(
4041
GraphQLNonNull(GraphQLID),
4142
description='The ID of an object'
42-
)
43-
},
43+
)),
44+
)),
4445
resolver=lambda obj, args, *_: id_fetcher(args.get('id'), *_)
4546
)
4647
return node_interface, node_field

graphql_relay/node/plural.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 promise import Promise
23
from graphql.type import (
34
GraphQLArgument,
@@ -8,7 +9,7 @@
89

910

1011
def plural_identifying_root_field(arg_name, input_type, output_type, resolve_single_input, description=None):
11-
input_args = {}
12+
input_args = OrderedDict()
1213
input_args[arg_name] = GraphQLArgument(
1314
GraphQLNonNull(
1415
GraphQLList(

0 commit comments

Comments
 (0)