@@ -31,12 +31,12 @@ describes a simple set of examples that exist as [tests](tests) in this
31
31
repository. A good way to get started with this repository is to walk through
32
32
that documentation and the corresponding tests in this library together.
33
33
34
- ## Using Relay Library for GraphQL Python (graphql-core)
34
+ ## Using Relay Library for GraphQL Python (graphql-core-next )
35
35
36
36
Install Relay Library for GraphQL Python
37
37
38
38
``` sh
39
- pip install graphql-core --pre # Last version of graphql-core
39
+ pip install graphql-core-next
40
40
pip install graphql-relay
41
41
```
42
42
@@ -69,25 +69,23 @@ An example usage of these methods from the [test schema](tests/starwars/schema.p
69
69
ship_edge, ship_connection = connection_definitions(' Ship' , shipType)
70
70
71
71
factionType = GraphQLObjectType(
72
- name = ' Faction' ,
73
- description = ' A faction in the Star Wars saga' ,
74
- fields = lambda : {
72
+ name = ' Faction' ,
73
+ description = ' A faction in the Star Wars saga' ,
74
+ fields = lambda : {
75
75
' id' : global_id_field(' Faction' ),
76
76
' name' : GraphQLField(
77
77
GraphQLString,
78
78
description = ' The name of the faction.' ,
79
79
),
80
80
' ships' : GraphQLField(
81
- shipConnection,
82
- description = ' The ships used by the faction.' ,
83
- args = connection_args,
84
- resolver = lambda faction , args , * _ : connection_from_list(
85
- map (getShip, faction.ships),
86
- args
87
- ),
81
+ ship_connection,
82
+ description = ' The ships used by the faction.' ,
83
+ args = connection_args,
84
+ resolve = lambda faction , _info , ** args : connection_from_list(
85
+ [getShip(ship) for ship in faction.ships], args),
88
86
)
89
87
},
90
- interfaces = [node_interface]
88
+ interfaces = [node_interface]
91
89
)
92
90
```
93
91
@@ -108,7 +106,7 @@ this, it takes a function to resolve an ID to an object, and to determine
108
106
the type of a given object.
109
107
- ` to_global_id ` takes a type name and an ID specific to that type name,
110
108
and returns a "global ID" that is unique among all types.
111
- - ` from_global_id ` takes the "global ID" created by ` toGlobalID ` , and retuns
109
+ - ` from_global_id ` takes the "global ID" created by ` toGlobalID ` , and returns
112
110
the type name and ID used to create it.
113
111
- ` global_id_field ` creates the configuration for an ` id ` field on a node.
114
112
- ` plural_identifying_root_field ` creates a field that accepts a list of
@@ -118,17 +116,16 @@ objects.
118
116
An example usage of these methods from the [ test schema] ( tests/starwars/schema.py ) :
119
117
120
118
``` python
121
- def get_node (global_id , context , info ):
122
- resolvedGlobalId = from_global_id(global_id)
123
- _type, _id = resolvedGlobalId.type, resolvedGlobalId.id
124
- if _type == ' Faction' :
125
- return getFaction(_id)
126
- elif _type == ' Ship' :
127
- return getShip(_id)
119
+ def get_node (global_id , _info ):
120
+ type_, id_ = from_global_id(global_id)
121
+ if type_ == ' Faction' :
122
+ return getFaction(id_)
123
+ elif type_ == ' Ship' :
124
+ return getShip(id_)
128
125
else :
129
126
return None
130
127
131
- def get_node_type (obj , context , info ):
128
+ def get_node_type (obj , _info , _type ):
132
129
if isinstance (obj, Faction):
133
130
return factionType
134
131
else :
@@ -173,47 +170,42 @@ configuration that can be used as a top-level field on the mutation type.
173
170
An example usage of these methods from the [ test schema] ( tests/starwars/schema.py ) :
174
171
175
172
``` python
176
- class IntroduceShipMutation ( object ) :
173
+ class IntroduceShipMutation :
177
174
def __init__ (self , shipId , factionId , clientMutationId = None ):
178
175
self .shipId = shipId
179
176
self .factionId = factionId
180
- self .clientMutationId = None
177
+ self .clientMutationId = clientMutationId
181
178
182
- def mutate_and_get_payload (data , * _ ):
183
- shipName = data.get(' shipName' )
184
- factionId = data.get(' factionId' )
179
+ def mutate_and_get_payload (_info , shipName , factionId , ** _input ):
185
180
newShip = createShip(shipName, factionId)
186
- return IntroduceShipMutation(
187
- shipId = newShip.id,
188
- factionId = factionId,
189
- )
181
+ return IntroduceShipMutation(shipId = newShip.id, factionId = factionId)
190
182
191
183
shipMutation = mutation_with_client_mutation_id(
192
184
' IntroduceShip' ,
193
185
input_fields = {
194
- ' shipName' : GraphQLField (
186
+ ' shipName' : GraphQLInputField (
195
187
GraphQLNonNull(GraphQLString)
196
188
),
197
- ' factionId' : GraphQLField (
189
+ ' factionId' : GraphQLInputField (
198
190
GraphQLNonNull(GraphQLID)
199
191
)
200
192
},
201
- output_fields = {
193
+ output_fields = {
202
194
' ship' : GraphQLField(
203
195
shipType,
204
- resolver = lambda payload , * _ : getShip(payload.shipId)
196
+ resolve = lambda payload , _info : getShip(payload.shipId)
205
197
),
206
198
' faction' : GraphQLField(
207
199
factionType,
208
- resolver = lambda payload , * _ : getFaction(payload.factionId)
200
+ resolve = lambda payload , _info : getFaction(payload.factionId)
209
201
)
210
202
},
211
203
mutate_and_get_payload = mutate_and_get_payload
212
204
)
213
205
214
206
mutationType = GraphQLObjectType(
215
207
' Mutation' ,
216
- fields = lambda : {
208
+ fields = lambda : {
217
209
' introduceShip' : shipMutation
218
210
}
219
211
)
0 commit comments