From a97d3d3321b5bfa007d6bd4d3d02bba126a0d8a8 Mon Sep 17 00:00:00 2001 From: belkka Date: Thu, 2 Dec 2021 08:56:29 +0200 Subject: [PATCH] Define abstract Mutation.mutate() method Add default implementation of Mutation.mutate() that raises NotImplementedError. This makes code more clear and also improves work of auto-completion tools (e. g. in IDE). They usually guess if user is overriding a class method and suggest to complete method name/arguments. --- graphene/types/mutation.py | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/graphene/types/mutation.py b/graphene/types/mutation.py index 2de21b36..a7619c0a 100644 --- a/graphene/types/mutation.py +++ b/graphene/types/mutation.py @@ -104,9 +104,7 @@ def __init_subclass_with_meta__( ) arguments = props(input_class) if input_class else {} if not resolver: - mutate = getattr(cls, "mutate", None) - assert mutate, "All mutations must define a mutate method in it" - resolver = get_unbound_function(mutate) + resolver = get_unbound_function(cls.mutate) if _meta.fields: _meta.fields.update(fields) else: @@ -117,6 +115,10 @@ def __init_subclass_with_meta__( _meta.arguments = arguments super(Mutation, cls).__init_subclass_with_meta__(_meta=_meta, **options) + + @classmethod + def mutate(cls, parent, info, **kwargs): + raise NotImplementedError("All mutations must define a mutate method in it") @classmethod def Field(