Skip to content

Commit a97d3d3

Browse files
committed
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 5fb7b54 commit a97d3d3

File tree

1 file changed

+5
-3
lines changed

1 file changed

+5
-3
lines changed

Diff for: graphene/types/mutation.py

+5-3
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ def __init_subclass_with_meta__(
104104
)
105105
arguments = props(input_class) if input_class else {}
106106
if not resolver:
107-
mutate = getattr(cls, "mutate", None)
108-
assert mutate, "All mutations must define a mutate method in it"
109-
resolver = get_unbound_function(mutate)
107+
resolver = get_unbound_function(cls.mutate)
110108
if _meta.fields:
111109
_meta.fields.update(fields)
112110
else:
@@ -117,6 +115,10 @@ def __init_subclass_with_meta__(
117115
_meta.arguments = arguments
118116

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

121123
@classmethod
122124
def Field(

0 commit comments

Comments
 (0)