mirror of
https://github.com/graphql-python/graphene.git
synced 2025-02-09 08:00:39 +03:00
Update UPGRADE-v2.0.md
This commit is contained in:
parent
586ea56693
commit
d85a4e4874
|
@ -6,15 +6,16 @@ have been quite simplified, without the need to define a explicit Metaclass for
|
||||||
It also improves the field resolvers, [simplifying the code](#simpler-resolvers) the
|
It also improves the field resolvers, [simplifying the code](#simpler-resolvers) the
|
||||||
developer have to write to use them.
|
developer have to write to use them.
|
||||||
|
|
||||||
Deprecations:
|
**Deprecations:**
|
||||||
* [`AbstractType`](#abstracttype-deprecated)
|
* [`AbstractType`](#abstracttype-deprecated)
|
||||||
* [`resolve_only_args`](#resolve_only_args)
|
* [`resolve_only_args`](#resolve_only_args)
|
||||||
* [`Mutation.Input`](#mutationinput)
|
* [`Mutation.Input`](#mutationinput)
|
||||||
|
|
||||||
Breaking changes:
|
**Breaking changes:**
|
||||||
|
* [`Simpler Resolvers`](#simpler-resolvers)
|
||||||
* [`Node Connections`](#node-connections)
|
* [`Node Connections`](#node-connections)
|
||||||
|
|
||||||
New Features!
|
**New Features!**
|
||||||
* [`InputObjectType`](#inputobjecttype)
|
* [`InputObjectType`](#inputobjecttype)
|
||||||
* [`Meta as Class arguments`](#meta-ass-class-arguments) (_only available for Python 3_)
|
* [`Meta as Class arguments`](#meta-ass-class-arguments) (_only available for Python 3_)
|
||||||
|
|
||||||
|
@ -24,51 +25,6 @@ New Features!
|
||||||
|
|
||||||
## Deprecations
|
## 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, my_arg):
|
|
||||||
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 deprecated
|
||||||
|
|
||||||
AbstractType is deprecated in graphene 2.0, you can now use normal inheritance instead.
|
AbstractType is deprecated in graphene 2.0, you can now use normal inheritance instead.
|
||||||
|
@ -141,6 +97,50 @@ class User(Mutation):
|
||||||
|
|
||||||
## Breaking Changes
|
## Breaking Changes
|
||||||
|
|
||||||
|
### 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, my_arg):
|
||||||
|
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 ...
|
||||||
|
```
|
||||||
|
|
||||||
### Node Connections
|
### Node Connections
|
||||||
|
|
||||||
Node types no longer have a `Connection` by default.
|
Node types no longer have a `Connection` by default.
|
||||||
|
|
Loading…
Reference in New Issue
Block a user