Merge branch '2.0' into 2.0-newresolvers

This commit is contained in:
Syrus Akbary 2017-07-31 22:19:11 -07:00 committed by GitHub
commit 3a83671669

View File

@ -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_)
@ -49,7 +50,7 @@ def resolve_my_field(self, info, my_arg):
return ... return ...
``` ```
And, if the resolver want to get the context: And, if you need the context in the resolver, you can use `info.context`:
```python ```python
my_field = graphene.String(my_arg=graphene.String()) my_field = graphene.String(my_arg=graphene.String())
@ -132,6 +133,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.