mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-26 03:23:55 +03:00
Update UPGRADE-v2.0.md
This commit is contained in:
parent
66390554d9
commit
6ae9e51320
|
@ -3,7 +3,7 @@
|
|||
`ObjectType`, `Interface`, `InputObjectType`, `Scalar` and `Enum` implementations
|
||||
have been quite simplified, without the need to define a explicit Metaclass for each subtype.
|
||||
|
||||
It also improves the field resolvers, [simplifying the code](#resolve_only_args) the
|
||||
It also improves the field resolvers, [simplifying the code](#simpler-resolvers) the
|
||||
developer have to write to use them.
|
||||
|
||||
Deprecations:
|
||||
|
@ -24,6 +24,51 @@ New Features!
|
|||
|
||||
## Deprecations
|
||||
|
||||
### Simpler resolvers
|
||||
|
||||
All the resolvers in graphene have been simplified. If before resolvers must had received
|
||||
four arguments `root`, `args`, `context` and `info`, now the `args` are passed as keyword arguments
|
||||
and `context` and `info` will only be passed if the function is annotated with it.
|
||||
|
||||
Before:
|
||||
|
||||
```python
|
||||
my_field = graphene.String(my_arg=graphene.String())
|
||||
|
||||
def resolve_my_field(self, args, context, info):
|
||||
my_arg = args.get('my_arg')
|
||||
return ...
|
||||
```
|
||||
|
||||
With 2.0:
|
||||
|
||||
```python
|
||||
my_field = graphene.String(my_arg=graphene.String())
|
||||
|
||||
def resolve_my_field(self, arg1, arg2):
|
||||
return ...
|
||||
```
|
||||
|
||||
And, if the resolver want to receive the context:
|
||||
|
||||
```python
|
||||
my_field = graphene.String(my_arg=graphene.String())
|
||||
|
||||
def resolve_my_field(self, context: graphene.Context, my_arg):
|
||||
return ...
|
||||
```
|
||||
|
||||
which is equivalent in Python 2 to:
|
||||
|
||||
```python
|
||||
my_field = graphene.String(my_arg=graphene.String())
|
||||
|
||||
@annotate(context=graphene.Context)
|
||||
def resolve_my_field(self, context, my_arg):
|
||||
return ...
|
||||
```
|
||||
|
||||
|
||||
### AbstractType deprecated
|
||||
|
||||
AbstractType is deprecated in graphene 2.0, you can now use normal inheritance instead.
|
||||
|
|
Loading…
Reference in New Issue
Block a user