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 authored Dec 2, 2021
1 parent a61f0a2 commit eed4499
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 @@ -106,9 +106,7 @@ def __init_subclass_with_meta__(
else:
arguments = {}
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 @@ -119,6 +117,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 eed4499

Please sign in to comment.