Skip to content

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

Add Shop.version field

Marcin Gębalac340d2a35682
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 86441c1194..a27957d88f 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -83,6 +83,7 @@ All notable, unreleased changes to this project will be documented in this file.
- Change the `app` query to return info about the currently authenticated app - #6928 by @d-wysocki
- Add default sorting by rank for search products - #6936 by @d-wysocki
- Fix exporting product description to xlsx - #6959 by @IKarbowiak
+- Add `Shop.version` field to query API version - #6980 by @maarcingebala
# 2.11.1
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 5d0c1ce915..264b576301 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -5049,6 +5049,7 @@ type Shop {
companyAddress: Address
customerSetPasswordUrl: String
staffNotificationRecipients: [StaffNotificationRecipient]
+ version: String!
}
type ShopAddressUpdate {
diff --git a/saleor/graphql/shop/tests/test_shop.py b/saleor/graphql/shop/tests/test_shop.py
index 8323196514..1204fae560 100644
--- a/saleor/graphql/shop/tests/test_shop.py
+++ b/saleor/graphql/shop/tests/test_shop.py
@@ -4,6 +4,7 @@ import graphene
import pytest
from django_countries import countries
+from .... import __version__
from ....account.models import Address
from ....core.error_codes import ShopErrorCode
from ....core.permissions import get_permissions_codename
@@ -1265,3 +1266,34 @@ def test_order_settings_query_as_staff(
def test_order_settings_query_as_user(user_api_client, site_settings):
response = user_api_client.post_graphql(ORDER_SETTINGS_QUERY)
assert_no_permission(response)
+
+
+API_VERSION_QUERY = """
+ query {
+ shop {
+ version
+ }
+ }
+"""
+
+
+def test_version_query_as_anonymous_user(api_client):
+ response = api_client.post_graphql(API_VERSION_QUERY)
+ assert_no_permission(response)
+
+
+def test_version_query_as_customer(user_api_client):
+ response = user_api_client.post_graphql(API_VERSION_QUERY)
+ assert_no_permission(response)
+
+
+def test_version_query_as_app(app_api_client):
+ response = app_api_client.post_graphql(API_VERSION_QUERY)
+ content = get_graphql_content(response)
+ assert content["data"]["shop"]["version"] == __version__
+
+
+def test_version_query_as_staff_user(staff_api_client):
+ response = staff_api_client.post_graphql(API_VERSION_QUERY)
+ content = get_graphql_content(response)
+ assert content["data"]["shop"]["version"] == __version__
diff --git a/saleor/graphql/shop/types.py b/saleor/graphql/shop/types.py
index 158cda9b40..0622b71aa8 100644
--- a/saleor/graphql/shop/types.py
+++ b/saleor/graphql/shop/types.py
@@ -7,6 +7,7 @@ from django_countries import countries
from django_prices_vatlayer.models import VAT
from phonenumbers import COUNTRY_CODE_TO_REGION_CODE
+from ... import __version__
from ...account import models as account_models
from ...core.permissions import SitePermissions, get_permissions
from ...plugins.manager import get_plugins_manager
@@ -18,7 +19,7 @@ from ..core.connection import CountableDjangoObjectType
from ..core.enums import WeightUnitsEnum
from ..core.types.common import CountryDisplay, LanguageDisplay, Permission
from ..core.utils import str_to_enum
-from ..decorators import permission_required
+from ..decorators import permission_required, staff_member_or_app_required
from ..menu.dataloaders import MenuByIdLoader
from ..menu.types import Menu
from ..shipping.types import ShippingMethod
@@ -170,6 +171,7 @@ class Shop(graphene.ObjectType):
description="List of staff notification recipients.",
required=False,
)
+ version = graphene.String(description="Saleor API version.", required=True)
class Meta:
description = (
@@ -333,3 +335,8 @@ class Shop(graphene.ObjectType):
@permission_required(SitePermissions.MANAGE_SETTINGS)
def resolve_staff_notification_recipients(_, info):
return account_models.StaffNotificationRecipient.objects.all()
+
+ @staticmethod
+ @staff_member_or_app_required
+ def resolve_version(_, _info):
+ return __version__