@@ -51,27 +51,27 @@ returning those types.
5151
5252 - ` connectionArgs ` returns the arguments that fields should provide when
5353they return a connection type.
54- - ` connectionDefinitions ` returns a ` connectionType ` and its associated
54+ - ` connection_definitions ` returns a ` connection_type ` and its associated
5555` 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
5757arguments 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
6060it 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
6363member object, and returns a cursor for use in the mutation payload.
6464
6565An example usage of these methods from the [ test schema] ( tests/starwars/schema.py ) :
6666
6767``` python
68- shipConnection = connectionDefinitions (' Ship' , shipType).connectionType
68+ shipConnection = connection_definitions (' Ship' , shipType).connection_type
6969
7070factionType = GraphQLObjectType(
7171 name = ' Faction' ,
7272 description = ' A faction in the Star Wars saga' ,
7373 fields = lambda : {
74- ' id' : globalIdField (' Faction' ),
74+ ' id' : global_id_field (' Faction' ),
7575 ' name' : GraphQLField(
7676 GraphQLString,
7777 description = ' The name of the faction.' ,
@@ -80,45 +80,45 @@ factionType = GraphQLObjectType(
8080 shipConnection,
8181 description = ' The ships used by the faction.' ,
8282 args = connectionArgs,
83- resolver = lambda faction , args , * _ : connectionFromArray (
83+ resolver = lambda faction , args , * _ : connection_from_list (
8484 map (getShip, faction.ships),
8585 args
8686 ),
8787 )
8888 },
89- interfaces = [nodeInterface ]
89+ interfaces = [node_interface ]
9090)
9191```
9292
9393This 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
9595the connection type, adds ` connectionArgs ` as arguments on this function, and
9696then implements the resolver function by passing the array of ships and the
97- arguments to ` connectionFromArray ` .
97+ arguments to ` connection_from_list ` .
9898
9999### Object Identification
100100
101101Helper functions are provided for both building the GraphQL types
102102for nodes and for implementing global IDs around local IDs.
103103
104- - ` nodeDefinitions ` returns the ` Node ` interface that objects can implement,
104+ - ` node_definitions ` returns the ` Node ` interface that objects can implement,
105105and returns the ` node ` root field to include on the query type. To implement
106106this, it takes a function to resolve an ID to an object, and to determine
107107the 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,
109109and 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
111111the 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
114114non-ID identifiers (like a username) and maps then to their corresponding
115115objects.
116116
117117An example usage of these methods from the [ test schema] ( tests/starwars/schema.py ) :
118118
119119``` python
120- def getNode ( globalId , * args ):
121- resolvedGlobalId = fromGlobalId(globalId )
120+ def get_node ( global_id , * args ):
121+ resolvedGlobalId = from_global_id(global_id )
122122 _type, _id = resolvedGlobalId.type, resolvedGlobalId.id
123123 if _type == ' Faction' :
124124 return getFaction(_id)
@@ -127,45 +127,45 @@ def getNode(globalId, *args):
127127 else :
128128 return None
129129
130- def getNodeType (obj ):
130+ def get_node_type (obj ):
131131 if isinstance (obj, Faction):
132132 return factionType
133133 else :
134134 return shipType
135135
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
138138
139139factionType = GraphQLObjectType(
140140 name = ' Faction' ,
141141 description = ' A faction in the Star Wars saga' ,
142142 fields = lambda : {
143- ' id' : globalIdField (' Faction' ),
143+ ' id' : global_id_field (' Faction' ),
144144 },
145- interfaces = [nodeInterface ]
145+ interfaces = [node_interface ]
146146)
147147
148148queryType = GraphQLObjectType(
149149 name = ' Query' ,
150150 fields = lambda : {
151- ' node' : nodeField
151+ ' node' : node_field
152152 }
153153)
154154```
155155
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
159159create 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 ` .
162162
163163### Mutations
164164
165165A helper function is provided for building mutations with
166166single inputs and client mutation IDs.
167167
168- - ` mutationWithClientMutationId ` takes a name, input fields, output fields,
168+ - ` mutation_with_client_mutation_id ` takes a name, input fields, output fields,
169169and a mutation method to map from the input fields to the output fields,
170170performing the mutation along the way. It then creates and returns a field
171171configuration that can be used as a top-level field on the mutation type.
@@ -179,7 +179,7 @@ class IntroduceShipMutation(object):
179179 self .factionId = factionId
180180 self .clientMutationId = None
181181
182- def mutateAndGetPayload (data , * _ ):
182+ def mutate_and_get_payload (data , * _ ):
183183 shipName = data.get(' shipName' )
184184 factionId = data.get(' factionId' )
185185 newShip = createShip(shipName, factionId)
@@ -188,17 +188,17 @@ def mutateAndGetPayload(data, *_):
188188 factionId = factionId,
189189 )
190190
191- shipMutation = mutationWithClientMutationId (
191+ shipMutation = mutation_with_client_mutation_id (
192192 ' IntroduceShip' ,
193- inputFields = {
193+ input_fields = {
194194 ' shipName' : GraphQLField(
195195 GraphQLNonNull(GraphQLString)
196196 ),
197197 ' factionId' : GraphQLField(
198198 GraphQLNonNull(GraphQLID)
199199 )
200200 },
201- outputFields = {
201+ output_fields = {
202202 ' ship' : GraphQLField(
203203 shipType,
204204 resolver = lambda payload , * _ : getShip(payload.shipId)
@@ -208,7 +208,7 @@ shipMutation = mutationWithClientMutationId(
208208 resolver = lambda payload , * _ : getFaction(payload.factionId)
209209 )
210210 },
211- mutateAndGetPayload = mutateAndGetPayload
211+ mutate_and_get_payload = mutate_and_get_payload
212212)
213213
214214mutationType = GraphQLObjectType(
@@ -221,12 +221,12 @@ mutationType = GraphQLObjectType(
221221
222222This code creates a mutation named ` IntroduceShip ` , which takes a faction
223223ID 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
225225each input field, performs the mutation by constructing the new ship, then
226226returns an object that will be resolved by the output fields.
227227
228228Our mutation type then creates the ` introduceShip ` field using the return
229- value of ` mutationWithClientMutationId ` .
229+ value of ` mutation_with_client_mutation_id ` .
230230
231231## Contributing
232232
0 commit comments