Skip to content

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

Refator output field of model mutations

fowczrek3ac4208287dd
diff --git a/saleor/graphql/account/mutations/permission_group.py b/saleor/graphql/account/mutations/permission_group.py
index 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 PermissionEnum
from ...core.mutations import ModelDeleteMutation, ModelMutation
from ...core.types.common import PermissionGroupError
from ...core.utils import get_duplicates_ids
-from ..types import Group
if 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.py
index 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 = exclude
super().__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)
@classmethod
diff --git a/saleor/graphql/meta/deprecated/mutations.py b/saleor/graphql/meta/deprecated/mutations.py
index dceb284432..e2a96235a2 100644
--- a/saleor/graphql/meta/deprecated/mutations.py
+++ b/saleor/graphql/meta/deprecated/mutations.py
@@ -3,12 +3,23 @@ import graphene
from django.core.exceptions import ImproperlyConfigured
from 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_name
from .types import MetaInput, MetaPath
registry = 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 = None
return_field_name = None
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 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: Group
permissionGroupErrors: [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: Group
permissionGroupErrors: [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: ShippingZone
shippingErrors: [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: ShippingZone
shippingErrors: [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: Warehouse
warehouseErrors: [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: Warehouse
warehouseErrors: [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: Webhook
webhookErrors: [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: Webhook
webhookErrors: [WebhookError!]!
+ webhook: Webhook
}
input WebhookUpdateInput {
diff --git a/saleor/graphql/shipping/mutations.py b/saleor/graphql/shipping/mutations.py
index 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.py
index 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.Warehouse
permissions = (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.Warehouse
permissions = (ProductPermissions.MANAGE_PRODUCTS,)
diff --git a/saleor/graphql/webhook/mutations.py b/saleor/graphql/webhook/mutations.py
index d34d74029e..51df00fe64 100644
--- a/saleor/graphql/webhook/mutations.py
+++ b/saleor/graphql/webhook/mutations.py
@@ -7,7 +7,6 @@ from ...webhook.error_codes import WebhookErrorCode
from ..core.mutations import ModelDeleteMutation, ModelMutation
from ..core.types.common import WebhookError
from .enums import WebhookEventTypeEnum
-from .types import Webhook
class 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.")