Skip to content

Commit 908cb40

Browse files
committed
Fixed #3
1 parent 4b7078a commit 908cb40

File tree

16 files changed

+285
-286
lines changed

16 files changed

+285
-286
lines changed

README.md

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -51,27 +51,27 @@ returning those types.
5151

5252
- `connectionArgs` returns the arguments that fields should provide when
5353
they 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
5757
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
6060
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
6363
member object, and returns a cursor for use in the mutation payload.
6464

6565
An 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

7070
factionType = 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

9393
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
9595
the connection type, adds `connectionArgs` as arguments on this function, and
9696
then 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

101101
Helper functions are provided for both building the GraphQL types
102102
for 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,
105105
and returns the `node` root field to include on the query type. To implement
106106
this, it takes a function to resolve an ID to an object, and to determine
107107
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,
109109
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
111111
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
114114
non-ID identifiers (like a username) and maps then to their corresponding
115115
objects.
116116

117117
An 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

139139
factionType = 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

148148
queryType = 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
159159
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`.
162162

163163
### Mutations
164164

165165
A helper function is provided for building mutations with
166166
single 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,
169169
and a mutation method to map from the input fields to the output fields,
170170
performing the mutation along the way. It then creates and returns a field
171171
configuration 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

214214
mutationType = GraphQLObjectType(
@@ -221,12 +221,12 @@ mutationType = GraphQLObjectType(
221221

222222
This code creates a mutation named `IntroduceShip`, which takes a faction
223223
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
225225
each input field, performs the mutation by constructing the new ship, then
226226
returns an object that will be resolved by the output fields.
227227

228228
Our 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

Comments
 (0)