Skip to content

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

Clean changes not related to this PR

Adam Janik185dc90e5169
diff --git a/saleor/graphql/core/types.py b/saleor/graphql/core/types.py
index 0ccbeae142..8d9c1efb6d 100644
--- a/saleor/graphql/core/types.py
+++ b/saleor/graphql/core/types.py
@@ -15,16 +15,7 @@ class CountableConnection(graphene.relay.Connection):
return root.length
-class GetNodesMixin:
-
- @classmethod
- def get_nodes(cls, ids):
- try:
- return list(cls._meta.model.objects.filter(pk__in=ids))
- except cls._meta.model.DoesNotExist:
- return None
-
-class CountableDjangoObjectType(DjangoObjectType, GetNodesMixin):
+class CountableDjangoObjectType(DjangoObjectType):
class Meta:
abstract = True
diff --git a/saleor/graphql/product/mutations.py b/saleor/graphql/product/mutations.py
index 9c4c8ddaaa..96c179fe80 100644
--- a/saleor/graphql/product/mutations.py
+++ b/saleor/graphql/product/mutations.py
@@ -72,8 +72,9 @@ class CollectionCreateMutation(StaffMemberRequiredMixin, ModelFormMutation):
product_ids = input.pop('products', None)
kwargs = super().get_form_kwargs(root, info, **input)
if product_ids:
- products = set(
- get_nodes(info, product_ids, only_type=Product))
+ products = {
+ get_node(info, pr_id, only_type=Product)
+ for pr_id in product_ids}
kwargs['data']['products'] = products
return kwargs
@@ -245,14 +246,14 @@ class ProductTypeCreateMutation(StaffMemberRequiredMixin, ModelFormMutation):
def get_form_kwargs(cls, root, info, **input):
product_attributes = input.pop('product_attributes', None)
if product_attributes:
- product_attributes = set(
- get_nodes(
- info, product_attributes, only_type=ProductAttribute))
+ product_attributes = {
+ get_node(info, pr_att_id, only_type=ProductAttribute)
+ for pr_att_id in product_attributes}
variant_attributes = input.pop('variant_attributes', None)
if variant_attributes:
- variant_attributes = set(
- get_nodes(
- info, variant_attributes, only_type=ProductAttribute))
+ variant_attributes = {
+ get_node(info, pr_att_id, only_type=ProductAttribute)
+ for pr_att_id in variant_attributes}
kwargs = super().get_form_kwargs(root, info, **input)
kwargs['data']['product_attributes'] = product_attributes
diff --git a/saleor/graphql/utils.py b/saleor/graphql/utils.py
index ace3a4c9b8..3e4a26c448 100644
--- a/saleor/graphql/utils.py
+++ b/saleor/graphql/utils.py
@@ -6,38 +6,6 @@ from graphql_relay import from_global_id
from ..product.models import AttributeChoiceValue, ProductAttribute
-class MirumeeNode(graphene.Node):
-
- @classmethod
- def get_node_list_from_global_id(cls, info, global_ids, only_type=None):
- try:
- _ids = []
- for _id in global_ids:
- _type, _id = cls.from_global_id(_id)
- _ids.append(_id)
- graphene_type = info.schema.get_type(_type).graphene_type
- except Exception:
- return None
-
- if only_type:
- assert graphene_type == only_type, (
- 'Must receive an {} id.'
- ).format(graphene_type._meta.name)
-
- get_nodes = getattr(graphene_type, 'get_nodes', None)
- if get_nodes:
- return get_nodes(_ids)
-
-
-def get_nodes(info, ids, only_type=None):
- node_list = MirumeeNode.get_node_list_from_global_id(
- info, ids, only_type=only_type)
- if not node_list:
- raise Exception(
- "Could not resolve to a node_list with the global ids of '%s'." % id)
- return node_list
-
-
def get_node(info, id, only_type=None):
"""Return node or throw an error if the node does not exist."""
node = graphene.Node.get_node_from_global_id(info, id, only_type=only_type)