Update UPGRADE-v2.0.md

Migration docs improvement
This commit is contained in:
Felipe Mesquita 2018-05-23 20:13:03 -03:00 committed by GitHub
parent 12d4dab774
commit 5d084cf2ea
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -122,6 +122,13 @@ def resolve_my_field(self, info, my_arg):
return ...
```
**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).**
You may need something like this:
```python
def resolve_my_field(self, info, known_field1, known_field2, **args): ## get other args with: args.get('arg_key')
```
And, if you need the context in the resolver, you can use `info.context`:
```python
@ -193,7 +200,42 @@ class MyObject(ObjectType):
## Mutation.mutate
Now only receives (`root`, `info`, `**args`)
Now only receives (`self`, `info`, `**args`) and if not a @classmethod
Before:
```python
class SomeMutation(Mutation):
...
@classmethod
def mutate(cls, instance, args, context, info):
...
```
With 2.0:
```python
class SomeMutation(Mutation):
...
def mutate(self, info, **args):
...
```
With 2.0 you can also get your declared (as above) `args` this way:
```python
class SomeMutation(Mutation):
class Arguments:
first_name = String(required=True)
last_name = String(required=True)
...
def mutate(self, info, first_name, last_name):
...
```
## ClientIDMutation.mutate_and_get_payload
@ -201,6 +243,35 @@ Now only receives (`root`, `info`, `**args`)
Now only receives (`root`, `info`, `**input`)
### Middlewares
If you are using Middelwares, you need to some adjustments:
Before:
```python
class MyGrapheneMiddleware(object):
def resolve(self, next_mw, root, args, context, info):
## Middleware code
return next_mw(root, args, context, info)
```
With 2.0:
```python
class MyGrapheneMiddleware(object):
def resolve(self, next_mw, root, info, **args):
context = info.context
## Middleware code
info.context = context
       return next_mw(root, info, **args)```
```
## New Features
### InputObjectType