diff --git a/graphene_django_cud/mutations/batch_create.py b/graphene_django_cud/mutations/batch_create.py index 10459a6..b4c9627 100644 --- a/graphene_django_cud/mutations/batch_create.py +++ b/graphene_django_cud/mutations/batch_create.py @@ -15,6 +15,7 @@ from graphene_django_cud.consts import USE_ID_SUFFIXES_FOR_FK_SETTINGS_KEY, USE_ID_SUFFIXES_FOR_M2M_SETTINGS_KEY from graphene_django_cud.mutations.core import DjangoCudBase, DjangoCudBaseOptions from graphene_django_cud.registry import get_type_meta_registry +from graphene_django_cud.signals import post_batch_create_mutation from graphene_django_cud.util import get_input_fields_for_model, apply_field_name_mappings @@ -256,4 +257,7 @@ def mutate(cls, root, info, input): return_data = {cls._meta.return_field_name: created_objs} cls.after_mutate(root, info, input, created_objs, return_data) + + post_batch_create_mutation.send(sender=Model, instances=created_objs) + return cls(**return_data) diff --git a/graphene_django_cud/mutations/batch_delete.py b/graphene_django_cud/mutations/batch_delete.py index 0294fba..6c2baa6 100644 --- a/graphene_django_cud/mutations/batch_delete.py +++ b/graphene_django_cud/mutations/batch_delete.py @@ -11,6 +11,7 @@ from graphql_relay import to_global_id from graphene_django_cud.mutations.core import DjangoCudBase +from graphene_django_cud.signals import post_batch_delete_mutation class DjangoBatchDeleteMutationOptions(MutationOptions): @@ -131,6 +132,7 @@ def mutate(cls, root, info, ids): deletion_count, _ = qs_to_delete.delete() cls.after_mutate(root, info, ids, deletion_count, deleted_ids) + post_batch_delete_mutation.send(sender=Model, ids=ids, deletion_count=deletion_count, deleted_ids=deleted_ids) return cls( deletion_count=deletion_count, diff --git a/graphene_django_cud/mutations/batch_update.py b/graphene_django_cud/mutations/batch_update.py index 5c2ac3e..20442f4 100644 --- a/graphene_django_cud/mutations/batch_update.py +++ b/graphene_django_cud/mutations/batch_update.py @@ -15,6 +15,7 @@ from graphene_django_cud.consts import USE_ID_SUFFIXES_FOR_M2M_SETTINGS_KEY, USE_ID_SUFFIXES_FOR_FK_SETTINGS_KEY from graphene_django_cud.mutations.core import DjangoCudBase, DjangoCudBaseOptions from graphene_django_cud.registry import get_type_meta_registry +from graphene_django_cud.signals import post_batch_update_mutation from graphene_django_cud.util import get_input_fields_for_model, apply_field_name_mappings @@ -272,4 +273,7 @@ def mutate(cls, root, info, input): return_data = {cls._meta.return_field_name: updated_objs} cls.after_mutate(root, info, input, updated_objs, return_data) + + post_batch_update_mutation.send(sender=Model, instances=updated_objs) + return cls(**return_data) diff --git a/graphene_django_cud/mutations/create.py b/graphene_django_cud/mutations/create.py index 4d4e2f8..34d145d 100644 --- a/graphene_django_cud/mutations/create.py +++ b/graphene_django_cud/mutations/create.py @@ -15,6 +15,7 @@ from graphene_django_cud.consts import USE_ID_SUFFIXES_FOR_FK_SETTINGS_KEY, USE_ID_SUFFIXES_FOR_M2M_SETTINGS_KEY from graphene_django_cud.mutations.core import DjangoCudBase, DjangoCudBaseOptions from graphene_django_cud.registry import get_type_meta_registry +from graphene_django_cud.signals import post_create_mutation from graphene_django_cud.util import get_input_fields_for_model, apply_field_name_mappings @@ -240,4 +241,6 @@ def mutate(cls, root, info, input): return_data = {cls._meta.return_field_name: obj} cls.after_mutate(root, info, input, obj, return_data) + post_create_mutation.send(sender=Model, instance=obj) + return cls(**return_data) diff --git a/graphene_django_cud/mutations/delete.py b/graphene_django_cud/mutations/delete.py index 8a93ac4..2ca77a3 100644 --- a/graphene_django_cud/mutations/delete.py +++ b/graphene_django_cud/mutations/delete.py @@ -12,6 +12,7 @@ from graphql_relay import to_global_id from graphene_django_cud.mutations.core import DjangoCudBase +from graphene_django_cud.signals import post_delete_mutation class DjangoDeleteMutationOptions(MutationOptions): @@ -26,15 +27,15 @@ class Meta: @classmethod def __init_subclass_with_meta__( - cls, - _meta=None, - model=None, - permissions=None, - login_required=None, - only_fields=(), - exclude_fields=(), - return_field_name=None, - **kwargs, + cls, + _meta=None, + model=None, + permissions=None, + login_required=None, + only_fields=(), + exclude_fields=(), + return_field_name=None, + **kwargs, ): registry = get_global_registry() model_type = registry.get_type_for_model(model) @@ -131,6 +132,9 @@ def mutate(cls, root, info, id): raw_id = obj.pk cls.perform_delete(obj) cls.after_mutate(root, info, id, True) + + post_delete_mutation.send(sender=cls._meta.model, id=return_id, raw_id=raw_id, deleted_input_id=id) + return cls( found=True, deleted_raw_id=raw_id, diff --git a/graphene_django_cud/mutations/filter_delete.py b/graphene_django_cud/mutations/filter_delete.py index 10f4781..886b687 100644 --- a/graphene_django_cud/mutations/filter_delete.py +++ b/graphene_django_cud/mutations/filter_delete.py @@ -12,6 +12,7 @@ from graphql_relay import to_global_id from graphene_django_cud.mutations.core import DjangoCudBase +from graphene_django_cud.signals import post_filter_update_mutation, post_filter_delete_mutation from graphene_django_cud.util import get_filter_fields_input_args @@ -167,5 +168,6 @@ def mutate(cls, root, info, input): deletion_count, _ = filter_qs.delete() cls.after_mutate(root, info, input, deletion_count, ids) + post_filter_delete_mutation.send(sender=Model, ids=ids) return cls(deletion_count=deletion_count, deleted_ids=ids) diff --git a/graphene_django_cud/mutations/filter_update.py b/graphene_django_cud/mutations/filter_update.py index 9fc7897..5a1cb41 100644 --- a/graphene_django_cud/mutations/filter_update.py +++ b/graphene_django_cud/mutations/filter_update.py @@ -13,6 +13,7 @@ from graphql import GraphQLError from graphene_django_cud.mutations.core import DjangoCudBase, meta_registry +from graphene_django_cud.signals import post_filter_update_mutation from graphene_django_cud.util import ( get_filter_fields_input_args, get_input_fields_for_model, @@ -240,4 +241,6 @@ def mutate(cls, root, info, filter, data): filter_qs.update(**data) cls.after_mutate(root, info, filter, data, filter_qs) + post_filter_update_mutation.send(sender=Model, instances=filter_qs, data=data) + return cls(updated_objects=filter_qs, updated_count=filter_qs.count()) diff --git a/graphene_django_cud/mutations/update.py b/graphene_django_cud/mutations/update.py index 0d8a3cd..e5255bd 100644 --- a/graphene_django_cud/mutations/update.py +++ b/graphene_django_cud/mutations/update.py @@ -14,6 +14,7 @@ from graphene_django_cud.consts import USE_ID_SUFFIXES_FOR_FK_SETTINGS_KEY, USE_ID_SUFFIXES_FOR_M2M_SETTINGS_KEY from graphene_django_cud.mutations.core import DjangoCudBaseOptions, DjangoCudBase from graphene_django_cud.registry import get_type_meta_registry +from graphene_django_cud.signals import post_update_mutation from graphene_django_cud.util import get_input_fields_for_model, to_snake_case, apply_field_name_mappings @@ -254,4 +255,6 @@ def mutate(cls, root, info, input, id): return_data = {cls._meta.return_field_name: obj} cls.after_mutate(root, info, id, input, obj, return_data) + post_update_mutation.send(sender=Model, instance=obj) + return cls(**return_data) diff --git a/graphene_django_cud/signals.py b/graphene_django_cud/signals.py new file mode 100644 index 0000000..ddb1f1c --- /dev/null +++ b/graphene_django_cud/signals.py @@ -0,0 +1,12 @@ +from django.dispatch import Signal + +post_create_mutation = Signal() +post_update_mutation = Signal() +post_delete_mutation = Signal() + +post_batch_create_mutation = Signal() +post_batch_update_mutation = Signal() +post_batch_delete_mutation = Signal() + +post_filter_update_mutation = Signal() +post_filter_delete_mutation = Signal()