Skip to content

Commit eed4499

Browse files
authored
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.
1 parent a61f0a2 commit eed4499

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

graphene/types/mutation.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -106,9 +106,7 @@ def __init_subclass_with_meta__(
106106
else:
107107
arguments = {}
108108
if not resolver:
109-
mutate = getattr(cls, "mutate", None)
110-
assert mutate, "All mutations must define a mutate method in it"
111-
resolver = get_unbound_function(mutate)
109+
resolver = get_unbound_function(cls.mutate)
112110
if _meta.fields:
113111
_meta.fields.update(fields)
114112
else:
@@ -119,6 +117,10 @@ def __init_subclass_with_meta__(
119117
_meta.arguments = arguments
120118

121119
super(Mutation, cls).__init_subclass_with_meta__(_meta=_meta, **options)
120+
121+
@classmethod
122+
def mutate(cls, parent, info, **kwargs):
123+
raise NotImplementedError("All mutations must define a mutate method in it")
122124

123125
@classmethod
124126
def Field(

0 commit comments

Comments
 (0)