Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Refator output field of model mutations
fowczrek3ac4208287dd
diff --git a/saleor/graphql/account/mutations/permission_group.py b/saleor/graphql/account/mutations/permission_group.pyindex 6aa93cde48..f3cfb0a13a 100644--- a/saleor/graphql/account/mutations/permission_group.py+++ b/saleor/graphql/account/mutations/permission_group.py@@ -20,7 +20,6 @@ from ...core.enums import PermissionEnumfrom ...core.mutations import ModelDeleteMutation, ModelMutationfrom ...core.types.common import PermissionGroupErrorfrom ...core.utils import get_duplicates_ids-from ..types import Groupif TYPE_CHECKING:from ....account.models import User@@ -44,8 +43,6 @@ class PermissionGroupCreateInput(PermissionGroupInput):class PermissionGroupCreate(ModelMutation):- group = graphene.Field(Group, description="The newly created group.")-class Arguments:input = PermissionGroupCreateInput(description="Input fields to create permission group.", required=True@@ -181,8 +178,6 @@ class PermissionGroupUpdateInput(PermissionGroupInput):class PermissionGroupUpdate(PermissionGroupCreate):- group = graphene.Field(Group, description="Group which was edited.")-class Arguments:id = graphene.ID(description="ID of the group to update.", required=True)input = PermissionGroupUpdateInput(diff --git a/saleor/graphql/core/mutations.py b/saleor/graphql/core/mutations.pyindex 799feb6ed8..5ca2029fb2 100644--- a/saleor/graphql/core/mutations.py+++ b/saleor/graphql/core/mutations.py@@ -36,17 +36,6 @@ def get_model_name(model):return model_name[:1].lower() + model_name[1:]-def get_output_fields(model, return_field_name):- """Return mutation output field for model instance."""- model_type = registry.get_type_for_model(model)- if not model_type:- raise ImproperlyConfigured(- "Unable to find type for model %s in graphene registry" % model.__name__- )- fields = {return_field_name: graphene.Field(model_type)}- return fields--def get_error_fields(error_type_class, error_type_field):return {error_type_field: graphene.Field(@@ -357,12 +346,19 @@ class ModelMutation(BaseMutation):return_field_name = get_model_name(model)if arguments is None:arguments = {}- fields = get_output_fields(model, return_field_name)_meta.model = model_meta.return_field_name = return_field_name_meta.exclude = excludesuper().__init_subclass_with_meta__(_meta=_meta, **options)++ model_type = cls.get_type_for_model()+ if not model_type:+ raise ImproperlyConfigured(+ "Unable to find type for model %s in graphene registry" % model.__name__+ )+ fields = {return_field_name: graphene.Field(model_type)}+cls._update_mutation_arguments_and_fields(arguments=arguments, fields=fields)@classmethoddiff --git a/saleor/graphql/meta/deprecated/mutations.py b/saleor/graphql/meta/deprecated/mutations.pyindex dceb284432..e2a96235a2 100644--- a/saleor/graphql/meta/deprecated/mutations.py+++ b/saleor/graphql/meta/deprecated/mutations.py@@ -3,12 +3,23 @@ import graphenefrom django.core.exceptions import ImproperlyConfiguredfrom graphene_django.registry import get_global_registry-from ...core.mutations import BaseMutation, get_model_name, get_output_fields+from ...core.mutations import BaseMutation, get_model_namefrom .types import MetaInput, MetaPathregistry = get_global_registry()+def get_output_fields(model, return_field_name):+ """Return mutation output field for model instance."""+ model_type = registry.get_type_for_model(model)+ if not model_type:+ raise ImproperlyConfigured(+ "Unable to find type for model %s in graphene registry" % model.__name__+ )+ fields = {return_field_name: graphene.Field(model_type)}+ return fields++class MetaUpdateOptions(graphene.types.mutation.MutationOptions):model = Nonereturn_field_name = Nonediff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphqlindex 0654df5161..a84239edb1 100644--- a/saleor/graphql/schema.graphql+++ b/saleor/graphql/schema.graphql@@ -3176,8 +3176,8 @@ enum PermissionEnum {type PermissionGroupCreate {errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")- group: GrouppermissionGroupErrors: [PermissionGroupError!]!+ group: Group}input PermissionGroupCreateInput {@@ -3226,8 +3226,8 @@ input PermissionGroupSortingInput {type PermissionGroupUpdate {errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")- group: GrouppermissionGroupErrors: [PermissionGroupError!]!+ group: Group}input PermissionGroupUpdateInput {@@ -4337,8 +4337,8 @@ type ShippingZoneCountableEdge {type ShippingZoneCreate {errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")- shippingZone: ShippingZoneshippingErrors: [ShippingError!]!+ shippingZone: ShippingZone}input ShippingZoneCreateInput {@@ -4356,8 +4356,8 @@ type ShippingZoneDelete {type ShippingZoneUpdate {errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")- shippingZone: ShippingZoneshippingErrors: [ShippingError!]!+ shippingZone: ShippingZone}input ShippingZoneUpdateInput {@@ -5126,14 +5126,14 @@ input WarehouseFilterInput {type WarehouseShippingZoneAssign {errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")- warehouse: WarehousewarehouseErrors: [WarehouseError!]!+ warehouse: Warehouse}type WarehouseShippingZoneUnassign {errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")- warehouse: WarehousewarehouseErrors: [WarehouseError!]!+ warehouse: Warehouse}enum WarehouseSortField {@@ -5199,8 +5199,8 @@ input WebhookCreateInput {type WebhookDelete {errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")- webhook: WebhookwebhookErrors: [WebhookError!]!+ webhook: Webhook}type WebhookError {@@ -5266,8 +5266,8 @@ input WebhookSortingInput {type WebhookUpdate {errors: [Error!]! @deprecated(reason: "Use typed errors with error codes. This field will be removed after 2020-07-31.")- webhook: WebhookwebhookErrors: [WebhookError!]!+ webhook: Webhook}input WebhookUpdateInput {diff --git a/saleor/graphql/shipping/mutations.py b/saleor/graphql/shipping/mutations.pyindex 62077503c2..57c2512c16 100644--- a/saleor/graphql/shipping/mutations.py+++ b/saleor/graphql/shipping/mutations.py@@ -122,8 +122,6 @@ class ShippingZoneMixin:class ShippingZoneCreate(ShippingZoneMixin, ModelMutation):- shipping_zone = graphene.Field(ShippingZone, description="Created shipping zone.")-class Arguments:input = ShippingZoneCreateInput(description="Fields required to create a shipping zone.", required=True@@ -138,8 +136,6 @@ class ShippingZoneCreate(ShippingZoneMixin, ModelMutation):class ShippingZoneUpdate(ShippingZoneMixin, ModelMutation):- shipping_zone = graphene.Field(ShippingZone, description="Updated shipping zone.")-class Arguments:id = graphene.ID(description="ID of a shipping zone to update.", required=True)input = ShippingZoneUpdateInput(diff --git a/saleor/graphql/warehouse/mutations.py b/saleor/graphql/warehouse/mutations.pyindex 9324d852cc..e3923b76e9 100644--- a/saleor/graphql/warehouse/mutations.py+++ b/saleor/graphql/warehouse/mutations.py@@ -69,10 +69,6 @@ class WarehouseCreate(WarehouseMixin, ModelMutation, I18nMixin):class WarehouseShippingZoneAssign(WarehouseMixin, ModelMutation, I18nMixin):- warehouse = graphene.Field(- Warehouse, description="A warehouse to add shipping zone."- )-class Meta:model = models.Warehousepermissions = (ProductPermissions.MANAGE_PRODUCTS,)@@ -99,10 +95,6 @@ class WarehouseShippingZoneAssign(WarehouseMixin, ModelMutation, I18nMixin):class WarehouseShippingZoneUnassign(WarehouseMixin, ModelMutation, I18nMixin):- warehouse = graphene.Field(- Warehouse, description="A warehouse to add shipping zone."- )-class Meta:model = models.Warehousepermissions = (ProductPermissions.MANAGE_PRODUCTS,)diff --git a/saleor/graphql/webhook/mutations.py b/saleor/graphql/webhook/mutations.pyindex d34d74029e..51df00fe64 100644--- a/saleor/graphql/webhook/mutations.py+++ b/saleor/graphql/webhook/mutations.py@@ -7,7 +7,6 @@ from ...webhook.error_codes import WebhookErrorCodefrom ..core.mutations import ModelDeleteMutation, ModelMutationfrom ..core.types.common import WebhookErrorfrom .enums import WebhookEventTypeEnum-from .types import Webhookclass WebhookCreateInput(graphene.InputObjectType):@@ -124,8 +123,6 @@ class WebhookUpdateInput(graphene.InputObjectType):class WebhookUpdate(ModelMutation):- webhook = graphene.Field(Webhook)-class Arguments:id = graphene.ID(required=True, description="ID of a webhook to update.")input = WebhookUpdateInput(@@ -164,8 +161,6 @@ class WebhookUpdate(ModelMutation):class WebhookDelete(ModelDeleteMutation):- webhook = graphene.Field(Webhook)-class Arguments:id = graphene.ID(required=True, description="ID of a webhook to delete.")