From 6ae9e51320fdea7ea7b13b38e192e56dbd92cc2e Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Thu, 27 Jul 2017 00:10:22 -0700 Subject: [PATCH] Update UPGRADE-v2.0.md --- UPGRADE-v2.0.md | 47 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 46 insertions(+), 1 deletion(-) diff --git a/UPGRADE-v2.0.md b/UPGRADE-v2.0.md index 15e0b486..c3238254 100644 --- a/UPGRADE-v2.0.md +++ b/UPGRADE-v2.0.md @@ -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.