Merge pull request #732 from femesq/patch-1

Migrations docs improvement
This commit is contained in:
Syrus Akbary 2018-05-24 19:20:33 -07:00 committed by GitHub
commit 28f6353212
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 is 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