Skip to content

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

Fix circular import

Adam Janika6a08bde3f7e
diff --git a/saleor/graphql/product/resolvers.py b/saleor/graphql/product/resolvers.py
index dbca43b91b..cfd1bbf9f9 100644
--- a/saleor/graphql/product/resolvers.py
+++ b/saleor/graphql/product/resolvers.py
@@ -1,30 +1,9 @@
from django.db.models import Q
-from . import types
from ...product import models
from ...product.utils import products_visible_to_user
from ..utils import get_node
-
-
-def resolve_attribute_list(attributes=None):
- """
- :param attributes: dict
- :return: list of objects of type SelectedAttribute
- """
- attribute_list = []
- if attributes:
- product_attributes = dict(
- models.ProductAttribute.objects.values_list('id', 'slug'))
- attribute_values = dict(
- models.AttributeChoiceValue.objects.values_list('id', 'slug'))
- for k, v in attributes.items():
- value = None
- name = product_attributes.get(int(k))
- if v:
- value = attribute_values.get(int(v))
- attribute_list.append(
- types.SelectedAttribute(name=name, value=value))
- return attribute_list
+from .types import Category, SelectedAttribute
def resolve_categories(info, level=None):
@@ -38,7 +17,7 @@ def resolve_products(info, category_id):
user = info.context.user
products = products_visible_to_user(user=user).distinct()
if category_id is not None:
- category = get_node(info, category_id, only_type=types.Category)
+ category = get_node(info, category_id, only_type=Category)
return products.filter(category=category).distinct()
return products
@@ -48,7 +27,7 @@ def resolve_attributes(category_id, info):
if category_id:
# Get attributes that are used with product types
# within the given category.
- category = get_node(info, category_id, only_type=types.Category)
+ category = get_node(info, category_id, only_type=Category)
if category is None:
return queryset.none()
tree = category.get_descendants(include_self=True)
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.py
index 56b00a9ba6..d102582025 100644
--- a/saleor/graphql/product/types.py
+++ b/saleor/graphql/product/types.py
@@ -12,7 +12,23 @@ from ..core.filters import DistinctFilterSet
from ..core.types import (
CountableDjangoObjectType, Money, TaxedMoney, TaxedMoneyRange)
from .filters import ProductFilterSet
-from .resolvers import resolve_attribute_list
+
+
+def resolve_attribute_list(attributes):
+ attribute_list = []
+ if attributes:
+ product_attributes = dict(
+ models.ProductAttribute.objects.values_list('id', 'slug'))
+ attribute_values = dict(
+ models.AttributeChoiceValue.objects.values_list('id', 'slug'))
+ for k, v in attributes.items():
+ value = None
+ name = product_attributes.get(int(k))
+ if v:
+ value = attribute_values.get(int(v))
+ attribute_list.append(
+ SelectedAttribute(name=name, value=value))
+ return attribute_list
class GrossMargin(graphene.ObjectType):