Skip to content

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

Revert ancestors field

Marcin Gębalae324e53ec75d
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.py
index a5fc1aaf18..36229b0850 100644
--- a/saleor/graphql/product/types.py
+++ b/saleor/graphql/product/types.py
@@ -432,6 +432,9 @@ class Collection(CountableDjangoObjectType):
class Category(CountableDjangoObjectType):
+ ancestors = PrefetchingConnectionField(
+ lambda: Category,
+ description='List of ancestors of the category.')
products = gql_optimizer.field(
PrefetchingConnectionField(
Product, description='List of products in the category.'),
@@ -453,6 +456,10 @@ class Category(CountableDjangoObjectType):
interfaces = [relay.Node]
model = models.Category
+ def resolve_ancestors(self, info, **kwargs):
+ qs = self.get_ancestors()
+ return gql_optimizer.query(qs, info)
+
def resolve_background_image(self, info, **kwargs):
return self.background_image or None
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 574c1bc076..e428f9a1f7 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -230,6 +230,7 @@ type Category implements Node {
level: Int!
children(before: String, after: String, first: Int, last: Int): CategoryCountableConnection
products(before: String, after: String, first: Int, last: Int): ProductCountableConnection
+ ancestors(before: String, after: String, first: Int, last: Int): CategoryCountableConnection
url: String
}
diff --git a/tests/api/test_category.py b/tests/api/test_category.py
index 861c00f124..45c6797557 100644
--- a/tests/api/test_category.py
+++ b/tests/api/test_category.py
@@ -16,6 +16,13 @@ def test_category_query(user_api_client, product):
category(id: "%(category_pk)s") {
id
name
+ ancestors(last: 20) {
+ edges {
+ node {
+ name
+ }
+ }
+ }
children(first: 20) {
edges {
node {
@@ -31,6 +38,9 @@ def test_category_query(user_api_client, product):
category_data = content['data']['category']
assert category_data is not None
assert category_data['name'] == category.name
+ assert (
+ len(category_data['ancestors']['edges']) ==
+ category.get_ancestors().count())
assert (
len(category_data['children']['edges']) ==
category.get_children().count())
diff --git a/tests/api/test_graphql.py b/tests/api/test_graphql.py
index 2662143e36..705a73178a 100644
--- a/tests/api/test_graphql.py
+++ b/tests/api/test_graphql.py
@@ -68,6 +68,16 @@ def test_real_query(user_api_client, product):
id
name
url
+ ancestors(last: 20) {
+ edges {
+ node {
+ name
+ id
+ url
+ __typename
+ }
+ }
+ }
children(first: 20) {
edges {
node {