Repository: saleor/saleor
Pull request: Add `schemaVersion` field to `Shop` type
https://github.com/saleor/saleor/issues/11274

I want to merge this change because I want to fetch minor version of Saleor as anonymous user.
```graphql
type Shop {
   ...
   schemaVersion: String!
}
```

<!-- Please mention all relevant issue numbers. -->

# Impact

* [ ] New migrations
* [x] New/Updated API fields or mutations
* [ ] Deprecated API fields or mutations
* [ ] Removed API types, fields, or mutations
* [ ] Documentation needs to be updated

# Pull Request Checklist

<!-- Please keep this section. It will make the maintainer's life easier. -->

* [ ] Privileged queries and mutations are guarded by proper permission checks
* [ ] Database queries are optimized and the number of queries is constant
* [ ] Database migration files are up to date
* [ ] The changes are tested
* [ ] GraphQL schema and type definitions are up to date
* [ ] Changes are mentioned in the changelog


Problem statement:
Add `schemaVersion` field to `Shop` type
### What I'm trying to achieve
I want to add public information about Saleor's api version to `Shop` type.

### Describe a proposed solution
```graphql
type Shop {
   ...
   schemaVersion: String!
}
```

`schemaVersion` will be displayed without any permissions and will be truncated to minor version only. 

### Other solutions I've tried and won't work
…

### Screenshots or mockups
<!-- Please provide any illustrations that could help others understand the problem or the proposed solution. -->

Hints from issue discussion:
I think it needs to be `String!` as it's guaranteed not to return `null`.

Commit message: add schemaVersion field to Shop type

Patch to review:
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 151b824fbfc..b1befcae8c9 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -236,6 +236,7 @@ All notable, unreleased changes to this project will be documented in this file.
 - Expose manifest in the `App` type (#10055) (f0f944066)
 - Deprecate `configurationUrl` and `dataPrivacy` fields in apps (#10046) (68bd7c8a2)
 - Fix `ProductVariant.created` resolver (#10072) (6c77053a9)
+- Add `schemaVersion` field to `Shop` type. #11275 by @zedzior
 
 ### Saleor Apps
 
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index e95996d77da..c7c6d023197 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -8197,6 +8197,13 @@ type Shop {
   """
   version: String!
 
+  """
+  Minor Saleor API version.
+  
+  Added in Saleor 3.5.
+  """
+  schemaVersion: String!
+
   """Include taxes in prices."""
   includeTaxesInPrices: Boolean! @deprecated(reason: "This field will be removed in Saleor 4.0. Use `Channel.taxConfiguration.pricesEnteredWithTax` to determine whether prices are entered with tax.")
 
diff --git a/saleor/graphql/shop/tests/test_shop.py b/saleor/graphql/shop/tests/test_shop.py
index 5efcad2ea79..a68bf04eaf0 100644
--- a/saleor/graphql/shop/tests/test_shop.py
+++ b/saleor/graphql/shop/tests/test_shop.py
@@ -1559,6 +1559,25 @@ def test_version_query_as_staff_user(staff_api_client):
     assert content["data"]["shop"]["version"] == __version__
 
 
+def test_schema_version_query(api_client):
+    # given
+    query = """
+        query {
+            shop {
+                schemaVersion
+            }
+        }
+    """
+
+    # when
+    response = api_client.post_graphql(query)
+    content = get_graphql_content(response)
+
+    # then
+    assert content["data"]["shop"]["schemaVersion"] in __version__
+    assert content["data"]["shop"]["schemaVersion"] != __version__
+
+
 def test_cannot_get_shop_limit_info_when_not_staff(user_api_client):
     query = LIMIT_INFO_QUERY
     response = user_api_client.post_graphql(query)
diff --git a/saleor/graphql/shop/types.py b/saleor/graphql/shop/types.py
index bd1988c21f2..06f6012d97b 100644
--- a/saleor/graphql/shop/types.py
+++ b/saleor/graphql/shop/types.py
@@ -17,6 +17,7 @@
 from ..checkout.types import PaymentGateway
 from ..core.descriptions import (
     ADDED_IN_31,
+    ADDED_IN_35,
     DEPRECATED_IN_3X_FIELD,
     DEPRECATED_IN_3X_INPUT,
     PREVIEW_FEATURE,
@@ -293,6 +294,10 @@ class Shop(graphene.ObjectType):
             AuthorizationFilters.AUTHENTICATED_APP,
         ],
     )
+    schema_version = graphene.String(
+        description="Minor Saleor API version." + ADDED_IN_35,
+        required=True,
+    )
 
     # deprecated
     include_taxes_in_prices = graphene.Boolean(
@@ -506,6 +511,10 @@ def resolve_limits(_, _info):
     def resolve_version(_, _info):
         return __version__
 
+    @staticmethod
+    def resolve_schema_version(_, _info):
+        return f'{__version__.split(".")[0]}.{__version__.split(".")[1]}'
+
     # deprecated
 
     @staticmethod


Code review comments:
diff_hunk: @@ -506,6 +511,10 @@ def resolve_limits(_, _info):
     def resolve_version(_, _info):
         return __version__
 
+    @staticmethod
+    def resolve_schema_version(_, _info):
+        return f'{__version__.split(".")[0]}.{__version__.split(".")[1]}'
path: saleor/graphql/shop/types.py
text: @user1:
No need to scan and split twice:
```suggestion
    def resolve_schema_version(_, _info):
        major, minor, _ = __version__.split(".", 2)
        return f'{major}.{minor}'
```



@author:
You are absolutely right, thanks