Skip to content

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

Add field descriptions

Marcin Gębala3c0fb6100c0c
diff --git a/saleor/graphql/core/types.py b/saleor/graphql/core/types.py
index d8088183c7..e145ddf8ea 100644
--- a/saleor/graphql/core/types.py
+++ b/saleor/graphql/core/types.py
@@ -7,7 +7,8 @@ class CountableConnection(graphene.relay.Connection):
class Meta:
abstract = True
- total_count = graphene.Int()
+ total_count = graphene.Int(
+ description="A total count of items in the collection")
@staticmethod
def resolve_total_count(root, info, *args, **kwargs):
diff --git a/saleor/graphql/page/types.py b/saleor/graphql/page/types.py
index f623469d46..157c260504 100644
--- a/saleor/graphql/page/types.py
+++ b/saleor/graphql/page/types.py
@@ -6,6 +6,9 @@ from ..core.types import CountableDjangoObjectType
class Page(CountableDjangoObjectType):
class Meta:
+ description = """
+ A static page that can be manually added by staff users through
+ the dashboard."""
model = models.Page
interfaces = [relay.Node]
diff --git a/saleor/graphql/product/types.py b/saleor/graphql/product/types.py
index fc36c649c9..40ef9b0d8b 100644
--- a/saleor/graphql/product/types.py
+++ b/saleor/graphql/product/types.py
@@ -19,13 +19,20 @@ class SelectedAttribute(graphene.ObjectType):
class ProductVariant(CountableDjangoObjectType):
- stock_quantity = graphene.Int()
- price_override = graphene.Field(Money)
+ stock_quantity = graphene.Int(
+ required=True, description='Quantity of a product available for sale.')
+ price_override = graphene.Field(
+ Money,
+ description="""
+ Override the base price of a product if necessary. A value of `null`
+ indicates the the default product price is used.""")
attributes = graphene.List(SelectedAttribute)
class Meta:
- model = models.ProductVariant
+ description = """
+ Represents a version of a product such as different size or color."""
interfaces = [relay.Node]
+ model = models.ProductVariant
def resolve_stock_quantity(self, info):
return self.get_stock_quantity()
@@ -43,20 +50,38 @@ class ProductAvailability(graphene.ObjectType):
price_range_undiscounted = graphene.Field(TaxedMoneyRange)
price_range_local_currency = graphene.Field(TaxedMoneyRange)
+ class Meta:
+ description = 'Represents availability of a product in the storefront.'
+
class Product(CountableDjangoObjectType):
- url = graphene.String()
+ url = graphene.String(
+ description='The storefront URL for the product.',
+ required=True)
thumbnail_url = graphene.String(
+ description='The URL of a main thumbnail for a product.',
size=graphene.Argument(
graphene.String,
- description='The size of a thumbnail, for example 255x255'))
- availability = graphene.Field(ProductAvailability)
- price = graphene.Field(Money)
+ description='Size of a thumbnail, for example 255x255.'))
+ images = graphene.List(
+ lambda: ProductImage, description='List of product images.')
+ variants = graphene.List(
+ lambda: ProductVariant, description='List of product variants.')
+ availability = graphene.Field(
+ ProductAvailability,
+ description="""
+ Informs about product\'s availability in the storefront, current price
+ and discounts.""")
+ price = graphene.Field(
+ Money,
+ description="""
+ The product\'s base price (without any discounts applied).""")
attributes = graphene.List(SelectedAttribute)
class Meta:
- model = models.Product
+ description = 'Represents an individual item for sale in the storefront.'
interfaces = [relay.Node]
+ model = models.Product
def resolve_thumbnail_url(self, info, *, size=None):
if not size:
@@ -87,19 +112,26 @@ class ProductType(CountableDjangoObjectType):
class Category(CountableDjangoObjectType):
products = DjangoFilterConnectionField(
- Product, filterset_class=ProductFilterSet)
- url = graphene.String()
+ Product, filterset_class=ProductFilterSet,
+ description='List of products in the category.')
+ url = graphene.String(
+ description='The storefront\'s URL for the category.')
ancestors = DjangoFilterConnectionField(
- lambda: Category, filterset_class=DistinctFilterSet)
+ lambda: Category, filterset_class=DistinctFilterSet,
+ description='List of ancestors of the category.')
children = DjangoFilterConnectionField(
- lambda: Category, filterset_class=DistinctFilterSet)
- siblings = DjangoFilterConnectionField(
- lambda: Category, filterset_class=DistinctFilterSet)
+ lambda: Category, filterset_class=DistinctFilterSet,
+ description='List of children of the category.')
class Meta:
- model = models.Category
- filter_fields = ['id', 'name']
+ description = """
+ Represents a single category of products. Categories allow to organize
+ products in a tree-hierarchies which can be used for navigation in the
+ storefront."""
+ exclude_fields = ['lft', 'rght', 'tree_id']
interfaces = [relay.Node]
+ filter_fields = ['id', 'name']
+ model = models.Category
def resolve_ancestors(self, info, **kwargs):
return self.get_ancestors().distinct()
@@ -107,9 +139,6 @@ class Category(CountableDjangoObjectType):
def resolve_children(self, info, **kwargs):
return self.children.distinct()
- def resolve_siblings(self, info, **kwargs):
- return self.get_siblings().distinct()
-
def resolve_url(self, info):
ancestors = self.get_ancestors().distinct()
return self.get_absolute_url(ancestors)
@@ -121,11 +150,16 @@ class Category(CountableDjangoObjectType):
class ProductImage(CountableDjangoObjectType):
- url = graphene.String(size=graphene.String())
+ url = graphene.String(
+ required=True, description='',
+ size=graphene.String(
+ description='Size of an image, for example 255x255.'))
class Meta:
- model = models.ProductImage
+ description = 'Represents a product image.'
+ exclude_fields = ['product', 'productvariant_set', 'variant_images']
interfaces = [relay.Node]
+ model = models.ProductImage
def resolve_url(self, info, *, size=None):
if size:
@@ -135,17 +169,22 @@ class ProductImage(CountableDjangoObjectType):
class ProductAttributeValue(CountableDjangoObjectType):
class Meta:
- model = models.AttributeChoiceValue
+ description = 'Represents a value of an attribute.'
interfaces = [relay.Node]
+ model = models.AttributeChoiceValue
class ProductAttribute(CountableDjangoObjectType):
- values = graphene.List(ProductAttributeValue)
+ values = graphene.List(
+ ProductAttributeValue, description='List of attribute\'s values.')
class Meta:
- model = models.ProductAttribute
- filter_fields = ['id', 'slug']
+ description = """
+ Custom attribute of a product. Attributes can be dynamically assigned
+ to products and variants at the product type level."""
interfaces = [relay.Node]
+ filter_fields = ['id', 'slug']
+ model = models.ProductAttribute
def resolve_values(self, info):
return self.values.all()
diff --git a/tests/dashboard/test_graphql.py b/tests/dashboard/test_graphql.py
index dada4baf62..fc93eef668 100644
--- a/tests/dashboard/test_graphql.py
+++ b/tests/dashboard/test_graphql.py
@@ -6,14 +6,14 @@ import pytest
from django.shortcuts import reverse
from django.utils.text import slugify
-from saleor.dashboard.graphql.mutations import (
+from saleor.dashboard.graphql.core.mutations import (
ModelFormMutation, ModelFormUpdateMutation)
from ..utils import get_graphql_content
-@patch('saleor.dashboard.graphql.mutations.convert_form_fields')
-@patch('saleor.dashboard.graphql.mutations.convert_form_field')
+@patch('saleor.dashboard.graphql.core.mutations.convert_form_fields')
+@patch('saleor.dashboard.graphql.core.mutations.convert_form_field')
def test_model_form_mutation(
mocked_convert_form_field, mocked_convert_form_fields,
model_form_class):
@@ -47,7 +47,7 @@ def test_model_form_mutation(
assert 'errors' in output_fields
-@patch('saleor.dashboard.graphql.mutations')
+@patch('saleor.dashboard.graphql.core.mutations')
def test_model_form_update_mutation(model_form_class):
class TestUpdateMutation(ModelFormUpdateMutation):
class Meta:
diff --git a/tests/test_graphql.py b/tests/test_graphql.py
index 915e531139..02cb7a4ca5 100644
--- a/tests/test_graphql.py
+++ b/tests/test_graphql.py
@@ -31,13 +31,6 @@ def test_category_query(client, product_in_stock):
}
}
}
- siblings {
- edges {
- node {
- name
- }
- }
- }
}
}
''' % {'category_pk': graphene.Node.to_global_id('Category', category.pk)}
@@ -53,9 +46,6 @@ def test_category_query(client, product_in_stock):
assert (
len(category_data['children']['edges']) ==
category.get_children().count())
- assert (
- len(category_data['siblings']['edges']) ==
- category.get_siblings().count())
def test_fetch_all_products(client, product_in_stock):