@@ -51,27 +51,27 @@ returning those types.
51
51
52
52
- ` connectionArgs ` returns the arguments that fields should provide when
53
53
they return a connection type.
54
- - ` connectionDefinitions ` returns a ` connectionType ` and its associated
54
+ - ` connection_definitions ` returns a ` connection_type ` and its associated
55
55
` edgeType ` , given a name and a node type.
56
- - ` connectionFromArray ` is a helper method that takes an array and the
56
+ - ` connection_from_list ` is a helper method that takes an array and the
57
57
arguments from ` connectionArgs ` , does pagination and filtering, and returns
58
- an object in the shape expected by a ` connectionType ` 's ` resolver ` function.
59
- - ` connectionFromPromisedArray ` is similar to ` connectionFromArray ` , but
58
+ an object in the shape expected by a ` connection_type ` 's ` resolver ` function.
59
+ - ` connection_from_promised_list ` is similar to ` connection_from_list ` , but
60
60
it takes a promise that resolves to an array, and returns a promise that
61
- resolves to the expected shape by ` connectionType ` .
62
- - ` cursorForObjectInConnection ` is a helper method that takes an array and a
61
+ resolves to the expected shape by ` connection_type ` .
62
+ - ` cursor_for_object_in_connection ` is a helper method that takes an array and a
63
63
member object, and returns a cursor for use in the mutation payload.
64
64
65
65
An example usage of these methods from the [ test schema] ( tests/starwars/schema.py ) :
66
66
67
67
``` python
68
- shipConnection = connectionDefinitions (' Ship' , shipType).connectionType
68
+ shipConnection = connection_definitions (' Ship' , shipType).connection_type
69
69
70
70
factionType = GraphQLObjectType(
71
71
name = ' Faction' ,
72
72
description = ' A faction in the Star Wars saga' ,
73
73
fields = lambda : {
74
- ' id' : globalIdField (' Faction' ),
74
+ ' id' : global_id_field (' Faction' ),
75
75
' name' : GraphQLField(
76
76
GraphQLString,
77
77
description = ' The name of the faction.' ,
@@ -80,45 +80,45 @@ factionType = GraphQLObjectType(
80
80
shipConnection,
81
81
description = ' The ships used by the faction.' ,
82
82
args = connectionArgs,
83
- resolver = lambda faction , args , * _ : connectionFromArray (
83
+ resolver = lambda faction , args , * _ : connection_from_list (
84
84
map (getShip, faction.ships),
85
85
args
86
86
),
87
87
)
88
88
},
89
- interfaces = [nodeInterface ]
89
+ interfaces = [node_interface ]
90
90
)
91
91
```
92
92
93
93
This shows adding a ` ships ` field to the ` Faction ` object that is a connection.
94
- It uses ` connectionDefinitions ({name: 'Ship', nodeType: shipType})` to create
94
+ It uses ` connection_definitions ({name: 'Ship', nodeType: shipType})` to create
95
95
the connection type, adds ` connectionArgs ` as arguments on this function, and
96
96
then implements the resolver function by passing the array of ships and the
97
- arguments to ` connectionFromArray ` .
97
+ arguments to ` connection_from_list ` .
98
98
99
99
### Object Identification
100
100
101
101
Helper functions are provided for both building the GraphQL types
102
102
for nodes and for implementing global IDs around local IDs.
103
103
104
- - ` nodeDefinitions ` returns the ` Node ` interface that objects can implement,
104
+ - ` node_definitions ` returns the ` Node ` interface that objects can implement,
105
105
and returns the ` node ` root field to include on the query type. To implement
106
106
this, it takes a function to resolve an ID to an object, and to determine
107
107
the type of a given object.
108
- - ` toGlobalId ` takes a type name and an ID specific to that type name,
108
+ - ` to_global_id ` takes a type name and an ID specific to that type name,
109
109
and returns a "global ID" that is unique among all types.
110
- - ` fromGlobalId ` takes the "global ID" created by ` toGlobalID ` , and retuns
110
+ - ` from_global_id ` takes the "global ID" created by ` toGlobalID ` , and retuns
111
111
the type name and ID used to create it.
112
- - ` globalIdField ` creates the configuration for an ` id ` field on a node.
113
- - ` pluralIdentifyingRootField ` creates a field that accepts a list of
112
+ - ` global_id_field ` creates the configuration for an ` id ` field on a node.
113
+ - ` plural_identifying_root_field ` creates a field that accepts a list of
114
114
non-ID identifiers (like a username) and maps then to their corresponding
115
115
objects.
116
116
117
117
An example usage of these methods from the [ test schema] ( tests/starwars/schema.py ) :
118
118
119
119
``` python
120
- def getNode ( globalId , * args ):
121
- resolvedGlobalId = fromGlobalId(globalId )
120
+ def get_node ( global_id , * args ):
121
+ resolvedGlobalId = from_global_id(global_id )
122
122
_type, _id = resolvedGlobalId.type, resolvedGlobalId.id
123
123
if _type == ' Faction' :
124
124
return getFaction(_id)
@@ -127,45 +127,45 @@ def getNode(globalId, *args):
127
127
else :
128
128
return None
129
129
130
- def getNodeType (obj ):
130
+ def get_node_type (obj ):
131
131
if isinstance (obj, Faction):
132
132
return factionType
133
133
else :
134
134
return shipType
135
135
136
- _nodeDefinitions = nodeDefinitions(getNode, getNodeType )
137
- nodeField, nodeInterface = _nodeDefinitions.nodeField, _nodeDefinitions.nodeInterface
136
+ _node_definitions = node_definitions(get_node, get_node_type )
137
+ node_field, node_interface = _node_definitions.node_field, _node_definitions.node_interface
138
138
139
139
factionType = GraphQLObjectType(
140
140
name = ' Faction' ,
141
141
description = ' A faction in the Star Wars saga' ,
142
142
fields = lambda : {
143
- ' id' : globalIdField (' Faction' ),
143
+ ' id' : global_id_field (' Faction' ),
144
144
},
145
- interfaces = [nodeInterface ]
145
+ interfaces = [node_interface ]
146
146
)
147
147
148
148
queryType = GraphQLObjectType(
149
149
name = ' Query' ,
150
150
fields = lambda : {
151
- ' node' : nodeField
151
+ ' node' : node_field
152
152
}
153
153
)
154
154
```
155
155
156
- This uses ` nodeDefinitions ` to construct the ` Node ` interface and the ` node `
157
- field; it uses ` fromGlobalId ` to resolve the IDs passed in in the implementation
158
- of the function mapping ID to object. It then uses the ` globalIdField ` method to
156
+ This uses ` node_definitions ` to construct the ` Node ` interface and the ` node `
157
+ field; it uses ` from_global_id ` to resolve the IDs passed in in the implementation
158
+ of the function mapping ID to object. It then uses the ` global_id_field ` method to
159
159
create the ` id ` field on ` Faction ` , which also ensures implements the
160
- ` nodeInterface ` . Finally, it adds the ` node ` field to the query type, using the
161
- ` nodeField ` returned by ` nodeDefinitions ` .
160
+ ` node_interface ` . Finally, it adds the ` node ` field to the query type, using the
161
+ ` node_field ` returned by ` node_definitions ` .
162
162
163
163
### Mutations
164
164
165
165
A helper function is provided for building mutations with
166
166
single inputs and client mutation IDs.
167
167
168
- - ` mutationWithClientMutationId ` takes a name, input fields, output fields,
168
+ - ` mutation_with_client_mutation_id ` takes a name, input fields, output fields,
169
169
and a mutation method to map from the input fields to the output fields,
170
170
performing the mutation along the way. It then creates and returns a field
171
171
configuration that can be used as a top-level field on the mutation type.
@@ -179,7 +179,7 @@ class IntroduceShipMutation(object):
179
179
self .factionId = factionId
180
180
self .clientMutationId = None
181
181
182
- def mutateAndGetPayload (data , * _ ):
182
+ def mutate_and_get_payload (data , * _ ):
183
183
shipName = data.get(' shipName' )
184
184
factionId = data.get(' factionId' )
185
185
newShip = createShip(shipName, factionId)
@@ -188,17 +188,17 @@ def mutateAndGetPayload(data, *_):
188
188
factionId = factionId,
189
189
)
190
190
191
- shipMutation = mutationWithClientMutationId (
191
+ shipMutation = mutation_with_client_mutation_id (
192
192
' IntroduceShip' ,
193
- inputFields = {
193
+ input_fields = {
194
194
' shipName' : GraphQLField(
195
195
GraphQLNonNull(GraphQLString)
196
196
),
197
197
' factionId' : GraphQLField(
198
198
GraphQLNonNull(GraphQLID)
199
199
)
200
200
},
201
- outputFields = {
201
+ output_fields = {
202
202
' ship' : GraphQLField(
203
203
shipType,
204
204
resolver = lambda payload , * _ : getShip(payload.shipId)
@@ -208,7 +208,7 @@ shipMutation = mutationWithClientMutationId(
208
208
resolver = lambda payload , * _ : getFaction(payload.factionId)
209
209
)
210
210
},
211
- mutateAndGetPayload = mutateAndGetPayload
211
+ mutate_and_get_payload = mutate_and_get_payload
212
212
)
213
213
214
214
mutationType = GraphQLObjectType(
@@ -221,12 +221,12 @@ mutationType = GraphQLObjectType(
221
221
222
222
This code creates a mutation named ` IntroduceShip ` , which takes a faction
223
223
ID and a ship name as input. It outputs the ` Faction ` and the ` Ship ` in
224
- question. ` mutateAndGetPayload ` then gets an object with a property for
224
+ question. ` mutate_and_get_payload ` then gets an object with a property for
225
225
each input field, performs the mutation by constructing the new ship, then
226
226
returns an object that will be resolved by the output fields.
227
227
228
228
Our mutation type then creates the ` introduceShip ` field using the return
229
- value of ` mutationWithClientMutationId ` .
229
+ value of ` mutation_with_client_mutation_id ` .
230
230
231
231
## Contributing
232
232
0 commit comments