From 6dde81ee65d1542ee6f8a41aebea6deabde36cc6 Mon Sep 17 00:00:00 2001 From: Syrus Akbary Date: Wed, 26 Jul 2017 19:44:17 -0700 Subject: [PATCH] Improved Mutation warning --- UPGRADE-v2.0.md | 40 ++++++++++++++++++++++++++++++++++++++ graphene/types/mutation.py | 7 ++++++- 2 files changed, 46 insertions(+), 1 deletion(-) diff --git a/UPGRADE-v2.0.md b/UPGRADE-v2.0.md index 1877b8b9..b4b671b7 100644 --- a/UPGRADE-v2.0.md +++ b/UPGRADE-v2.0.md @@ -9,6 +9,7 @@ developer have to write to use them. Deprecations: * [`AbstractType`](#abstracttype-deprecated) * [`resolve_only_args`](#resolve_only_args) +* [`Mutation.Input`](#mutation-input) Breaking changes: * [`Node Connections`](#node-connections) @@ -72,6 +73,26 @@ class User(ObjectType): return self.name ``` +### Mutation.Input + +`Mutation.Input` is now deprecated in favor using `Mutation.Arguments` (`ClientIDMutation` still uses `Input`). + +Before: + +```python +class User(Mutation): + class Input: + name = String() +``` + +With 2.0: + +```python +class User(Mutation): + class Arguments: + name = String() +``` + ## Breaking Changes @@ -177,6 +198,25 @@ class Dog(ObjectType, interfaces=[Pet]): name = String() ``` + +### Abstract types + +Now you can create abstact types super easily, without the need of subclassing the meta. + +```python +class Base(ObjectType): + class Meta: + abstract = True + + id = ID() + + def resolve_id(self): + return "{type}_{id}".format( + type=self.__class__.__name__, + id=self.id + ) +``` + ### UUID Scalar In Graphene 2.0 there is a new dedicated scalar for UUIDs, `UUID`. diff --git a/graphene/types/mutation.py b/graphene/types/mutation.py index 32194e9e..e44f8c15 100644 --- a/graphene/types/mutation.py +++ b/graphene/types/mutation.py @@ -6,6 +6,7 @@ from .field import Field from .objecttype import ObjectType, ObjectTypeOptions from .utils import yank_fields_from_attrs from ..utils.auto_resolver import auto_resolver +from ..utils.deprecated import warn_deprecation class MutationOptions(ObjectTypeOptions): @@ -40,7 +41,11 @@ class Mutation(ObjectType): if not input_class: input_class = getattr(cls, 'Input', None) if input_class: - print("WARNING: Please use Arguments for Mutation (Input is for ClientMutationID)") + warn_deprecation(( + "Please use {name}.Arguments instead of {name}.Input." + "Input is now only used in ClientMutationID.\n" + "Read more: https://github.com/graphql-python/graphene/blob/2.0/UPGRADE-v2.0.md#mutation-input" + ).format(name=cls.__name__)) if input_class: arguments = props(input_class)