Skip to content

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

Add names to input fields so there is no null field in returned errors

Adam Janikd86a0b83d174
diff --git a/saleor/graphql/account/mutations.py b/saleor/graphql/account/mutations.py
index 6a149fa5ff..155b957c2d 100644
--- a/saleor/graphql/account/mutations.py
+++ b/saleor/graphql/account/mutations.py
@@ -40,11 +40,18 @@ class StaffInput(UserInput):
permissions = graphene.List(
graphene.String,
description='List of permission code names to assign to this user.')
+<<<<<<< HEAD
class StaffCreateInput(StaffInput):
send_password_email = graphene.Boolean(
description='Send an email with a link to set a password')
+=======
+ groups = graphene.List(
+ graphene.ID,
+ description='List of IDs of permission groups to assign the user to.',
+ name='groups')
+>>>>>>> eedc30806... Add names to input fields so there is no null field in returned errors
class CustomerCreate(ModelMutation):
diff --git a/saleor/graphql/core/mutations.py b/saleor/graphql/core/mutations.py
index 00278a63e5..ac48ca801c 100644
--- a/saleor/graphql/core/mutations.py
+++ b/saleor/graphql/core/mutations.py
@@ -124,12 +124,14 @@ class ModelMutation(BaseMutation):
if value is not None and (
isinstance(field.type, graphene.List)) and (
field.type.of_type == graphene.ID):
- instances = get_nodes(value) if value else []
+ instances = cls.get_instances(
+ value, errors=errors, field=field.name) if value else []
cleaned_input[field_name] = instances
# handle ID field
elif value is not None and field.type == graphene.ID:
- instance = get_node(info, value)
+ instance = cls.get_instance(
+ info, value, errors, field=field.name)
cleaned_input[field_name] = instance
# handle uploaded files
@@ -220,6 +222,16 @@ class ModelMutation(BaseMutation):
field=field, message=str(e), errors=errors)
return instance
+ @classmethod
+ def get_instances(cls, ids, errors, graphene_type=None, field='Error'):
+ instances = None
+ try:
+ instances = get_nodes(ids, graphene_type)
+ except Exception as e:
+ cls.add_error(
+ field=field, message=str(e), errors=errors)
+ return instances
+
@classmethod
def mutate(cls, root, info, **data):
diff --git a/saleor/graphql/discount/mutations.py b/saleor/graphql/discount/mutations.py
index a19603fffc..e64a307923 100644
--- a/saleor/graphql/discount/mutations.py
+++ b/saleor/graphql/discount/mutations.py
@@ -34,17 +34,19 @@ class VoucherInput(graphene.InputObjectType):
description='Choices: fixed or percentage.')
discount_value = Decimal(description='Value of the voucher.')
products = graphene.List(
- graphene.ID, description='Products discounted by the voucher.')
+ graphene.ID, description='Products discounted by the voucher.',
+ name='products')
collections = graphene.List(
- graphene.ID, description='Collections discounted by the voucher.')
+ graphene.ID, description='Collections discounted by the voucher.',
+ name='collections')
categories = graphene.List(
- graphene.ID, description='Categories discounted by the voucher.')
+ graphene.ID, description='Categories discounted by the voucher.',
+ name='categories')
min_amount_spent = Decimal(
description='Min purchase amount required to apply the voucher.')
countries = graphene.List(
graphene.String,
- description='Country codes that can be used with '
- 'the shipping voucher')
+ description='Country codes that can be used with the shipping voucher')
class VoucherCreate(ModelMutation):
@@ -102,11 +104,14 @@ class SaleInput(graphene.InputObjectType):
type = DiscountValueTypeEnum(description='Fixed or percentage.')
value = Decimal(description='Value of the voucher.')
products = graphene.List(
- graphene.ID, description='Products related to the discount.')
+ graphene.ID, description='Products related to the discount.',
+ name='products')
categories = graphene.List(
- graphene.ID, description='Categories related to the discount.')
+ graphene.ID, description='Categories related to the discount.',
+ name='categories')
collections = graphene.List(
- graphene.ID, description='Collections related to the discount.')
+ graphene.ID, description='Collections related to the discount.',
+ name='collections')
start_date = graphene.types.datetime.DateTime(
description='Start date of the sale in ISO 8601 format.')
end_date = graphene.types.datetime.DateTime(
diff --git a/saleor/graphql/menu/mutations.py b/saleor/graphql/menu/mutations.py
index 1a2deb6128..36e1762332 100644
--- a/saleor/graphql/menu/mutations.py
+++ b/saleor/graphql/menu/mutations.py
@@ -9,15 +9,21 @@ class MenuInput(graphene.InputObjectType):
class MenuItemInput(graphene.InputObjectType):
- menu = graphene.ID(description='Menu to which item belongs to.')
+ menu = graphene.ID(
+ description='Menu to which item belongs to.', name='menu')
name = graphene.String(description='Name of the menu item.')
- parent = graphene.ID(description='''
+ parent = graphene.ID(
+ description='''
ID of the parent menu. If empty, menu will be top level
- menu.''')
+ menu.''',
+ name='parent')
url = graphene.String(description='URL of the pointed item.')
- category = graphene.ID(description='Category to which item points.')
- collection = graphene.ID(description='Collection to which item points.')
- page = graphene.ID(description='Page to which item points.')
+ category = graphene.ID(
+ description='Category to which item points.', name='category')
+ collection = graphene.ID(
+ description='Collection to which item points.', name='collection')
+ page = graphene.ID(
+ description='Page to which item points.', name='page')
class MenuCreate(ModelMutation):
diff --git a/saleor/graphql/order/mutations/draft_orders.py b/saleor/graphql/order/mutations/draft_orders.py
index 560bfbca29..d4e5ae47ec 100644
--- a/saleor/graphql/order/mutations/draft_orders.py
+++ b/saleor/graphql/order/mutations/draft_orders.py
@@ -30,7 +30,8 @@ class AddressInput(graphene.InputObjectType):
class OrderLineInput(graphene.InputObjectType):
- variant_id = graphene.ID(description='Product variant ID.')
+ variant_id = graphene.ID(
+ description='Product variant ID.', name='variantId')
quantity = graphene.Int(
description='Number of variant items ordered.')
@@ -39,7 +40,7 @@ class DraftOrderInput(InputObjectType):
billing_address = AddressInput(
description='Billing address of the customer.')
user = graphene.ID(
- descripton='Customer associated with the draft order.')
+ descripton='Customer associated with the draft order.', name='user')
user_email = graphene.String(description='Email address of the customer.')
discount = Decimal(description='Discount amount for the order.')
lines = graphene.List(
@@ -49,9 +50,10 @@ class DraftOrderInput(InputObjectType):
shipping_address = AddressInput(
description='Shipping address of the customer.')
shipping_method = graphene.ID(
- description='ID of a selected shipping method.')
+ description='ID of a selected shipping method.', name='shippingMethod')
voucher = graphene.ID(
- description='ID of the voucher associated with the order')
+ description='ID of the voucher associated with the order',
+ name='voucher')
def check_lines_quantity(variants, quantities):
@@ -91,7 +93,9 @@ class DraftOrderCreate(ModelMutation):
lines = input.pop('lines', None)
if lines:
variant_ids = [line.get('variant_id') for line in lines]
- variants = get_nodes(ids=variant_ids, graphene_type=ProductVariant)
+ variants = cls.get_instances(
+ ids=variant_ids, graphene_type=ProductVariant, errors=errors,
+ field='variants')
quantities = [line.get('quantity') for line in lines]
line_errors = check_lines_quantity(variants, quantities)
if line_errors:
diff --git a/saleor/graphql/order/mutations/fulfillments.py b/saleor/graphql/order/mutations/fulfillments.py
index fcfeef2043..2fbf50be9a 100644
--- a/saleor/graphql/order/mutations/fulfillments.py
+++ b/saleor/graphql/order/mutations/fulfillments.py
@@ -29,13 +29,15 @@ def clean_lines_quantities(order_lines, quantities):
class FulfillmentLineInput(graphene.InputObjectType):
- order_line_id = graphene.ID(description='The ID of the order line.')
+ order_line_id = graphene.ID(
+ description='The ID of the order line.', name='orderLineId')
quantity = graphene.Int(
description='The number of line item(s) to be fulfiled.')
class FulfillmentCreateInput(graphene.InputObjectType):
- order = graphene.ID(description='ID of the order to be fulfilled.')
+ order = graphene.ID(
+ description='ID of the order to be fulfilled.', name='order')
tracking_number = graphene.String(
description='Fulfillment tracking number')
notify_customer = graphene.Boolean(
diff --git a/saleor/graphql/order/mutations/orders.py b/saleor/graphql/order/mutations/orders.py
index 5642b7152a..9631f5571d 100644
--- a/saleor/graphql/order/mutations/orders.py
+++ b/saleor/graphql/order/mutations/orders.py
@@ -66,8 +66,9 @@ class OrderUpdate(DraftOrderUpdate):
class OrderAddNoteInput(graphene.InputObjectType):
- order = graphene.ID(description='ID of the order.')
- user = graphene.ID(description='ID of the user who added note.')
+ order = graphene.ID(description='ID of the order.', name='order')
+ user = graphene.ID(
+ description='ID of the user who added note.', name='user')
content = graphene.String(description='Note content.')
diff --git a/saleor/graphql/product/mutations/attributes.py b/saleor/graphql/product/mutations/attributes.py
index 28d38b7a54..eeaf331ef8 100644
--- a/saleor/graphql/product/mutations/attributes.py
+++ b/saleor/graphql/product/mutations/attributes.py
@@ -14,7 +14,8 @@ class ProductAttributesInput(graphene.InputObjectType):
class AttributeChoiceValueInput(graphene.InputObjectType):
attribute = graphene.ID(
required=False,
- description='Attribute to which value will be assigned.')
+ description='Attribute to which value will be assigned.',
+ name='attribute')
slug = graphene.String(
required=True, description='Internal name.')
name = graphene.String(
diff --git a/saleor/graphql/product/mutations/products.py b/saleor/graphql/product/mutations/products.py
index ad5b080181..56348839bd 100644
--- a/saleor/graphql/product/mutations/products.py
+++ b/saleor/graphql/product/mutations/products.py
@@ -18,7 +18,7 @@ class CategoryInput(graphene.InputObjectType):
parent = graphene.ID(
description='''
ID of the parent category. If empty, category will be top level
- category.''')
+ category.''', name='parent')
slug = graphene.String(description='Category slug')
seo = SeoInput(description='Search engine optimization fields.')
@@ -78,7 +78,8 @@ class CollectionInput(graphene.InputObjectType):
slug = graphene.String(description='Slug of the collection.')
products = graphene.List(
graphene.ID,
- description='List of products to be added to the collection.')
+ description='List of products to be added to the collection.',
+ name='products')
background_image = Upload(description='Background image file.')
seo = SeoInput(description='Search engine optimization fields.')
@@ -190,12 +191,14 @@ class ProductInput(graphene.InputObjectType):
description='List of product attributes.')
available_on = graphene.types.datetime.Date(
description='Publication date. ISO 8601 standard.')
- category = graphene.ID(description='ID of the product\'s category.')
+ category = graphene.ID(
+ description='ID of the product\'s category.', name='category')
charge_taxes = graphene.Boolean(
description='Determine if taxes are being charged for the product.')
collections = graphene.List(
graphene.ID,
- description='List of IDs of collections that the product belongs to.')
+ description='List of IDs of collections that the product belongs to.',
+ name='collections')
description = graphene.String(description='Product description.')
is_published = graphene.Boolean(
description='Determines if product is visible to customers.')
@@ -203,7 +206,8 @@ class ProductInput(graphene.InputObjectType):
description='Determines if product is featured in the storefront.')
name = graphene.String(description='Product name.')
product_type = graphene.ID(
- description='ID of the type that product belongs to.')
+ description='ID of the type that product belongs to.',
+ name='productType')
price = Decimal(description='Product price.')
tax_rate = graphene.String(description='Tax rate.')
seo = SeoInput(description='Search engine optimization fields.')
@@ -285,7 +289,8 @@ class ProductVariantInput(graphene.InputObjectType):
price_override = Decimal(
description='Special price of the particular variant.')
product = graphene.ID(
- description='Product ID of which type is the variant.')
+ description='Product ID of which type is the variant.',
+ name='product')
sku = graphene.String(description='Stock keeping unit.')
quantity = graphene.Int(
description='The total quantity of this variant available for sale.')
@@ -368,11 +373,13 @@ class ProductTypeInput(graphene.InputObjectType):
the hood.""")
product_attributes = graphene.List(
graphene.ID,
- description='List of attributes shared among all product variants.')
+ description='List of attributes shared among all product variants.',
+ name='productAttributes')
variant_attributes = graphene.List(
graphene.ID,
description="""List of attributes used to distinguish between
- different variants of a product.""")
+ different variants of a product.""",
+ name='variantAttributes')
is_shipping_required = graphene.Boolean(
description="""Determines if shipping is required for products
of this variant.""")
@@ -425,7 +432,7 @@ class ProductImageCreateInput(graphene.InputObjectType):
image = Upload(
required=True,
description='Represents an image file in a multipart request.')
- product = graphene.ID(description='ID of an product.')
+ product = graphene.ID(description='ID of an product.', name='product')
class ProductImageCreate(ModelMutation):
diff --git a/saleor/graphql/shipping/mutations.py b/saleor/graphql/shipping/mutations.py
index 2ae21a04b9..254d85eda2 100644
--- a/saleor/graphql/shipping/mutations.py
+++ b/saleor/graphql/shipping/mutations.py
@@ -9,7 +9,8 @@ class ShippingPriceInput(graphene.InputObjectType):
country_code = graphene.String(
description='Shipping specific country code.')
price = Decimal(description='Shipping price to a specified country.')
- shipping_method = graphene.ID(description='Related shipping method name.')
+ shipping_method = graphene.ID(
+ description='Related shipping method name.', name='shippingMethod')
class ShippingMethodInput(graphene.InputObjectType):