Skip to content

Commit

Permalink
Define abstract Mutation.mutate() method
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
belkka committed Dec 26, 2023
1 parent 5fb7b54 commit a97d3d3
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions graphene/types/mutation.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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(
Expand Down

0 comments on commit a97d3d3

Please sign in to comment.