Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Dry run webhook events. (#11548)

Piotr Zabieglikdf46b0f753f2
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4dcc62e03e..1f61a6380a 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,18 +11,19 @@ All notable, unreleased changes to this project will be documented in this file.
- Add ability to filter and sort products of a category - #10917 by @yemeksepeti-cihankarluk, @ogunheper
- Add `filter` argument to `Category.products`
- Add `sortBy` argument to `Category.products`
- - Allow to mutate objects, by newly added `externalReference` field, instead of Saleor-assigned ID. Apply to following models:
- - `Product`
- - `ProductVariant`
- - `Attribute`
- - `AttributeValue`
- - `Order`
- - `User`
- - `Warehouse`
- Extend invoice object types with `Order` references - #11505 by @przlada
- Add `Invoice.order` field
- Add `InvoiceRequested.order`, `InvoiceDeleted.order` and `InvoiceSent.order` fields
- Add support for metadata for `Address` model - #11701 by @IKarbowiak
+- Allow to mutate objects, by newly added `externalReference` field, instead of Saleor-assigned ID. Apply to following models: #11410 by @zedzior
+ - `Product`
+ - `ProductVariant`
+ - `Attribute`
+ - `AttributeValue`
+ - `Order`
+ - `User`
+ - `Warehouse`
+- Add `WebhookDryRun` mutation - #11548 by @zedzior
### Other changes
- Fix fetching the `checkout.availableCollectionPoints` - #11489 by @IKarbowiak
diff --git a/saleor/graphql/core/enums.py b/saleor/graphql/core/enums.py
index 63ce30c695..969899456b 100644
--- a/saleor/graphql/core/enums.py
+++ b/saleor/graphql/core/enums.py
@@ -149,3 +149,6 @@ UploadErrorCode = graphene.Enum.from_enum(core_error_codes.UploadErrorCode)
WarehouseErrorCode = graphene.Enum.from_enum(warehouse_error_codes.WarehouseErrorCode)
WebhookErrorCode = graphene.Enum.from_enum(webhook_error_codes.WebhookErrorCode)
TranslationErrorCode = graphene.Enum.from_enum(core_error_codes.TranslationErrorCode)
+WebhookDryRunErrorCode = graphene.Enum.from_enum(
+ webhook_error_codes.WebhookDryRunErrorCode
+)
diff --git a/saleor/graphql/core/types/__init__.py b/saleor/graphql/core/types/__init__.py
index dfeb90211c..88bcf7b616 100644
--- a/saleor/graphql/core/types/__init__.py
+++ b/saleor/graphql/core/types/__init__.py
@@ -52,9 +52,11 @@ from .common import (
TranslationError,
UploadError,
WarehouseError,
+ WebhookDryRunError,
WebhookError,
Weight,
)
+from .event import SubscriptionObjectType
from .filter_input import ChannelFilterInputObjectType, FilterInputObjectType
from .model import ModelObjectType
from .money import VAT, Money, MoneyRange, ReducedRate, TaxedMoney, TaxedMoneyRange
@@ -77,6 +79,7 @@ __all__ = [
"DateTimeRangeInput",
"DiscountError",
"Error",
+ "SubscriptionObjectType",
"ExportError",
"ExternalNotificationError",
"File",
@@ -123,6 +126,7 @@ __all__ = [
"Weight",
"WarehouseError",
"WebhookError",
+ "WebhookDryRunError",
"FilterInputObjectType",
"SortInputObjectType",
"ChannelFilterInputObjectType",
diff --git a/saleor/graphql/core/types/common.py b/saleor/graphql/core/types/common.py
index 1a2fd0c90f..ac837a6c97 100644
--- a/saleor/graphql/core/types/common.py
+++ b/saleor/graphql/core/types/common.py
@@ -43,6 +43,7 @@ from ..enums import (
TranslationErrorCode,
UploadErrorCode,
WarehouseErrorCode,
+ WebhookDryRunErrorCode,
WebhookErrorCode,
WeightUnitsEnum,
)
@@ -55,6 +56,7 @@ if TYPE_CHECKING:
# deprecated - this is temporary constant that contains the graphql types
# which has double id available - uuid and old int id
+
TYPES_WITH_DOUBLE_ID_AVAILABLE = ["Order", "OrderLine", "OrderDiscount", "CheckoutLine"]
@@ -410,6 +412,10 @@ class WebhookError(Error):
code = WebhookErrorCode(description="The error code.", required=True)
+class WebhookDryRunError(Error):
+ code = WebhookDryRunErrorCode(description="The error code.", required=True)
+
+
class TranslationError(Error):
code = TranslationErrorCode(description="The error code.", required=True)
diff --git a/saleor/graphql/core/types/event.py b/saleor/graphql/core/types/event.py
new file mode 100644
index 0000000000..ae74ce1d16
--- /dev/null
+++ b/saleor/graphql/core/types/event.py
@@ -0,0 +1,23 @@
+from graphene import ObjectType
+from graphene.types.objecttype import ObjectTypeOptions
+
+
+class SubscriptionObjectType(ObjectType):
+ class Meta:
+ abstract = True
+
+ @classmethod
+ def __init_subclass_with_meta__(
+ cls,
+ root_type=None,
+ enable_dry_run=False,
+ _meta=None,
+ **options,
+ ):
+ if not _meta:
+ _meta = ObjectTypeOptions(cls)
+
+ _meta.root_type = root_type
+ _meta.enable_dry_run = enable_dry_run
+
+ super().__init_subclass_with_meta__(_meta=_meta, **options)
diff --git a/saleor/graphql/core/utils/__init__.py b/saleor/graphql/core/utils/__init__.py
index cb692a3f41..1c0d9146a5 100644
--- a/saleor/graphql/core/utils/__init__.py
+++ b/saleor/graphql/core/utils/__init__.py
@@ -113,6 +113,10 @@ def add_hash_to_file_name(file):
file._name = new_name
+def raise_validation_error(field=None, message=None, code=None):
+ raise ValidationError({field: ValidationError(message, code=code)})
+
+
def ext_ref_to_global_id_or_error(model, external_reference):
"""Convert external reference to graphen global id."""
internal_id = (
@@ -123,11 +127,8 @@ def ext_ref_to_global_id_or_error(model, external_reference):
if internal_id:
return graphene.Node.to_global_id(model.__name__, internal_id)
else:
- raise ValidationError(
- {
- "externalReference": ValidationError(
- f"Couldn't resolve to a node: {external_reference}",
- code="not_found",
- )
- }
+ raise_validation_error(
+ field="externalReference",
+ message=f"Couldn't resolve to a node: {external_reference}",
+ code="not_found",
)
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 77c1754f01..26cb10f4d9 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -11946,6 +11946,23 @@ type Mutation {
id: ID!
): EventDeliveryRetry
+ """
+ Performs a dry run of a webhook event. Supports a single event (the first if multiple provided in the `query`). Requires permission relevant to processed event.
+
+ Added in Saleor 3.10.
+
+ Note: this API is currently in Feature Preview and can be subject to changes at later point.
+
+ Requires one of the following permissions: AUTHENTICATED_STAFF_USER.
+ """
+ webhookDryRun(
+ """The ID of an object to serialize."""
+ objectId: ID!
+
+ """The subscription query that defines the webhook event and its payload."""
+ query: String!
+ ): WebhookDryRun
+
"""
Creates new warehouse.
@@ -15891,6 +15908,44 @@ type EventDeliveryRetry {
errors: [WebhookError!]!
}
+"""
+Performs a dry run of a webhook event. Supports a single event (the first if multiple provided in the `query`). Requires permission relevant to processed event.
+
+Added in Saleor 3.10.
+
+Note: this API is currently in Feature Preview and can be subject to changes at later point.
+
+Requires one of the following permissions: AUTHENTICATED_STAFF_USER.
+"""
+type WebhookDryRun {
+ """JSON payload, that would be sent out to webhook's target URL."""
+ payload: JSONString
+ errors: [WebhookDryRunError!]!
+}
+
+type WebhookDryRunError {
+ """
+ Name of a field that caused the error. A value of `null` indicates that the error isn't associated with a particular field.
+ """
+ field: String
+
+ """The error message."""
+ message: String
+
+ """The error code."""
+ code: WebhookDryRunErrorCode!
+}
+
+"""An enumeration."""
+enum WebhookDryRunErrorCode {
+ GRAPHQL_ERROR
+ UNABLE_TO_PARSE
+ NOT_FOUND
+ INVALID_ID
+ MISSING_PERMISSION
+ TYPE_NOT_SUPPORTED
+}
+
"""
Creates new warehouse.
diff --git a/saleor/graphql/webhook/mutations.py b/saleor/graphql/webhook/mutations.py
index 15237f7152..daa379e501 100644
--- a/saleor/graphql/webhook/mutations.py
+++ b/saleor/graphql/webhook/mutations.py
@@ -1,19 +1,34 @@
import graphene
from django.core.exceptions import ValidationError
from django.db import IntegrityError
+from graphene.utils.str_converters import to_camel_case
from ...core.permissions import AppPermission, AuthorizationFilters
from ...webhook import models
-from ...webhook.error_codes import WebhookErrorCode
+from ...webhook.error_codes import WebhookDryRunErrorCode, WebhookErrorCode
+from ...webhook.event_types import WebhookEventAsyncType
from ..app.dataloaders import get_app_promise
from ..core import ResolveInfo
-from ..core.descriptions import ADDED_IN_32, DEPRECATED_IN_3X_INPUT, PREVIEW_FEATURE
+from ..core.descriptions import (
+ ADDED_IN_32,
+ ADDED_IN_310,
+ DEPRECATED_IN_3X_INPUT,
+ PREVIEW_FEATURE,
+)
+from ..core.fields import JSONString
from ..core.mutations import BaseMutation, ModelDeleteMutation, ModelMutation
-from ..core.types import NonNullList, WebhookError
+from ..core.types import NonNullList, WebhookDryRunError, WebhookError
+from ..core.utils import raise_validation_error
from ..plugins.dataloaders import get_plugin_manager_promise
from . import enums
-from .subscription_payload import validate_query
+from .subscription_payload import (
+ generate_payload_from_subscription,
+ initialize_request,
+ validate_query,
+)
+from .subscription_types import WEBHOOK_TYPES_MAP
from .types import EventDelivery, Webhook
+from .utils import get_event_type_from_subscription
class WebhookCreateInput(graphene.InputObjectType):
@@ -306,3 +321,101 @@ class EventDeliveryRetry(BaseMutation):
manager = get_plugin_manager_promise(info.context).get()
manager.event_delivery_retry(delivery)
return EventDeliveryRetry(delivery=delivery)
+
+
+class WebhookDryRun(BaseMutation):
+ payload = JSONString(
+ description="JSON payload, that would be sent out to webhook's target URL."
+ )
+
+ class Arguments:
+ query = graphene.String(
+ description="The subscription query that defines the webhook event and its "
+ "payload.",
+ required=True,
+ )
+ object_id = graphene.ID(
+ description="The ID of an object to serialize.", required=True
+ )
+
+ class Meta:
+ description = (
+ "Performs a dry run of a webhook event. "
+ "Supports a single event (the first if multiple provided in the `query`). "
+ "Requires permission relevant to processed event."
+ + ADDED_IN_310
+ + PREVIEW_FEATURE
+ )
+ permissions = (AuthorizationFilters.AUTHENTICATED_STAFF_USER,)
+ error_type_class = WebhookDryRunError
+
+ @classmethod
+ def validate_input(cls, info, **data):
+ query = data.get("query")
+ object_id = data.get("object_id")
+
+ event_type = get_event_type_from_subscription(query) if query else None
+ if not event_type:
+ raise_validation_error(
+ field="query",
+ message="Can't parse an event type from query.",
+ code=WebhookDryRunErrorCode.UNABLE_TO_PARSE,
+ )
+
+ event = WEBHOOK_TYPES_MAP.get(event_type) if event_type else None
+ if not event and event_type:
+ event_name = event_type[0].upper() + to_camel_case(event_type)[1:]
+ raise_validation_error(
+ field="query",
+ message=f"Event type: {event_name} is not defined in graphql schema.",
+ code=WebhookDryRunErrorCode.GRAPHQL_ERROR,
+ )
+
+ model, _ = graphene.Node.from_global_id(object_id)
+ model_name = event._meta.root_type # type: ignore[union-attr]
+ enable_dry_run = event._meta.enable_dry_run # type: ignore[union-attr]
+
+ if not (model_name or enable_dry_run) and event_type:
+ event_name = event_type[0].upper() + to_camel_case(event_type)[1:]
+ raise_validation_error(
+ field="query",
+ message=f"Event type: {event_name} not supported.",
+ code=WebhookDryRunErrorCode.TYPE_NOT_SUPPORTED,
+ )
+ if model != model_name:
+ raise_validation_error(
+ field="objectId",
+ message="ObjectId doesn't match event type.",
+ code=WebhookDryRunErrorCode.INVALID_ID,
+ )
+
+ object = cls.get_node_or_error(info, object_id, field="objectId")
+
+ if (
+ permission := WebhookEventAsyncType.PERMISSIONS.get(event_type)
+ if event_type
+ else None
+ ):
+
+ codename = permission.value.split(".")[1]
+ user_permissions = [
+ perm.codename for perm in info.context.user.effective_permissions.all()
+ ]
+ if codename not in user_permissions:
+ raise_validation_error(
+ message=f"The user doesn't have required permission: {codename}.",
+ code=WebhookDryRunErrorCode.MISSING_PERMISSION,
+ )
+
+ return event_type, object, query
+
+ @classmethod
+ def perform_mutation(cls, _root, info, **data):
+ event_type, object, query = cls.validate_input(info, **data)
+ payload = None
+ if all([event_type, object, query]):
+ request = initialize_request()
+ payload = generate_payload_from_subscription(
+ event_type, object, query, request
+ )
+ return WebhookDryRun(payload=payload)
diff --git a/saleor/graphql/webhook/schema.py b/saleor/graphql/webhook/schema.py
index 641da7c000..a8a0b93984 100644
--- a/saleor/graphql/webhook/schema.py
+++ b/saleor/graphql/webhook/schema.py
@@ -7,7 +7,13 @@ from ..core.descriptions import DEPRECATED_IN_3X_FIELD
from ..core.fields import JSONString, PermissionsField
from ..core.types import NonNullList
from .enums import WebhookSampleEventTypeEnum
-from .mutations import EventDeliveryRetry, WebhookCreate, WebhookDelete, WebhookUpdate
+from .mutations import (
+ EventDeliveryRetry,
+ WebhookCreate,
+ WebhookDelete,
+ WebhookDryRun,
+ WebhookUpdate,
+)
from .resolvers import resolve_sample_payload, resolve_webhook, resolve_webhook_events
from .types import Webhook, WebhookEvent
@@ -65,3 +71,4 @@ class WebhookMutations(graphene.ObjectType):
webhook_delete = WebhookDelete.Field()
webhook_update = WebhookUpdate.Field()
event_delivery_retry = EventDeliveryRetry.Field()
+ webhook_dry_run = WebhookDryRun.Field()
diff --git a/saleor/graphql/webhook/subscription_types.py b/saleor/graphql/webhook/subscription_types.py
index 34fa9830e2..a7557f3e84 100644
--- a/saleor/graphql/webhook/subscription_types.py
+++ b/saleor/graphql/webhook/subscription_types.py
@@ -1,6 +1,6 @@
import graphene
from django.utils import timezone
-from graphene import AbstractType, ObjectType, Union
+from graphene import AbstractType, Union
from rx import Observable
from ... import __version__
@@ -36,7 +36,7 @@ from ..core.descriptions import (
PREVIEW_FEATURE,
)
from ..core.scalars import PositiveDecimal
-from ..core.types import NonNullList
+from ..core.types import NonNullList, SubscriptionObjectType
from ..order.dataloaders import OrderByIdLoader
from ..payment.enums import TransactionActionEnum
from ..payment.types import TransactionItem
@@ -124,24 +124,30 @@ class AddressBase(AbstractType):
return address
-class AddressCreated(ObjectType, AddressBase):
+class AddressCreated(SubscriptionObjectType, AddressBase):
class Meta:
+ root_type = "Address"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new address is created." + ADDED_IN_35 + PREVIEW_FEATURE
)
-class AddressUpdated(ObjectType, AddressBase):
+class AddressUpdated(SubscriptionObjectType, AddressBase):
class Meta:
+ root_type = "Address"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when address is updated." + ADDED_IN_35 + PREVIEW_FEATURE
)
-class AddressDeleted(ObjectType, AddressBase):
+class AddressDeleted(SubscriptionObjectType, AddressBase):
class Meta:
+ root_type = "Address"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when address is deleted." + ADDED_IN_35 + PREVIEW_FEATURE
@@ -160,28 +166,36 @@ class AppBase(AbstractType):
return app
-class AppInstalled(ObjectType, AppBase):
+class AppInstalled(SubscriptionObjectType, AppBase):
class Meta:
+ root_type = "App"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new app is installed." + ADDED_IN_34 + PREVIEW_FEATURE
)
-class AppUpdated(ObjectType, AppBase):
+class AppUpdated(SubscriptionObjectType, AppBase):
class Meta:
+ root_type = "App"
+ enable_dry_run = True
interfaces = (Event,)
description = "Event sent when app is updated." + ADDED_IN_34 + PREVIEW_FEATURE
-class AppDeleted(ObjectType, AppBase):
+class AppDeleted(SubscriptionObjectType, AppBase):
class Meta:
+ root_type = "App"
+ enable_dry_run = True
interfaces = (Event,)
description = "Event sent when app is deleted." + ADDED_IN_34 + PREVIEW_FEATURE
-class AppStatusChanged(ObjectType, AppBase):
+class AppStatusChanged(SubscriptionObjectType, AppBase):
class Meta:
+ root_type = "App"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when app status has changed." + ADDED_IN_34 + PREVIEW_FEATURE
@@ -200,24 +214,30 @@ class AttributeBase(AbstractType):
return attribute
-class AttributeCreated(ObjectType, AttributeBase):
+class AttributeCreated(SubscriptionObjectType, AttributeBase):
class Meta:
+ root_type = "Attribute"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new attribute is created." + ADDED_IN_35 + PREVIEW_FEATURE
)
-class AttributeUpdated(ObjectType, AttributeBase):
+class AttributeUpdated(SubscriptionObjectType, AttributeBase):
class Meta:
+ root_type = "Attribute"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when attribute is updated." + ADDED_IN_35 + PREVIEW_FEATURE
)
-class AttributeDeleted(ObjectType, AttributeBase):
+class AttributeDeleted(SubscriptionObjectType, AttributeBase):
class Meta:
+ root_type = "Attribute"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when attribute is deleted." + ADDED_IN_35 + PREVIEW_FEATURE
@@ -236,8 +256,10 @@ class AttributeValueBase(AbstractType):
return attribute
-class AttributeValueCreated(ObjectType, AttributeValueBase):
+class AttributeValueCreated(SubscriptionObjectType, AttributeValueBase):
class Meta:
+ root_type = "AttributeValue"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new attribute value is created."
@@ -246,8 +268,10 @@ class AttributeValueCreated(ObjectType, AttributeValueBase):
)
-class AttributeValueUpdated(ObjectType, AttributeValueBase):
+class AttributeValueUpdated(SubscriptionObjectType, AttributeValueBase):
class Meta:
+ root_type = "AttributeValue"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when attribute value is updated."
@@ -256,8 +280,10 @@ class AttributeValueUpdated(ObjectType, AttributeValueBase):
)
-class AttributeValueDeleted(ObjectType, AttributeValueBase):
+class AttributeValueDeleted(SubscriptionObjectType, AttributeValueBase):
class Meta:
+ root_type = "AttributeValue"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when attribute value is deleted."
@@ -278,24 +304,30 @@ class CategoryBase(AbstractType):
return category
-class CategoryCreated(ObjectType, CategoryBase):
+class CategoryCreated(SubscriptionObjectType, CategoryBase):
class Meta:
+ root_type = "Category"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new category is created." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class CategoryUpdated(ObjectType, CategoryBase):
+class CategoryUpdated(SubscriptionObjectType, CategoryBase):
class Meta:
+ root_type = "Category"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when category is updated." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class CategoryDeleted(ObjectType, CategoryBase):
+class CategoryDeleted(SubscriptionObjectType, CategoryBase):
class Meta:
+ root_type = "Category"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when category is deleted." + ADDED_IN_32 + PREVIEW_FEATURE
@@ -314,32 +346,40 @@ class ChannelBase(AbstractType):
return channel
-class ChannelCreated(ObjectType, ChannelBase):
+class ChannelCreated(SubscriptionObjectType, ChannelBase):
class Meta:
+ root_type = "Channel"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new channel is created." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class ChannelUpdated(ObjectType, ChannelBase):
+class ChannelUpdated(SubscriptionObjectType, ChannelBase):
class Meta:
+ root_type = "Channel"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when channel is updated." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class ChannelDeleted(ObjectType, ChannelBase):
+class ChannelDeleted(SubscriptionObjectType, ChannelBase):
class Meta:
+ root_type = "Channel"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when channel is deleted." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class ChannelStatusChanged(ObjectType, ChannelBase):
+class ChannelStatusChanged(SubscriptionObjectType, ChannelBase):
class Meta:
+ root_type = "Channel"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when channel status has changed."
@@ -360,64 +400,80 @@ class OrderBase(AbstractType):
return order
-class OrderCreated(ObjectType, OrderBase):
+class OrderCreated(SubscriptionObjectType, OrderBase):
class Meta:
+ root_type = "Order"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new order is created." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class OrderUpdated(ObjectType, OrderBase):
+class OrderUpdated(SubscriptionObjectType, OrderBase):
class Meta:
+ root_type = "Order"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when order is updated." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class OrderConfirmed(ObjectType, OrderBase):
+class OrderConfirmed(SubscriptionObjectType, OrderBase):
class Meta:
+ root_type = "Order"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when order is confirmed." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class OrderFullyPaid(ObjectType, OrderBase):
+class OrderFullyPaid(SubscriptionObjectType, OrderBase):
class Meta:
+ root_type = "Order"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when order is fully paid." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class OrderFulfilled(ObjectType, OrderBase):
+class OrderFulfilled(SubscriptionObjectType, OrderBase):
class Meta:
+ root_type = "Order"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when order is fulfilled." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class OrderCancelled(ObjectType, OrderBase):
+class OrderCancelled(SubscriptionObjectType, OrderBase):
class Meta:
+ root_type = "Order"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when order is canceled." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class OrderMetadataUpdated(ObjectType, OrderBase):
+class OrderMetadataUpdated(SubscriptionObjectType, OrderBase):
class Meta:
+ root_type = "Order"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when order metadata is updated." + ADDED_IN_38 + PREVIEW_FEATURE
)
-class DraftOrderCreated(ObjectType, OrderBase):
+class DraftOrderCreated(SubscriptionObjectType, OrderBase):
class Meta:
+ root_type = "Order"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new draft order is created."
@@ -426,16 +482,20 @@ class DraftOrderCreated(ObjectType, OrderBase):
)
-class DraftOrderUpdated(ObjectType, OrderBase):
+class DraftOrderUpdated(SubscriptionObjectType, OrderBase):
class Meta:
+ root_type = "Order"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when draft order is updated." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class DraftOrderDeleted(ObjectType, OrderBase):
+class DraftOrderDeleted(SubscriptionObjectType, OrderBase):
class Meta:
+ root_type = "Order"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when draft order is deleted." + ADDED_IN_32 + PREVIEW_FEATURE
@@ -454,32 +514,40 @@ class GiftCardBase(AbstractType):
return gift_card
-class GiftCardCreated(ObjectType, GiftCardBase):
+class GiftCardCreated(SubscriptionObjectType, GiftCardBase):
class Meta:
+ root_type = "GiftCard"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new gift card is created." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class GiftCardUpdated(ObjectType, GiftCardBase):
+class GiftCardUpdated(SubscriptionObjectType, GiftCardBase):
class Meta:
+ root_type = "GiftCard"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when gift card is updated." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class GiftCardDeleted(ObjectType, GiftCardBase):
+class GiftCardDeleted(SubscriptionObjectType, GiftCardBase):
class Meta:
+ root_type = "GiftCard"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when gift card is deleted." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class GiftCardStatusChanged(ObjectType, GiftCardBase):
+class GiftCardStatusChanged(SubscriptionObjectType, GiftCardBase):
class Meta:
+ root_type = "GiftCard"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when gift card status has changed."
@@ -488,8 +556,10 @@ class GiftCardStatusChanged(ObjectType, GiftCardBase):
)
-class GiftCardMetadataUpdated(ObjectType, GiftCardBase):
+class GiftCardMetadataUpdated(SubscriptionObjectType, GiftCardBase):
class Meta:
+ root_type = "GiftCard"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when gift card metadata is updated."
@@ -513,22 +583,28 @@ class MenuBase(AbstractType):
return ChannelContext(node=menu, channel_slug=channel)
-class MenuCreated(ObjectType, MenuBase):
+class MenuCreated(SubscriptionObjectType, MenuBase):
class Meta:
+ root_type = "Menu"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new menu is created." + ADDED_IN_34 + PREVIEW_FEATURE
)
-class MenuUpdated(ObjectType, MenuBase):
+class MenuUpdated(SubscriptionObjectType, MenuBase):
class Meta:
+ root_type = "Menu"
+ enable_dry_run = True
interfaces = (Event,)
description = "Event sent when menu is updated." + ADDED_IN_34 + PREVIEW_FEATURE
-class MenuDeleted(ObjectType, MenuBase):
+class MenuDeleted(SubscriptionObjectType, MenuBase):
class Meta:
+ root_type = "Menu"
+ enable_dry_run = True
interfaces = (Event,)
description = "Event sent when menu is deleted." + ADDED_IN_34 + PREVIEW_FEATURE
@@ -548,24 +624,30 @@ class MenuItemBase(AbstractType):
return ChannelContext(node=menu_item, channel_slug=channel)
-class MenuItemCreated(ObjectType, MenuItemBase):
+class MenuItemCreated(SubscriptionObjectType, MenuItemBase):
class Meta:
+ root_type = "MenuItem"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new menu item is created." + ADDED_IN_34 + PREVIEW_FEATURE
)
-class MenuItemUpdated(ObjectType, MenuItemBase):
+class MenuItemUpdated(SubscriptionObjectType, MenuItemBase):
class Meta:
+ root_type = "MenuItem"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when menu item is updated." + ADDED_IN_34 + PREVIEW_FEATURE
)
-class MenuItemDeleted(ObjectType, MenuItemBase):
+class MenuItemDeleted(SubscriptionObjectType, MenuItemBase):
class Meta:
+ root_type = "MenuItem"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when menu item is deleted." + ADDED_IN_34 + PREVIEW_FEATURE
@@ -596,32 +678,40 @@ class ProductBase(AbstractType):
return product.category
-class ProductCreated(ObjectType, ProductBase):
+class ProductCreated(SubscriptionObjectType, ProductBase):
class Meta:
+ root_type = "Product"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new product is created." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class ProductUpdated(ObjectType, ProductBase):
+class ProductUpdated(SubscriptionObjectType, ProductBase):
class Meta:
+ root_type = "Product"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when product is updated." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class ProductDeleted(ObjectType, ProductBase):
+class ProductDeleted(SubscriptionObjectType, ProductBase):
class Meta:
+ root_type = "Product"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when product is deleted." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class ProductMetadataUpdated(ObjectType, ProductBase):
+class ProductMetadataUpdated(SubscriptionObjectType, ProductBase):
class Meta:
+ root_type = "Product"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when product metadata is updated."
@@ -645,8 +735,10 @@ class ProductVariantBase(AbstractType):
return ChannelContext(node=variant, channel_slug=channel)
-class ProductVariantCreated(ObjectType, ProductVariantBase):
+class ProductVariantCreated(SubscriptionObjectType, ProductVariantBase):
class Meta:
+ root_type = "Product"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new product variant is created."
@@ -655,8 +747,10 @@ class ProductVariantCreated(ObjectType, ProductVariantBase):
)
-class ProductVariantUpdated(ObjectType, ProductVariantBase):
+class ProductVariantUpdated(SubscriptionObjectType, ProductVariantBase):
class Meta:
+ root_type = "Product"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when product variant is updated."
@@ -665,8 +759,10 @@ class ProductVariantUpdated(ObjectType, ProductVariantBase):
)
-class ProductVariantDeleted(ObjectType, ProductVariantBase):
+class ProductVariantDeleted(SubscriptionObjectType, ProductVariantBase):
class Meta:
+ root_type = "Product"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when product variant is deleted."
@@ -675,8 +771,10 @@ class ProductVariantDeleted(ObjectType, ProductVariantBase):
)
-class ProductVariantMetadataUpdated(ObjectType, ProductVariantBase):
+class ProductVariantMetadataUpdated(SubscriptionObjectType, ProductVariantBase):
class Meta:
+ root_type = "Product"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when product variant metadata is updated."
@@ -685,12 +783,14 @@ class ProductVariantMetadataUpdated(ObjectType, ProductVariantBase):
)
-class ProductVariantOutOfStock(ObjectType, ProductVariantBase):
+class ProductVariantOutOfStock(SubscriptionObjectType, ProductVariantBase):
warehouse = graphene.Field(
"saleor.graphql.warehouse.types.Warehouse", description="Look up a warehouse."
)
class Meta:
+ root_type = "Stock"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when product variant is out of stock."
@@ -710,12 +810,14 @@ class ProductVariantOutOfStock(ObjectType, ProductVariantBase):
return stock.warehouse
-class ProductVariantBackInStock(ObjectType, ProductVariantBase):
+class ProductVariantBackInStock(SubscriptionObjectType, ProductVariantBase):
warehouse = graphene.Field(
"saleor.graphql.warehouse.types.Warehouse", description="Look up a warehouse."
)
class Meta:
+ root_type = "Stock"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when product variant is back in stock."
@@ -750,27 +852,33 @@ class SaleBase(AbstractType):
return ChannelContext(node=sale, channel_slug=channel)
-class SaleCreated(ObjectType, SaleBase):
+class SaleCreated(SubscriptionObjectType, SaleBase):
class Meta:
+ root_type = "Sale"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new sale is created." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class SaleUpdated(ObjectType, SaleBase):
+class SaleUpdated(SubscriptionObjectType, SaleBase):
class Meta:
+ root_type = "Sale"
+ enable_dry_run = True
interfaces = (Event,)
description = "Event sent when sale is updated." + ADDED_IN_32 + PREVIEW_FEATURE
-class SaleDeleted(ObjectType, SaleBase):
+class SaleDeleted(SubscriptionObjectType, SaleBase):
class Meta:
+ root_type = "Sale"
+ enable_dry_run = True
interfaces = (Event,)
description = "Event sent when sale is deleted." + ADDED_IN_32 + PREVIEW_FEATURE
-class SaleToggle(ObjectType, SaleBase):
+class SaleToggle(SubscriptionObjectType, SaleBase):
sale = graphene.Field(
"saleor.graphql.discount.types.Sale",
channel=graphene.String(
@@ -780,6 +888,8 @@ class SaleToggle(ObjectType, SaleBase):
)
class Meta:
+ root_type = "Sale"
+ enable_dry_run = True
description = (
"The event informs about the start or end of the sale."
+ ADDED_IN_35
@@ -809,7 +919,7 @@ class InvoiceBase(AbstractType):
return OrderByIdLoader(_info.context).load(invoice.order_id)
-class InvoiceRequested(ObjectType, InvoiceBase):
+class InvoiceRequested(SubscriptionObjectType, InvoiceBase):
order = graphene.Field(
"saleor.graphql.order.types.Order",
required=True,
@@ -817,22 +927,28 @@ class InvoiceRequested(ObjectType, InvoiceBase):
)
class Meta:
+ root_type = "Invoice"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when invoice is requested." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class InvoiceDeleted(ObjectType, InvoiceBase):
+class InvoiceDeleted(SubscriptionObjectType, InvoiceBase):
class Meta:
+ root_type = "Invoice"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when invoice is deleted." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class InvoiceSent(ObjectType, InvoiceBase):
+class InvoiceSent(SubscriptionObjectType, InvoiceBase):
class Meta:
+ root_type = "Invoice"
+ enable_dry_run = True
interfaces = (Event,)
description = "Event sent when invoice is sent." + ADDED_IN_32 + PREVIEW_FEATURE
@@ -858,8 +974,10 @@ class FulfillmentBase(AbstractType):
return fulfillment.order
-class FulfillmentCreated(ObjectType, FulfillmentBase):
+class FulfillmentCreated(SubscriptionObjectType, FulfillmentBase):
class Meta:
+ root_type = "Fulfillment"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new fulfillment is created."
@@ -868,24 +986,30 @@ class FulfillmentCreated(ObjectType, FulfillmentBase):
)
-class FulfillmentCanceled(ObjectType, FulfillmentBase):
+class FulfillmentCanceled(SubscriptionObjectType, FulfillmentBase):
class Meta:
+ root_type = "Fulfillment"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when fulfillment is canceled." + ADDED_IN_34 + PREVIEW_FEATURE
)
-class FulfillmentApproved(ObjectType, FulfillmentBase):
+class FulfillmentApproved(SubscriptionObjectType, FulfillmentBase):
class Meta:
+ root_type = "Fulfillment"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when fulfillment is approved." + ADDED_IN_37 + PREVIEW_FEATURE
)
-class FulfillmentMetadataUpdated(ObjectType, FulfillmentBase):
+class FulfillmentMetadataUpdated(SubscriptionObjectType, FulfillmentBase):
class Meta:
+ root_type = "Fulfillment"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when fulfillment metadata is updated."
@@ -906,8 +1030,10 @@ class UserBase(AbstractType):
return user
-class CustomerCreated(ObjectType, UserBase):
+class CustomerCreated(SubscriptionObjectType, UserBase):
class Meta:
+ root_type = "User"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new customer user is created."
@@ -916,16 +1042,20 @@ class CustomerCreated(ObjectType, UserBase):
)
-class CustomerUpdated(ObjectType, UserBase):
+class CustomerUpdated(SubscriptionObjectType, UserBase):
class Meta:
+ root_type = "User"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when customer user is updated." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class CustomerMetadataUpdated(ObjectType, UserBase):
+class CustomerMetadataUpdated(SubscriptionObjectType, UserBase):
class Meta:
+ root_type = "User"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when customer user metadata is updated."
@@ -949,32 +1079,40 @@ class CollectionBase(AbstractType):
return ChannelContext(node=collection, channel_slug=channel)
-class CollectionCreated(ObjectType, CollectionBase):
+class CollectionCreated(SubscriptionObjectType, CollectionBase):
class Meta:
+ root_type = "Collection"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new collection is created." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class CollectionUpdated(ObjectType, CollectionBase):
+class CollectionUpdated(SubscriptionObjectType, CollectionBase):
class Meta:
+ root_type = "Collection"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when collection is updated." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class CollectionDeleted(ObjectType, CollectionBase):
+class CollectionDeleted(SubscriptionObjectType, CollectionBase):
class Meta:
+ root_type = "Collection"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when collection is deleted." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class CollectionMetadataUpdated(ObjectType, CollectionBase):
+class CollectionMetadataUpdated(SubscriptionObjectType, CollectionBase):
class Meta:
+ root_type = "Collection"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when collection metadata is updated."
@@ -995,24 +1133,30 @@ class CheckoutBase(AbstractType):
return checkout
-class CheckoutCreated(ObjectType, CheckoutBase):
+class CheckoutCreated(SubscriptionObjectType, CheckoutBase):
class Meta:
+ root_type = "Checkout"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new checkout is created." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class CheckoutUpdated(ObjectType, CheckoutBase):
+class CheckoutUpdated(SubscriptionObjectType, CheckoutBase):
class Meta:
+ root_type = "Checkout"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when checkout is updated." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class CheckoutMetadataUpdated(ObjectType, CheckoutBase):
+class CheckoutMetadataUpdated(SubscriptionObjectType, CheckoutBase):
class Meta:
+ root_type = "Checkout"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when checkout metadata is updated."
@@ -1032,22 +1176,28 @@ class PageBase(AbstractType):
return page
-class PageCreated(ObjectType, PageBase):
+class PageCreated(SubscriptionObjectType, PageBase):
class Meta:
+ root_type = "Page"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new page is created." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class PageUpdated(ObjectType, PageBase):
+class PageUpdated(SubscriptionObjectType, PageBase):
class Meta:
+ root_type = "Page"
+ enable_dry_run = True
interfaces = (Event,)
description = "Event sent when page is updated." + ADDED_IN_32 + PREVIEW_FEATURE
-class PageDeleted(ObjectType, PageBase):
+class PageDeleted(SubscriptionObjectType, PageBase):
class Meta:
+ root_type = "Page"
+ enable_dry_run = True
interfaces = (Event,)
description = "Event sent when page is deleted." + ADDED_IN_32 + PREVIEW_FEATURE
@@ -1064,24 +1214,30 @@ class PageTypeBase(AbstractType):
return page_type
-class PageTypeCreated(ObjectType, PageTypeBase):
+class PageTypeCreated(SubscriptionObjectType, PageTypeBase):
class Meta:
+ root_type = "PageType"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new page type is created." + ADDED_IN_35 + PREVIEW_FEATURE
)
-class PageTypeUpdated(ObjectType, PageTypeBase):
+class PageTypeUpdated(SubscriptionObjectType, PageTypeBase):
class Meta:
+ root_type = "PageType"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when page type is updated." + ADDED_IN_35 + PREVIEW_FEATURE
)
-class PageTypeDeleted(ObjectType, PageTypeBase):
+class PageTypeDeleted(SubscriptionObjectType, PageTypeBase):
class Meta:
+ root_type = "PageType"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when page type is deleted." + ADDED_IN_35 + PREVIEW_FEATURE
@@ -1100,8 +1256,10 @@ class PermissionGroupBase(AbstractType):
return permission_group
-class PermissionGroupCreated(ObjectType, PermissionGroupBase):
+class PermissionGroupCreated(SubscriptionObjectType, PermissionGroupBase):
class Meta:
+ root_type = "Group"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new permission group is created."
@@ -1110,8 +1268,10 @@ class PermissionGroupCreated(ObjectType, PermissionGroupBase):
)
-class PermissionGroupUpdated(ObjectType, PermissionGroupBase):
+class PermissionGroupUpdated(SubscriptionObjectType, PermissionGroupBase):
class Meta:
+ root_type = "Group"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when permission group is updated."
@@ -1120,8 +1280,10 @@ class PermissionGroupUpdated(ObjectType, PermissionGroupBase):
)
-class PermissionGroupDeleted(ObjectType, PermissionGroupBase):
+class PermissionGroupDeleted(SubscriptionObjectType, PermissionGroupBase):
class Meta:
+ root_type = "Group"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when permission group is deleted."
@@ -1157,8 +1319,10 @@ class ShippingPriceBase(AbstractType):
return ChannelContext(node=shipping_method.shipping_zone, channel_slug=channel)
-class ShippingPriceCreated(ObjectType, ShippingPriceBase):
+class ShippingPriceCreated(SubscriptionObjectType, ShippingPriceBase):
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = (
"Event sent when new shipping price is created."
@@ -1167,16 +1331,20 @@ class ShippingPriceCreated(ObjectType, ShippingPriceBase):
)
-class ShippingPriceUpdated(ObjectType, ShippingPriceBase):
+class ShippingPriceUpdated(SubscriptionObjectType, ShippingPriceBase):
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = (
"Event sent when shipping price is updated." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class ShippingPriceDeleted(ObjectType, ShippingPriceBase):
+class ShippingPriceDeleted(SubscriptionObjectType, ShippingPriceBase):
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = (
"Event sent when shipping price is deleted." + ADDED_IN_32 + PREVIEW_FEATURE
@@ -1198,8 +1366,10 @@ class ShippingZoneBase(AbstractType):
return ChannelContext(node=shipping_zone, channel_slug=channel)
-class ShippingZoneCreated(ObjectType, ShippingZoneBase):
+class ShippingZoneCreated(SubscriptionObjectType, ShippingZoneBase):
class Meta:
+ root_type = "ShippingZone"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new shipping zone is created."
@@ -1208,24 +1378,30 @@ class ShippingZoneCreated(ObjectType, ShippingZoneBase):
)
-class ShippingZoneUpdated(ObjectType, ShippingZoneBase):
+class ShippingZoneUpdated(SubscriptionObjectType, ShippingZoneBase):
class Meta:
+ root_type = "ShippingZone"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when shipping zone is updated." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class ShippingZoneDeleted(ObjectType, ShippingZoneBase):
+class ShippingZoneDeleted(SubscriptionObjectType, ShippingZoneBase):
class Meta:
+ root_type = "ShippingZone"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when shipping zone is deleted." + ADDED_IN_32 + PREVIEW_FEATURE
)
-class ShippingZoneMetadataUpdated(ObjectType, ShippingZoneBase):
+class ShippingZoneMetadataUpdated(SubscriptionObjectType, ShippingZoneBase):
class Meta:
+ root_type = "ShippingZone"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when shipping zone metadata is updated."
@@ -1234,31 +1410,37 @@ class ShippingZoneMetadataUpdated(ObjectType, ShippingZoneBase):
)
-class StaffCreated(ObjectType, UserBase):
+class StaffCreated(SubscriptionObjectType, UserBase):
class Meta:
+ root_type = "User"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new staff user is created." + ADDED_IN_35 + PREVIEW_FEATURE
)
-class StaffUpdated(ObjectType, UserBase):
+class StaffUpdated(SubscriptionObjectType, UserBase):
class Meta:
+ root_type = "User"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when staff user is updated." + ADDED_IN_35 + PREVIEW_FEATURE
)
-class StaffDeleted(ObjectType, UserBase):
+class StaffDeleted(SubscriptionObjectType, UserBase):
class Meta:
+ root_type = "User"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when staff user is deleted." + ADDED_IN_35 + PREVIEW_FEATURE
)
-class TransactionAction(ObjectType, AbstractType):
+class TransactionAction(SubscriptionObjectType, AbstractType):
action_type = graphene.Field(
TransactionActionEnum,
required=True,
@@ -1275,7 +1457,7 @@ class TransactionAction(ObjectType, AbstractType):
return None
-class TransactionActionRequest(ObjectType):
+class TransactionActionRequest(SubscriptionObjectType):
transaction = graphene.Field(
TransactionItem,
description="Look up a transaction." + ADDED_IN_34 + PREVIEW_FEATURE,
@@ -1287,6 +1469,8 @@ class TransactionActionRequest(ObjectType):
)
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = (
"Event sent when transaction action is requested."
@@ -1307,13 +1491,15 @@ class TransactionActionRequest(ObjectType):
return transaction_action_data
-class TransactionItemMetadataUpdated(ObjectType):
+class TransactionItemMetadataUpdated(SubscriptionObjectType):
transaction = graphene.Field(
TransactionItem,
description="Look up a transaction." + PREVIEW_FEATURE,
)
class Meta:
+ root_type = "TransactionItem"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when transaction item metadata is updated."
@@ -1351,8 +1537,10 @@ class TranslationBase(AbstractType):
return translation
-class TranslationCreated(ObjectType, TranslationBase):
+class TranslationCreated(SubscriptionObjectType, TranslationBase):
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = (
"Event sent when new translation is created."
@@ -1361,8 +1549,10 @@ class TranslationCreated(ObjectType, TranslationBase):
)
-class TranslationUpdated(ObjectType, TranslationBase):
+class TranslationUpdated(SubscriptionObjectType, TranslationBase):
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = (
"Event sent when translation is updated." + ADDED_IN_32 + PREVIEW_FEATURE
@@ -1384,32 +1574,40 @@ class VoucherBase(AbstractType):
return ChannelContext(node=voucher, channel_slug=None)
-class VoucherCreated(ObjectType, VoucherBase):
+class VoucherCreated(SubscriptionObjectType, VoucherBase):
class Meta:
+ root_type = "Voucher"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new voucher is created." + ADDED_IN_34 + PREVIEW_FEATURE
)
-class VoucherUpdated(ObjectType, VoucherBase):
+class VoucherUpdated(SubscriptionObjectType, VoucherBase):
class Meta:
+ root_type = "Voucher"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when voucher is updated." + ADDED_IN_34 + PREVIEW_FEATURE
)
-class VoucherDeleted(ObjectType, VoucherBase):
+class VoucherDeleted(SubscriptionObjectType, VoucherBase):
class Meta:
+ root_type = "Voucher"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when voucher is deleted." + ADDED_IN_34 + PREVIEW_FEATURE
)
-class VoucherMetadataUpdated(ObjectType, VoucherBase):
+class VoucherMetadataUpdated(SubscriptionObjectType, VoucherBase):
class Meta:
+ root_type = "Voucher"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when voucher metadata is updated."
@@ -1418,18 +1616,6 @@ class VoucherMetadataUpdated(ObjectType, VoucherBase):
)
-class WarehouseBase(AbstractType):
- warehouse = graphene.Field(
- "saleor.graphql.warehouse.types.Warehouse",
- description="The warehouse the event relates to.",
- )
-
- @staticmethod
- def resolve_warehouse(root, _info: ResolveInfo):
- _, warehouse = root
- return warehouse
-
-
class PaymentBase(AbstractType):
payment = graphene.Field(
"saleor.graphql.payment.types.Payment",
@@ -1442,49 +1628,63 @@ class PaymentBase(AbstractType):
return payment
-class PaymentAuthorize(ObjectType, PaymentBase):
+class PaymentAuthorize(SubscriptionObjectType, PaymentBase):
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = "Authorize payment." + ADDED_IN_36 + PREVIEW_FEATURE
-class PaymentCaptureEvent(ObjectType, PaymentBase):
+class PaymentCaptureEvent(SubscriptionObjectType, PaymentBase):
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = "Capture payment." + ADDED_IN_36 + PREVIEW_FEATURE
-class PaymentRefundEvent(ObjectType, PaymentBase):
+class PaymentRefundEvent(SubscriptionObjectType, PaymentBase):
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = "Refund payment." + ADDED_IN_36 + PREVIEW_FEATURE
-class PaymentVoidEvent(ObjectType, PaymentBase):
+class PaymentVoidEvent(SubscriptionObjectType, PaymentBase):
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = "Void payment." + ADDED_IN_36 + PREVIEW_FEATURE
-class PaymentConfirmEvent(ObjectType, PaymentBase):
+class PaymentConfirmEvent(SubscriptionObjectType, PaymentBase):
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = "Confirm payment." + ADDED_IN_36 + PREVIEW_FEATURE
-class PaymentProcessEvent(ObjectType, PaymentBase):
+class PaymentProcessEvent(SubscriptionObjectType, PaymentBase):
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = "Process payment." + ADDED_IN_36 + PREVIEW_FEATURE
-class PaymentListGateways(ObjectType, CheckoutBase):
+class PaymentListGateways(SubscriptionObjectType, CheckoutBase):
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = "List payment gateways." + ADDED_IN_36 + PREVIEW_FEATURE
-class ShippingListMethodsForCheckout(ObjectType, CheckoutBase):
+class ShippingListMethodsForCheckout(SubscriptionObjectType, CheckoutBase):
shipping_methods = NonNullList(
ShippingMethod,
description="Shipping methods that can be used with this checkout."
@@ -1499,18 +1699,22 @@ class ShippingListMethodsForCheckout(ObjectType, CheckoutBase):
return resolve_shipping_methods_for_checkout(info, checkout, manager)
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = (
"List shipping methods for checkout." + ADDED_IN_36 + PREVIEW_FEATURE
)
-class CalculateTaxes(ObjectType):
+class CalculateTaxes(SubscriptionObjectType):
tax_base = graphene.Field(
"saleor.graphql.core.types.taxes.TaxableObject", required=True
)
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = (
"Synchronous webhook for calculating checkout/order taxes."
@@ -1523,7 +1727,7 @@ class CalculateTaxes(ObjectType):
return tax_base
-class CheckoutFilterShippingMethods(ObjectType, CheckoutBase):
+class CheckoutFilterShippingMethods(SubscriptionObjectType, CheckoutBase):
shipping_methods = NonNullList(
ShippingMethod,
description="Shipping methods that can be used with this checkout."
@@ -1538,13 +1742,15 @@ class CheckoutFilterShippingMethods(ObjectType, CheckoutBase):
return resolve_shipping_methods_for_checkout(info, checkout, manager)
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = (
"Filter shipping methods for checkout." + ADDED_IN_36 + PREVIEW_FEATURE
)
-class OrderFilterShippingMethods(ObjectType, OrderBase):
+class OrderFilterShippingMethods(SubscriptionObjectType, OrderBase):
shipping_methods = NonNullList(
ShippingMethod,
description="Shipping methods that can be used with this checkout."
@@ -1569,38 +1775,60 @@ class OrderFilterShippingMethods(ObjectType, OrderBase):
return ChannelByIdLoader(info.context).load(order.channel_id).then(with_channel)
class Meta:
+ root_type = None
+ enable_dry_run = False
interfaces = (Event,)
description = (
"Filter shipping methods for order." + ADDED_IN_36 + PREVIEW_FEATURE
)
-class WarehouseCreated(ObjectType, WarehouseBase):
+class WarehouseBase(AbstractType):
+ warehouse = graphene.Field(
+ "saleor.graphql.warehouse.types.Warehouse",
+ description="The warehouse the event relates to.",
+ )
+
+ @staticmethod
+ def resolve_warehouse(root, _info: ResolveInfo):
+ _, warehouse = root
+ return warehouse
+
+
+class WarehouseCreated(SubscriptionObjectType, WarehouseBase):
class Meta:
+ root_type = "Warehouse"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when new warehouse is created." + ADDED_IN_34 + PREVIEW_FEATURE
)
-class WarehouseUpdated(ObjectType, WarehouseBase):
+class WarehouseUpdated(SubscriptionObjectType, WarehouseBase):
class Meta:
+ root_type = "Warehouse"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when warehouse is updated." + ADDED_IN_34 + PREVIEW_FEATURE
)
-class WarehouseDeleted(ObjectType, WarehouseBase):
+class WarehouseDeleted(SubscriptionObjectType, WarehouseBase):
class Meta:
+ root_type = "Warehouse"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when warehouse is deleted." + ADDED_IN_34 + PREVIEW_FEATURE
)
-class WarehouseMetadataUpdated(ObjectType, WarehouseBase):
+class WarehouseMetadataUpdated(SubscriptionObjectType, WarehouseBase):
class Meta:
+ root_type = "Warehouse"
+ enable_dry_run = True
interfaces = (Event,)
description = (
"Event sent when warehouse metadata is updated."
@@ -1609,7 +1837,7 @@ class WarehouseMetadataUpdated(ObjectType, WarehouseBase):
)
-class Subscription(ObjectType):
+class Subscription(SubscriptionObjectType):
event = graphene.Field(
Event,
description="Look up subscription event." + ADDED_IN_32 + PREVIEW_FEATURE,
diff --git a/saleor/graphql/webhook/tests/mutations/test_webhook_dry_run.py b/saleor/graphql/webhook/tests/mutations/test_webhook_dry_run.py
new file mode 100644
index 0000000000..6a8b00b19b
--- /dev/null
+++ b/saleor/graphql/webhook/tests/mutations/test_webhook_dry_run.py
@@ -0,0 +1,591 @@
+import json
+import uuid
+
+import graphene
+import pytest
+
+from .....graphql.tests.utils import get_graphql_content
+from .....webhook.error_codes import WebhookDryRunErrorCode
+from .....webhook.event_types import WebhookEventAsyncType
+from ...subscription_types import WEBHOOK_TYPES_MAP
+
+WEBHOOK_DRY_RUN_MUTATION = """
+ mutation webhookDryRun($query: String!, $objectId: ID!) {
+ webhookDryRun(query: $query, objectId: $objectId) {
+ errors {
+ field
+ code
+ message
+ }
+ payload
+ }
+ }
+ """
+
+
+def test_webhook_dry_run(
+ staff_api_client,
+ permission_manage_orders,
+ order,
+ subscription_order_created_webhook,
+):
+ # given
+ query = WEBHOOK_DRY_RUN_MUTATION
+ staff_api_client.user.user_permissions.add(permission_manage_orders)
+ order_id = graphene.Node.to_global_id("Order", order.id)
+ webhook = subscription_order_created_webhook
+
+ variables = {"objectId": order_id, "query": webhook.subscription_query}
+
+ # when
+ response = staff_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+
+ # then
+ data = content["data"]["webhookDryRun"]
+ payload = json.loads(data["payload"])
+ assert payload["order"]["id"] == order_id
+
+
+def test_webhook_dry_run_missing_user_permission(
+ staff_api_client,
+ order,
+ subscription_order_created_webhook,
+):
+ # given
+ query = WEBHOOK_DRY_RUN_MUTATION
+ order_id = graphene.Node.to_global_id("Order", order.id)
+ webhook = subscription_order_created_webhook
+
+ variables = {"objectId": order_id, "query": webhook.subscription_query}
+
+ # when
+ response = staff_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+
+ # then
+ error = content["data"]["webhookDryRun"]["errors"][0]
+ assert not error["field"]
+ assert error["code"] == WebhookDryRunErrorCode.MISSING_PERMISSION.name
+ assert (
+ error["message"] == "The user doesn't have required permission: manage_orders."
+ )
+
+
+def test_webhook_dry_run_non_existing_id(
+ staff_api_client,
+ permission_manage_orders,
+ order,
+ subscription_order_created_webhook,
+):
+ # given
+ query = WEBHOOK_DRY_RUN_MUTATION
+ staff_api_client.user.user_permissions.add(permission_manage_orders)
+ order_id = graphene.Node.to_global_id("Order", uuid.uuid4())
+ webhook = subscription_order_created_webhook
+
+ variables = {"objectId": order_id, "query": webhook.subscription_query}
+
+ # when
+ response = staff_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+
+ # then
+ error = content["data"]["webhookDryRun"]["errors"][0]
+ assert error["field"] == "objectId"
+ assert error["code"] == WebhookDryRunErrorCode.NOT_FOUND.name
+ assert error["message"] == f"Couldn't resolve to a node: {order_id}"
+
+
+def test_webhook_dry_run_wrong_subscription_query(
+ staff_api_client,
+ permission_manage_orders,
+ order,
+ subscription_order_created_webhook,
+):
+ # given
+ query = WEBHOOK_DRY_RUN_MUTATION
+ staff_api_client.user.user_permissions.add(permission_manage_orders)
+ order_id = graphene.Node.to_global_id("Order", order.id)
+ webhook = subscription_order_created_webhook
+ subscription = webhook.subscription_query.replace("subscription", "whatever")
+
+ variables = {"objectId": order_id, "query": subscription}
+
+ # when
+ response = staff_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+
+ # then
+ error = content["data"]["webhookDryRun"]["errors"][0]
+ assert error["field"] == "query"
+ assert error["code"] == WebhookDryRunErrorCode.UNABLE_TO_PARSE.name
+ assert error["message"] == "Can't parse an event type from query."
+
+
+def test_webhook_dry_run_event_type_doesnt_exist(
+ staff_api_client,
+ permission_manage_orders,
+ order,
+ subscription_order_created_webhook,
+):
+ # given
+ query = WEBHOOK_DRY_RUN_MUTATION
+ staff_api_client.user.user_permissions.add(permission_manage_orders)
+ order_id = graphene.Node.to_global_id("Order", order.id)
+ webhook = subscription_order_created_webhook
+ subscription = webhook.subscription_query.replace("OrderCreated", "UndefinedEvent")
+
+ variables = {"objectId": order_id, "query": subscription}
+
+ # when
+ response = staff_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+
+ # then
+ error = content["data"]["webhookDryRun"]["errors"][0]
+ assert error["field"] == "query"
+ assert error["code"] == WebhookDryRunErrorCode.GRAPHQL_ERROR.name
+ assert (
+ error["message"]
+ == "Event type: UndefinedEvent is not defined in graphql schema."
+ )
+
+
+def test_webhook_dry_run_object_id_does_not_match_event(
+ staff_api_client,
+ permission_manage_orders,
+ product,
+ subscription_order_created_webhook,
+):
+ # given
+ query = WEBHOOK_DRY_RUN_MUTATION
+ staff_api_client.user.user_permissions.add(permission_manage_orders)
+ product_id = graphene.Node.to_global_id("Product", product.id)
+ webhook = subscription_order_created_webhook
+
+ variables = {"objectId": product_id, "query": webhook.subscription_query}
+
+ # when
+ response = staff_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+
+ # then
+ error = content["data"]["webhookDryRun"]["errors"][0]
+ assert error["field"] == "objectId"
+ assert error["code"] == WebhookDryRunErrorCode.INVALID_ID.name
+ assert error["message"] == "ObjectId doesn't match event type."
+
+
+def test_webhook_dry_run_event_type_not_supported(
+ staff_api_client,
+ permission_manage_orders,
+ product,
+ subscription_payment_authorize_webhook,
+):
+ # given
+ query = WEBHOOK_DRY_RUN_MUTATION
+ staff_api_client.user.user_permissions.add(permission_manage_orders)
+ product_id = graphene.Node.to_global_id("Product", product.id)
+ webhook = subscription_payment_authorize_webhook
+
+ variables = {"objectId": product_id, "query": webhook.subscription_query}
+
+ # when
+ response = staff_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+
+ # then
+ error = content["data"]["webhookDryRun"]["errors"][0]
+ assert error["field"] == "query"
+ assert error["code"] == WebhookDryRunErrorCode.TYPE_NOT_SUPPORTED.name
+ assert error["message"] == "Event type: PaymentAuthorize not supported."
+
+
+def async_subscription_webhooks_with_root_objects(
+ subscription_address_created_webhook,
+ subscription_address_updated_webhook,
+ subscription_address_deleted_webhook,
+ subscription_app_installed_webhook,
+ subscription_app_updated_webhook,
+ subscription_app_deleted_webhook,
+ subscription_app_status_changed_webhook,
+ subscription_attribute_created_webhook,
+ subscription_attribute_updated_webhook,
+ subscription_attribute_deleted_webhook,
+ subscription_attribute_value_created_webhook,
+ subscription_attribute_value_updated_webhook,
+ subscription_attribute_value_deleted_webhook,
+ subscription_category_created_webhook,
+ subscription_category_updated_webhook,
+ subscription_category_deleted_webhook,
+ subscription_channel_created_webhook,
+ subscription_channel_updated_webhook,
+ subscription_channel_deleted_webhook,
+ subscription_channel_status_changed_webhook,
+ subscription_gift_card_created_webhook,
+ subscription_gift_card_updated_webhook,
+ subscription_gift_card_deleted_webhook,
+ subscription_gift_card_status_changed_webhook,
+ subscription_gift_card_metadata_updated_webhook,
+ subscription_menu_created_webhook,
+ subscription_menu_updated_webhook,
+ subscription_menu_deleted_webhook,
+ subscription_menu_item_created_webhook,
+ subscription_menu_item_updated_webhook,
+ subscription_menu_item_deleted_webhook,
+ subscription_shipping_price_created_webhook,
+ subscription_shipping_price_updated_webhook,
+ subscription_shipping_price_deleted_webhook,
+ subscription_shipping_zone_created_webhook,
+ subscription_shipping_zone_updated_webhook,
+ subscription_shipping_zone_deleted_webhook,
+ subscription_shipping_zone_metadata_updated_webhook,
+ subscription_product_updated_webhook,
+ subscription_product_created_webhook,
+ subscription_product_deleted_webhook,
+ subscription_product_metadata_updated_webhook,
+ subscription_product_variant_created_webhook,
+ subscription_product_variant_updated_webhook,
+ subscription_product_variant_deleted_webhook,
+ subscription_product_variant_metadata_updated_webhook,
+ subscription_product_variant_out_of_stock_webhook,
+ subscription_product_variant_back_in_stock_webhook,
+ subscription_order_created_webhook,
+ subscription_order_updated_webhook,
+ subscription_order_confirmed_webhook,
+ subscription_order_fully_paid_webhook,
+ subscription_order_cancelled_webhook,
+ subscription_order_fulfilled_webhook,
+ subscription_order_metadata_updated_webhook,
+ subscription_draft_order_created_webhook,
+ subscription_draft_order_updated_webhook,
+ subscription_draft_order_deleted_webhook,
+ subscription_sale_created_webhook,
+ subscription_sale_updated_webhook,
+ subscription_sale_deleted_webhook,
+ subscription_sale_toggle_webhook,
+ subscription_invoice_requested_webhook,
+ subscription_invoice_deleted_webhook,
+ subscription_invoice_sent_webhook,
+ subscription_fulfillment_created_webhook,
+ subscription_fulfillment_canceled_webhook,
+ subscription_fulfillment_approved_webhook,
+ subscription_fulfillment_metadata_updated_webhook,
+ subscription_customer_created_webhook,
+ subscription_customer_updated_webhook,
+ subscription_customer_deleted_webhook,
+ subscription_customer_metadata_updated_webhook,
+ subscription_collection_created_webhook,
+ subscription_collection_updated_webhook,
+ subscription_collection_deleted_webhook,
+ subscription_collection_metadata_updated_webhook,
+ subscription_checkout_created_webhook,
+ subscription_checkout_updated_webhook,
+ subscription_checkout_metadata_updated_webhook,
+ subscription_page_created_webhook,
+ subscription_page_updated_webhook,
+ subscription_page_deleted_webhook,
+ subscription_page_type_created_webhook,
+ subscription_page_type_updated_webhook,
+ subscription_page_type_deleted_webhook,
+ subscription_permission_group_created_webhook,
+ subscription_permission_group_updated_webhook,
+ subscription_permission_group_deleted_webhook,
+ subscription_product_created_multiple_events_webhook,
+ subscription_staff_created_webhook,
+ subscription_staff_updated_webhook,
+ subscription_staff_deleted_webhook,
+ subscription_transaction_item_metadata_updated_webhook,
+ subscription_translation_created_webhook,
+ subscription_translation_updated_webhook,
+ subscription_warehouse_created_webhook,
+ subscription_warehouse_updated_webhook,
+ subscription_warehouse_deleted_webhook,
+ subscription_warehouse_metadata_updated_webhook,
+ subscription_voucher_created_webhook,
+ subscription_voucher_updated_webhook,
+ subscription_voucher_deleted_webhook,
+ subscription_voucher_webhook_with_meta,
+ subscription_voucher_metadata_updated_webhook,
+ address,
+ app,
+ numeric_attribute,
+ category,
+ channel_PLN,
+ gift_card,
+ menu_item,
+ shipping_method,
+ product,
+ fulfilled_order,
+ sale,
+ fulfillment,
+ stock,
+ customer_user,
+ collection,
+ checkout,
+ page,
+ permission_group_manage_users,
+ shipping_zone,
+ staff_user,
+ voucher,
+ warehouse,
+ translated_attribute,
+ transaction_item,
+):
+ events = WebhookEventAsyncType
+ attr = numeric_attribute
+ attr_value = attr.values.first()
+ menu = menu_item.menu
+ order = fulfilled_order
+ invoice = order.invoices.first()
+ page_type = page.page_type
+
+ return {
+ events.ADDRESS_UPDATED: [subscription_address_updated_webhook, address],
+ events.ADDRESS_CREATED: [subscription_address_created_webhook, address],
+ events.ADDRESS_DELETED: [subscription_address_deleted_webhook, address],
+ events.APP_UPDATED: [subscription_app_updated_webhook, app],
+ events.APP_DELETED: [subscription_app_deleted_webhook, app],
+ events.APP_INSTALLED: [subscription_app_installed_webhook, app],
+ events.APP_STATUS_CHANGED: [subscription_app_status_changed_webhook, app],
+ events.ATTRIBUTE_CREATED: [subscription_attribute_created_webhook, attr],
+ events.ATTRIBUTE_UPDATED: [subscription_attribute_updated_webhook, attr],
+ events.ATTRIBUTE_DELETED: [subscription_attribute_deleted_webhook, attr],
+ events.ATTRIBUTE_VALUE_UPDATED: [
+ subscription_attribute_value_updated_webhook,
+ attr_value,
+ ],
+ events.ATTRIBUTE_VALUE_CREATED: [
+ subscription_attribute_value_created_webhook,
+ attr_value,
+ ],
+ events.ATTRIBUTE_VALUE_DELETED: [
+ subscription_attribute_value_deleted_webhook,
+ attr_value,
+ ],
+ events.CATEGORY_CREATED: [subscription_category_created_webhook, category],
+ events.CATEGORY_UPDATED: [subscription_category_updated_webhook, category],
+ events.CATEGORY_DELETED: [subscription_category_deleted_webhook, category],
+ events.CHANNEL_CREATED: [subscription_channel_created_webhook, channel_PLN],
+ events.CHANNEL_UPDATED: [subscription_channel_updated_webhook, channel_PLN],
+ events.CHANNEL_DELETED: [subscription_channel_deleted_webhook, channel_PLN],
+ events.CHANNEL_STATUS_CHANGED: [
+ subscription_channel_status_changed_webhook,
+ channel_PLN,
+ ],
+ events.GIFT_CARD_CREATED: [subscription_gift_card_created_webhook, gift_card],
+ events.GIFT_CARD_UPDATED: [subscription_gift_card_updated_webhook, gift_card],
+ events.GIFT_CARD_DELETED: [subscription_gift_card_deleted_webhook, gift_card],
+ events.GIFT_CARD_STATUS_CHANGED: [
+ subscription_gift_card_status_changed_webhook,
+ gift_card,
+ ],
+ events.GIFT_CARD_METADATA_UPDATED: [
+ subscription_gift_card_metadata_updated_webhook,
+ gift_card,
+ ],
+ events.MENU_CREATED: [subscription_menu_created_webhook, menu],
+ events.MENU_UPDATED: [subscription_menu_updated_webhook, menu],
+ events.MENU_DELETED: [subscription_menu_deleted_webhook, menu],
+ events.MENU_ITEM_CREATED: [subscription_menu_item_created_webhook, menu_item],
+ events.MENU_ITEM_UPDATED: [subscription_menu_item_updated_webhook, menu_item],
+ events.MENU_ITEM_DELETED: [subscription_menu_item_deleted_webhook, menu_item],
+ events.ORDER_CREATED: [subscription_order_created_webhook, order],
+ events.ORDER_UPDATED: [subscription_order_updated_webhook, order],
+ events.ORDER_CONFIRMED: [subscription_order_confirmed_webhook, order],
+ events.ORDER_FULLY_PAID: [subscription_order_fully_paid_webhook, order],
+ events.ORDER_FULFILLED: [subscription_order_fulfilled_webhook, order],
+ events.ORDER_CANCELLED: [subscription_order_cancelled_webhook, order],
+ events.ORDER_METADATA_UPDATED: [
+ subscription_order_metadata_updated_webhook,
+ order,
+ ],
+ events.DRAFT_ORDER_CREATED: [subscription_draft_order_created_webhook, order],
+ events.DRAFT_ORDER_UPDATED: [subscription_draft_order_updated_webhook, order],
+ events.DRAFT_ORDER_DELETED: [subscription_draft_order_deleted_webhook, order],
+ events.PRODUCT_CREATED: [subscription_product_created_webhook, product],
+ events.PRODUCT_UPDATED: [subscription_product_updated_webhook, product],
+ events.PRODUCT_DELETED: [subscription_product_deleted_webhook, product],
+ events.PRODUCT_METADATA_UPDATED: [
+ subscription_product_metadata_updated_webhook,
+ product,
+ ],
+ events.PRODUCT_VARIANT_CREATED: [
+ subscription_product_variant_created_webhook,
+ product,
+ ],
+ events.PRODUCT_VARIANT_UPDATED: [
+ subscription_product_variant_updated_webhook,
+ product,
+ ],
+ events.PRODUCT_VARIANT_OUT_OF_STOCK: [
+ subscription_product_variant_out_of_stock_webhook,
+ stock,
+ ],
+ events.PRODUCT_VARIANT_BACK_IN_STOCK: [
+ subscription_product_variant_back_in_stock_webhook,
+ stock,
+ ],
+ events.PRODUCT_VARIANT_DELETED: [
+ subscription_product_variant_deleted_webhook,
+ product,
+ ],
+ events.PRODUCT_VARIANT_METADATA_UPDATED: [
+ subscription_product_variant_metadata_updated_webhook,
+ product,
+ ],
+ events.SALE_CREATED: [subscription_sale_created_webhook, sale],
+ events.SALE_UPDATED: [subscription_sale_updated_webhook, sale],
+ events.SALE_DELETED: [subscription_sale_deleted_webhook, sale],
+ events.SALE_TOGGLE: [subscription_sale_toggle_webhook, sale],
+ events.INVOICE_REQUESTED: [subscription_invoice_requested_webhook, invoice],
+ events.INVOICE_DELETED: [subscription_invoice_deleted_webhook, invoice],
+ events.INVOICE_SENT: [subscription_invoice_sent_webhook, invoice],
+ events.FULFILLMENT_CREATED: [
+ subscription_fulfillment_created_webhook,
+ fulfillment,
+ ],
+ events.FULFILLMENT_CANCELED: [
+ subscription_fulfillment_canceled_webhook,
+ fulfillment,
+ ],
+ events.FULFILLMENT_APPROVED: [
+ subscription_fulfillment_approved_webhook,
+ fulfillment,
+ ],
+ events.FULFILLMENT_METADATA_UPDATED: [
+ subscription_fulfillment_metadata_updated_webhook,
+ fulfillment,
+ ],
+ events.CUSTOMER_CREATED: [subscription_customer_created_webhook, customer_user],
+ events.CUSTOMER_UPDATED: [subscription_customer_updated_webhook, customer_user],
+ events.CUSTOMER_METADATA_UPDATED: [
+ subscription_customer_metadata_updated_webhook,
+ customer_user,
+ ],
+ events.COLLECTION_CREATED: [
+ subscription_collection_created_webhook,
+ collection,
+ ],
+ events.COLLECTION_UPDATED: [
+ subscription_collection_updated_webhook,
+ collection,
+ ],
+ events.COLLECTION_DELETED: [
+ subscription_collection_deleted_webhook,
+ collection,
+ ],
+ events.COLLECTION_METADATA_UPDATED: [
+ subscription_collection_metadata_updated_webhook,
+ collection,
+ ],
+ events.CHECKOUT_CREATED: [subscription_checkout_created_webhook, checkout],
+ events.CHECKOUT_UPDATED: [subscription_checkout_updated_webhook, checkout],
+ events.CHECKOUT_METADATA_UPDATED: [
+ subscription_checkout_metadata_updated_webhook,
+ checkout,
+ ],
+ events.PAGE_CREATED: [subscription_page_created_webhook, page],
+ events.PAGE_UPDATED: [subscription_page_updated_webhook, page],
+ events.PAGE_DELETED: [subscription_page_deleted_webhook, page],
+ events.PAGE_TYPE_CREATED: [subscription_page_type_created_webhook, page_type],
+ events.PAGE_TYPE_UPDATED: [subscription_page_type_updated_webhook, page_type],
+ events.PAGE_TYPE_DELETED: [subscription_page_type_deleted_webhook, page_type],
+ events.PERMISSION_GROUP_CREATED: [
+ subscription_permission_group_created_webhook,
+ permission_group_manage_users,
+ ],
+ events.PERMISSION_GROUP_UPDATED: [
+ subscription_permission_group_updated_webhook,
+ permission_group_manage_users,
+ ],
+ events.PERMISSION_GROUP_DELETED: [
+ subscription_permission_group_deleted_webhook,
+ permission_group_manage_users,
+ ],
+ events.SHIPPING_PRICE_CREATED: [
+ subscription_shipping_price_created_webhook,
+ shipping_method,
+ ],
+ events.SHIPPING_PRICE_UPDATED: [
+ subscription_shipping_price_updated_webhook,
+ shipping_method,
+ ],
+ events.SHIPPING_PRICE_DELETED: [
+ subscription_shipping_price_deleted_webhook,
+ shipping_method,
+ ],
+ events.SHIPPING_ZONE_CREATED: [
+ subscription_shipping_zone_created_webhook,
+ shipping_zone,
+ ],
+ events.SHIPPING_ZONE_UPDATED: [
+ subscription_shipping_zone_updated_webhook,
+ shipping_zone,
+ ],
+ events.SHIPPING_ZONE_DELETED: [
+ subscription_shipping_zone_deleted_webhook,
+ shipping_zone,
+ ],
+ events.SHIPPING_ZONE_METADATA_UPDATED: [
+ subscription_shipping_zone_metadata_updated_webhook,
+ shipping_zone,
+ ],
+ events.STAFF_CREATED: [subscription_staff_created_webhook, staff_user],
+ events.STAFF_UPDATED: [subscription_staff_updated_webhook, staff_user],
+ events.STAFF_DELETED: [subscription_staff_deleted_webhook, staff_user],
+ events.TRANSACTION_ITEM_METADATA_UPDATED: [
+ subscription_transaction_item_metadata_updated_webhook,
+ transaction_item,
+ ],
+ events.TRANSLATION_CREATED: [
+ subscription_translation_created_webhook,
+ translated_attribute,
+ ],
+ events.TRANSLATION_UPDATED: [
+ subscription_translation_updated_webhook,
+ translated_attribute,
+ ],
+ events.VOUCHER_CREATED: [subscription_voucher_created_webhook, voucher],
+ events.VOUCHER_UPDATED: [subscription_voucher_updated_webhook, voucher],
+ events.VOUCHER_DELETED: [subscription_voucher_deleted_webhook, voucher],
+ events.VOUCHER_METADATA_UPDATED: [
+ subscription_voucher_metadata_updated_webhook,
+ voucher,
+ ],
+ events.WAREHOUSE_CREATED: [subscription_warehouse_created_webhook, warehouse],
+ events.WAREHOUSE_UPDATED: [subscription_warehouse_updated_webhook, warehouse],
+ events.WAREHOUSE_DELETED: [subscription_warehouse_deleted_webhook, warehouse],
+ events.WAREHOUSE_METADATA_UPDATED: [
+ subscription_warehouse_metadata_updated_webhook,
+ warehouse,
+ ],
+ }
+
+
+def test_webhook_dry_run_root_type(
+ superuser_api_client,
+ async_subscription_webhooks_with_root_objects,
+):
+ # given
+ query = WEBHOOK_DRY_RUN_MUTATION
+
+ for event_name, event_type in WEBHOOK_TYPES_MAP.items():
+ if not event_type._meta.enable_dry_run:
+ continue
+
+ webhook = async_subscription_webhooks_with_root_objects[event_name][0]
+ object = async_subscription_webhooks_with_root_objects[event_name][1]
+ object_id = graphene.Node.to_global_id(object.__class__.__name__, object.pk)
+
+ variables = {"objectId": object_id, "query": webhook.subscription_query}
+
+ # when
+ response = superuser_api_client.post_graphql(query, variables)
+ content = get_graphql_content(response)
+
+ # then
+ assert not content["data"]["webhookDryRun"]["errors"]
+ assert content["data"]["webhookDryRun"]["payload"]
diff --git a/saleor/graphql/webhook/tests/test_utils.py b/saleor/graphql/webhook/tests/test_utils.py
new file mode 100644
index 0000000000..55cd65e0b8
--- /dev/null
+++ b/saleor/graphql/webhook/tests/test_utils.py
@@ -0,0 +1,104 @@
+import pytest
+
+from ..utils import get_event_type_from_subscription
+
+
+ "query,event",
+ [
+ (
+ """
+ subscription {
+ event {
+ ...on
+ OrderCreated {
+ order {
+ id
+ }
+ }
+ }
+ }
+ """,
+ "order_created",
+ ),
+ (
+ """
+ fragment OrderFragment on Order {
+ id
+ number
+ lines {
+ id
+ }
+ }
+ subscription {
+ event {
+ ...on OrderCreated {
+ order {
+ ...OrderFragment
+ }
+ }
+ }
+ }
+ """,
+ "order_created",
+ ),
+ (
+ """
+ fragment NotUsedEvents on Event {
+ ... on OrderCreated {
+ order {
+ id
+ }
+ }
+ }
+
+ subscription {
+ event {
+ ... on OrderUpdated {
+ order {
+ id
+ }
+ }
+ }
+ }
+ """,
+ "order_updated",
+ ),
+ (
+ """
+ fragment OrderFragment on Order {
+ order {
+ id
+ }
+ }
+
+ fragment EventFragment on Event {
+ ... on OrderUpdated {
+ ... OrderFragment
+ }
+ }
+
+ subscription {
+ event {
+ ... EventFragment
+ }
+ }
+ """,
+ "order_updated",
+ ),
+ (
+ """
+ mutation SomeMutation {
+ someMutation(input: {}) {
+ result {
+ id
+ }
+ }
+ }
+ """,
+ None,
+ ),
+ ],
+)
+def test_get_event_type_from_subscription(query, event):
+ assert get_event_type_from_subscription(query) == event
diff --git a/saleor/graphql/webhook/utils.py b/saleor/graphql/webhook/utils.py
new file mode 100644
index 0000000000..a8f2e5dc87
--- /dev/null
+++ b/saleor/graphql/webhook/utils.py
@@ -0,0 +1,58 @@
+from typing import Dict, Optional
+
+from graphene.utils.str_converters import to_snake_case
+from graphql import parse, print_ast
+from graphql.error.syntax_error import GraphQLSyntaxError
+from graphql.language.ast import Document
+
+
+def get_event_type_from_subscription(query: str) -> Optional[str]:
+ try:
+ ast = parse(query)
+ subscription = None
+ fragments = get_event_fragments_from_query(ast)
+
+ for definition in ast.definitions:
+ if (
+ hasattr(definition, "operation")
+ and definition.operation == "subscription"
+ ):
+ subscription = definition
+
+ if subscription:
+ subscription_string = print_ast(subscription)
+
+ if fragments:
+ for fragment_name, event_type in fragments.items():
+ if fragment_name in subscription_string:
+ return to_snake_case(event_type)
+
+ event_type = (
+ "".join(subscription_string.split())
+ .split("event{...on")[1]
+ .split("{")[0]
+ )
+ return to_snake_case(event_type)
+ return None
+ except (GraphQLSyntaxError, IndexError):
+ return None
+
+
+def get_event_fragments_from_query(ast: Document) -> Optional[Dict[str, str]]:
+ fragments = {}
+ for definition in ast.definitions:
+ try:
+ if (
+ definition.__class__.__name__ == "FragmentDefinition"
+ and definition.type_condition.name.value == "Event"
+ ):
+ fragment_string = print_ast(definition)
+ event_type = (
+ "".join(fragment_string.split())
+ .split("Event{...on")[1]
+ .split("{")[0]
+ )
+ fragments[definition.name.value] = event_type
+ except IndexError:
+ continue
+ return fragments
diff --git a/saleor/webhook/error_codes.py b/saleor/webhook/error_codes.py
index 82cd8ae91c..8d254e1867 100644
--- a/saleor/webhook/error_codes.py
+++ b/saleor/webhook/error_codes.py
@@ -8,3 +8,12 @@ class WebhookErrorCode(Enum):
REQUIRED = "required"
UNIQUE = "unique"
DELETE_FAILED = "delete_failed"
+
+
+class WebhookDryRunErrorCode(Enum):
+ GRAPHQL_ERROR = "graphql_error"
+ UNABLE_TO_PARSE = "unable_to_parse"
+ NOT_FOUND = "not_found"
+ INVALID_ID = "invalid_id"
+ MISSING_PERMISSION = "missing_permission"
+ TYPE_NOT_SUPPORTED = "type_not_supported"