Skip to content

Commit 28f6353

Browse files
authored
Merge pull request #732 from femesq/patch-1
Migrations docs improvement
2 parents 4720f77 + ead24a9 commit 28f6353

File tree

1 file changed

+72
-1
lines changed

1 file changed

+72
-1
lines changed

UPGRADE-v2.0.md

+72-1
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,13 @@ def resolve_my_field(self, info, my_arg):
122122
return ...
123123
```
124124

125+
**PS.: Take care with receiving args like `my_arg` as above. This doesn't work for optional (non-required) arguments as stantard `Connection`'s arguments (first, before, after, before).**
126+
You may need something like this:
127+
128+
```python
129+
def resolve_my_field(self, info, known_field1, known_field2, **args): ## get other args with: args.get('arg_key')
130+
```
131+
125132
And, if you need the context in the resolver, you can use `info.context`:
126133

127134
```python
@@ -193,14 +200,78 @@ class MyObject(ObjectType):
193200

194201
## Mutation.mutate
195202

196-
Now only receives (`root`, `info`, `**args`)
203+
Now only receives (`self`, `info`, `**args`) and is not a @classmethod
204+
205+
Before:
206+
207+
```python
208+
class SomeMutation(Mutation):
209+
...
210+
211+
@classmethod
212+
def mutate(cls, instance, args, context, info):
213+
...
214+
```
215+
216+
With 2.0:
217+
218+
```python
219+
class SomeMutation(Mutation):
220+
...
221+
222+
def mutate(self, info, **args):
223+
...
224+
```
225+
226+
With 2.0 you can also get your declared (as above) `args` this way:
227+
228+
```python
229+
class SomeMutation(Mutation):
230+
class Arguments:
231+
first_name = String(required=True)
232+
last_name = String(required=True)
233+
...
234+
235+
def mutate(self, info, first_name, last_name):
236+
...
237+
```
238+
197239

198240

199241
## ClientIDMutation.mutate_and_get_payload
200242

201243
Now only receives (`root`, `info`, `**input`)
202244

203245

246+
### Middlewares
247+
248+
If you are using Middelwares, you need to some adjustments:
249+
250+
Before:
251+
252+
```python
253+
class MyGrapheneMiddleware(object):
254+
def resolve(self, next_mw, root, args, context, info):
255+
256+
## Middleware code
257+
258+
return next_mw(root, args, context, info)
259+
```
260+
261+
With 2.0:
262+
263+
```python
264+
class MyGrapheneMiddleware(object):
265+
def resolve(self, next_mw, root, info, **args):
266+
context = info.context
267+
268+
## Middleware code
269+
270+
info.context = context
271+
       return next_mw(root, info, **args)```
272+
```
273+
274+
204275
## New Features
205276

206277
### InputObjectType

0 commit comments

Comments
 (0)