1
+ from collections import OrderedDict
2
+
1
3
from graphql .type import (
2
4
GraphQLArgument ,
3
5
GraphQLBoolean ,
11
13
from ..utils import resolve_maybe_thunk
12
14
13
15
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
+ ))
20
22
21
23
22
24
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 ()
25
27
edge_type = GraphQLObjectType (
26
28
name + 'Edge' ,
27
29
description = 'An edge in a connection.' ,
28
- fields = lambda : dict ({
29
- 'node' : GraphQLField (
30
+ fields = lambda : OrderedDict ((
31
+ ( 'node' , GraphQLField (
30
32
node_type ,
31
33
resolver = resolve_node ,
32
34
description = 'The item at the end of the edge' ,
33
- ),
34
- 'cursor' : GraphQLField (
35
+ )) ,
36
+ ( 'cursor' , GraphQLField (
35
37
GraphQLNonNull (GraphQLString ),
36
38
resolver = resolve_cursor ,
37
39
description = 'A cursor for use in pagination' ,
38
- )
39
- } , ** resolve_maybe_thunk (edge_fields ))
40
+ )),
41
+ ) , ** resolve_maybe_thunk (edge_fields ))
40
42
)
41
43
42
44
connection_type = GraphQLObjectType (
43
45
name + 'Connection' ,
44
46
description = 'A connection to a list of items.' ,
45
- fields = lambda : dict ({
46
- 'pageInfo' : GraphQLField (
47
+ fields = lambda : OrderedDict ((
48
+ ( 'pageInfo' , GraphQLField (
47
49
GraphQLNonNull (page_info_type ),
48
50
description = 'The Information to aid in pagination' ,
49
- ),
50
- 'edges' : GraphQLField (
51
+ )) ,
52
+ ( 'edges' , GraphQLField (
51
53
GraphQLList (edge_type ),
52
54
description = 'A list of edges.' ,
53
- )
54
- } , ** resolve_maybe_thunk (connection_fields ))
55
+ )),
56
+ ) , ** resolve_maybe_thunk (connection_fields ))
55
57
)
56
58
57
59
return edge_type , connection_type
@@ -61,22 +63,22 @@ def connection_definitions(name, node_type, resolve_node=None, resolve_cursor=No
61
63
page_info_type = GraphQLObjectType (
62
64
'PageInfo' ,
63
65
description = 'Information about pagination in a connection.' ,
64
- fields = lambda : {
65
- 'hasNextPage' : GraphQLField (
66
+ fields = lambda : OrderedDict ((
67
+ ( 'hasNextPage' , GraphQLField (
66
68
GraphQLNonNull (GraphQLBoolean ),
67
69
description = 'When paginating forwards, are there more items?' ,
68
- ),
69
- 'hasPreviousPage' : GraphQLField (
70
+ )) ,
71
+ ( 'hasPreviousPage' , GraphQLField (
70
72
GraphQLNonNull (GraphQLBoolean ),
71
73
description = 'When paginating backwards, are there more items?' ,
72
- ),
73
- 'startCursor' : GraphQLField (
74
+ )) ,
75
+ ( 'startCursor' , GraphQLField (
74
76
GraphQLString ,
75
77
description = 'When paginating backwards, the cursor to continue.' ,
76
- ),
77
- 'endCursor' : GraphQLField (
78
+ )) ,
79
+ ( 'endCursor' , GraphQLField (
78
80
GraphQLString ,
79
81
description = 'When paginating forwards, the cursor to continue.' ,
80
- ),
81
- }
82
+ )) ,
83
+ ))
82
84
)
0 commit comments