mirror of
https://github.com/graphql-python/graphene.git
synced 2024-11-25 19:13:57 +03:00
Merge branch '2.0' into 2.0-newresolvers
This commit is contained in:
commit
3a83671669
|
@ -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
|
||||
developer have to write to use them.
|
||||
|
||||
Deprecations:
|
||||
**Deprecations:**
|
||||
* [`AbstractType`](#abstracttype-deprecated)
|
||||
* [`resolve_only_args`](#resolve_only_args)
|
||||
* [`Mutation.Input`](#mutationinput)
|
||||
|
||||
Breaking changes:
|
||||
**Breaking changes:**
|
||||
* [`Simpler Resolvers`](#simpler-resolvers)
|
||||
* [`Node Connections`](#node-connections)
|
||||
|
||||
New Features!
|
||||
**New Features!**
|
||||
* [`InputObjectType`](#inputobjecttype)
|
||||
* [`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 ...
|
||||
```
|
||||
|
||||
And, if the resolver want to get the context:
|
||||
And, if you need the context in the resolver, you can use `info.context`:
|
||||
|
||||
```python
|
||||
my_field = graphene.String(my_arg=graphene.String())
|
||||
|
@ -132,6 +133,50 @@ class User(Mutation):
|
|||
|
||||
## 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 types no longer have a `Connection` by default.
|
||||
|
|
Loading…
Reference in New Issue
Block a user