diff --git a/UPGRADE-v2.0.md b/UPGRADE-v2.0.md index 0f7e8209..ab8b997b 100644 --- a/UPGRADE-v2.0.md +++ b/UPGRADE-v2.0.md @@ -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_) @@ -24,51 +25,6 @@ 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, 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 is deprecated in graphene 2.0, you can now use normal inheritance instead. @@ -141,6 +97,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.