Skip to content

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

fix(federation): improve error handling (#18718)

Mikail59d8fa134aac
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 87a0b2e323..238c98ee72 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,6 +10,14 @@ All notable, unreleased changes to this project will be documented in this file.
- Shipping method metadata is now also denormalized during draft order finalization, ensuring consistent behavior across all order creation flows.
- Fields `options`, `mount` and `target` are removed from `AppExtension` and `AppManifestExtension` types. Use `mountName`, `targetName` and `settings`
- Deprecate the `hasVariants` field on `ProductType`. This setting is a legacy artifact from the former Simple/Configurable product distinction. Products can have multiple variants regardless of this flag. Previously, it only prevented assigning variant attributes to a product type; this restriction will no longer apply.
+- Improved error handling in Federation - #18718 by @NyanKiyoshi
+
+ The type for GraphQL field `representations` in `{ _entities(representations: [_Any!]!) { ... } }` was changed.
+
+ Before: `[_Any]`
+ After: `[_Any!]!`
+
+ Make sure to adapt your GraphQL queries if you use the `_entities` query.
### GraphQL API
- Gift cards support as payment method within Transaction API (read more in the [docs](https://docs.saleor.io/developer/gift-cards#using-gift-cards-in-checkout)).
diff --git a/saleor/graphql/account/tests/benchmark/test_account.py b/saleor/graphql/account/tests/benchmark/test_account.py
index 3d6dff021f..9db2b8539b 100644
--- a/saleor/graphql/account/tests/benchmark/test_account.py
+++ b/saleor/graphql/account/tests/benchmark/test_account.py
@@ -377,7 +377,7 @@ def test_users_for_federation_query_count(
count_queries,
):
query = """
- query GetUserInFederation($representations: [_Any]) {
+ query GetUserInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on User {
@@ -460,7 +460,7 @@ def test_addresses_for_federation_query_count(
customer_user2.addresses.add(address2)
query = """
- query GetAddressInFederation($representations: [_Any]) {
+ query GetAddressInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on Address {
diff --git a/saleor/graphql/account/tests/benchmark/test_permission_group.py b/saleor/graphql/account/tests/benchmark/test_permission_group.py
index 1e684cb1cb..35f167f745 100644
--- a/saleor/graphql/account/tests/benchmark/test_permission_group.py
+++ b/saleor/graphql/account/tests/benchmark/test_permission_group.py
@@ -329,7 +329,7 @@ def test_groups_for_federation_query_count(
)
query = """
- query GetGroupInFederation($representations: [_Any]) {
+ query GetGroupInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on Group {
diff --git a/saleor/graphql/account/tests/queries/test_address.py b/saleor/graphql/account/tests/queries/test_address.py
index ab6fd2c802..23f092a760 100644
--- a/saleor/graphql/account/tests/queries/test_address.py
+++ b/saleor/graphql/account/tests/queries/test_address.py
@@ -92,7 +92,7 @@ def test_address_query_with_invalid_object_type(
ADDRESS_FEDERATION_QUERY = """
- query GetUserInFederation($representations: [_Any]) {
+ query GetUserInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on Address {
diff --git a/saleor/graphql/account/tests/queries/test_permission_group.py b/saleor/graphql/account/tests/queries/test_permission_group.py
index a290c1499f..a8acd20e20 100644
--- a/saleor/graphql/account/tests/queries/test_permission_group.py
+++ b/saleor/graphql/account/tests/queries/test_permission_group.py
@@ -4,7 +4,7 @@ from .....account.models import Group
from ....tests.utils import get_graphql_content
GROUP_FEDERATION_QUERY = """
- query GetGroupInFederation($representations: [_Any]) {
+ query GetGroupInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on Group {
diff --git a/saleor/graphql/account/tests/queries/test_user.py b/saleor/graphql/account/tests/queries/test_user.py
index d2400975b1..a5debda57c 100644
--- a/saleor/graphql/account/tests/queries/test_user.py
+++ b/saleor/graphql/account/tests/queries/test_user.py
@@ -1055,7 +1055,7 @@ def test_user_with_cancelled_fulfillments(
USER_FEDERATION_QUERY = """
- query GetUserInFederation($representations: [_Any]) {
+ query GetUserInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on User {
diff --git a/saleor/graphql/app/tests/benchmarks/test_apps.py b/saleor/graphql/app/tests/benchmarks/test_apps.py
index 2a62eb51a0..52e841f18a 100644
--- a/saleor/graphql/app/tests/benchmarks/test_apps.py
+++ b/saleor/graphql/app/tests/benchmarks/test_apps.py
@@ -23,7 +23,7 @@ def test_apps_for_federation_query_count(
)
query = """
- query GetAppInFederation($representations: [_Any]) {
+ query GetAppInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on App {
diff --git a/saleor/graphql/app/tests/queries/test_apps.py b/saleor/graphql/app/tests/queries/test_apps.py
index 042a1251c3..5eb8a30088 100644
--- a/saleor/graphql/app/tests/queries/test_apps.py
+++ b/saleor/graphql/app/tests/queries/test_apps.py
@@ -249,7 +249,7 @@ def test_apps_query_pending_installation(staff_api_client, app):
QUERY_APPS_FOR_FEDERATION = """
- query GetAppInFederation($representations: [_Any]) {
+ query GetAppInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on App {
diff --git a/saleor/graphql/core/federation/resolvers.py b/saleor/graphql/core/federation/resolvers.py
index 9f815012c2..5d1335ce64 100644
--- a/saleor/graphql/core/federation/resolvers.py
+++ b/saleor/graphql/core/federation/resolvers.py
@@ -1,10 +1,35 @@
+from typing import Any
+
+import graphene
+from django.core.exceptions import ValidationError
+from graphql.error import GraphQLError
+
from ..utils import from_global_id_or_error
-def resolve_federation_references(graphql_type, roots, queryset):
- ids = [
- from_global_id_or_error(root.id, graphql_type, raise_error=True)[1]
- for root in roots
- ]
+def resolve_id_or_error(idx: Any, graphql_type: type[graphene.ObjectType] | str):
+ # Note: 'graphene.GlobalID' type happens when a user provides other fields
+ # (e.g., 'userEmail') but doesn't provide a value for 'id'.
+ # This is likely Graphene putting a placeholder until the field is resolved.
+ if not idx or isinstance(idx, graphene.GlobalID):
+ raise GraphQLError("Missing required field: id")
+ if isinstance(idx, str) is False:
+ raise GraphQLError("ID must be a string")
+
+ try:
+ _object_type, resolved_id = from_global_id_or_error(
+ idx,
+ only_type=graphql_type,
+ raise_error=True,
+ )
+ except ValidationError as exc:
+ raise GraphQLError(str(exc)) from exc
+ return resolved_id
+
+
+def resolve_federation_references(
+ graphql_type: type[graphene.ObjectType] | str, roots, queryset
+):
+ ids = [resolve_id_or_error(root.id, graphql_type) for root in roots]
objects = {str(obj.id): obj for obj in queryset.filter(id__in=ids)}
return [objects.get(root_id) for root_id in ids]
diff --git a/saleor/graphql/core/federation/schema.py b/saleor/graphql/core/federation/schema.py
index aa095d682c..63fd7ec44d 100644
--- a/saleor/graphql/core/federation/schema.py
+++ b/saleor/graphql/core/federation/schema.py
@@ -4,7 +4,13 @@ from typing import Any
import graphene
from django.conf import settings
from graphene.utils.str_converters import to_snake_case
-from graphql import GraphQLArgument, GraphQLError, GraphQLField, GraphQLList
+from graphql import (
+ GraphQLArgument,
+ GraphQLError,
+ GraphQLField,
+ GraphQLList,
+ GraphQLNonNull,
+)
from ...schema_printer import print_schema
from .. import ResolveInfo
@@ -62,8 +68,12 @@ def build_federated_schema(
query_type.fields["_entities"] = GraphQLField(
GraphQLList(entity_type),
args={
- "representations": GraphQLArgument(
- GraphQLList(schema.get_type("_Any")),
+ "representations": (
+ GraphQLArgument(
+ GraphQLNonNull(
+ GraphQLList(GraphQLNonNull(schema.get_type("_Any")))
+ ),
+ )
),
},
resolver=resolve_entities,
@@ -108,25 +118,40 @@ def resolve_entities(_, info: ResolveInfo, *, representations):
)
resolvers = {}
- for representation in representations:
- if representation["__typename"] not in resolvers:
- try:
- model = federated_entities[representation["__typename"]]
- resolvers[representation["__typename"]] = getattr(
- model,
- "_{}__resolve_references".format(representation["__typename"]),
- )
- except AttributeError:
- pass
-
batches = defaultdict(list)
for representation in representations:
- model = federated_entities[representation["__typename"]]
- model_arguments = representation.copy()
- typename = model_arguments.pop("__typename")
- model_arguments = {to_snake_case(k): v for k, v in model_arguments.items()}
- model_instance = model(**model_arguments)
- batches[typename].append(model_instance)
+ if isinstance(representation, dict) is False:
+ raise GraphQLError(
+ "Invalid type for 'representation' field: must be an object"
+ )
+
+ typename = representation.get("__typename")
+
+ # Validate ``__typename``
+ if typename is None:
+ raise GraphQLError("Missing required field: __typename")
+ if isinstance(typename, str) is False:
+ raise GraphQLError("Invalid type for __typename: must be a string")
+ if not (model := federated_entities.get(typename)):
+ raise GraphQLError("Invalid value or unsupported model for __typename")
+
+ if typename not in resolvers:
+ resolver_ref = f"_{typename}__resolve_references"
+ if hasattr(model, resolver_ref) is True:
+ resolvers[typename] = getattr(model, f"_{typename}__resolve_references")
+
+ attrs = {}
+ for field_name, value in representation.items():
+ if field_name == "__typename":
+ continue
+
+ field_name = to_snake_case(field_name)
+ if field_name not in model._meta.fields:
+ raise GraphQLError(f"Unknown field for {typename}: {field_name}")
+
+ attrs[field_name] = value
+
+ batches[typename].append(model(**attrs))
entities = []
for typename, batch in batches.items():
diff --git a/saleor/graphql/core/federation/tests/__init__.py b/saleor/graphql/core/federation/tests/__init__.py
new file mode 100644
index 0000000000..e69de29bb2
diff --git a/saleor/graphql/core/federation/tests/test_resolvers.py b/saleor/graphql/core/federation/tests/test_resolvers.py
new file mode 100644
index 0000000000..8a689290c2
--- /dev/null
+++ b/saleor/graphql/core/federation/tests/test_resolvers.py
@@ -0,0 +1,70 @@
+from typing import Any
+
+import graphene
+import pytest
+
+QUERY = """
+query Federation ($representations: [_Any!]!) {
+ _entities(representations: $representations) {
+ ... on Order { number }
+ }
+}
+"""
+
+
+# NOTE: happy path for the 'id' field is in ./test_schema.py
+# (test_resolve_entity_should_return_object_when_found)
+ ("_case", "fields", "expected_error_msg"),
+ [
+ (
+ "Error when the Graphene Type mismatches",
+ {"id": graphene.Node.to_global_id("User", 1)},
+ ("Invalid ID: VXNlcjox. Expected: Order, received: User."),
+ ),
+ (
+ "Error when ID isn't UUID",
+ {"id": graphene.Node.to_global_id("Order", 1)},
+ ("['\u201c1\u201d is not a valid UUID.']"),
+ ),
+ (
+ "Error when ID isn't a string",
+ {"id": 123},
+ ("ID must be a string"),
+ ),
+ (
+ "Error when ID null",
+ {"id": None},
+ ("Missing required field: id"),
+ ),
+ (
+ "Error when ID is blank",
+ {"id": ""},
+ ("Missing required field: id"),
+ ),
+ (
+ "Error when ID is missing",
+ {},
+ ("Missing required field: id"),
+ ),
+ (
+ "Error when ID isn't based64",
+ {"id": "foo"},
+ ("Invalid ID: foo. Expected: Order."),
+ ),
+ ],
+)
+def test_resolve_federation_references(
+ _case,
+ fields: dict[str, Any],
+ expected_error_msg: str,
+ staff_api_client,
+):
+ """Ensure errors are handled when user passes invalid IDs."""
+ variables = {"representations": [{"__typename": "Order", **fields}]}
+
+ data = staff_api_client.post_graphql(QUERY, variables).json()
+
+ error_list = data["errors"]
+ assert len(error_list) == 1
+ assert data["errors"][0]["message"] == expected_error_msg
diff --git a/saleor/graphql/core/federation/tests/test_schema.py b/saleor/graphql/core/federation/tests/test_schema.py
new file mode 100644
index 0000000000..c0256f73e0
--- /dev/null
+++ b/saleor/graphql/core/federation/tests/test_schema.py
@@ -0,0 +1,159 @@
+from typing import Any
+
+import graphene
+import pytest
+
+from saleor.graphql.order.types import Order
+
+VALID_QUERY = """
+query Federation ($representations: [_Any!]!) {
+ _entities(representations: $representations) {
+ ... on Order { number }
+ }
+}
+"""
+
+# Query with 'Any' instead of 'Any!' - this must not be allowed, an object must be
+# provided instead.
+INVALID_QUERY_NULL_LIST_ITEM = """
+query Federation ($representations: [_Any]!) {
+ _entities(representations: $representations) {
+ ... on Order { number }
+ }
+}
+"""
+
+# Query with '[Any!]' instead of '[Any!]!' - this must not be allowed, the
+# 'representations' argument is required.
+INVALID_QUERY_NULL_LIST = """
+query Federation ($representations: [_Any!]) {
+ _entities(representations: $representations) {
+ ... on Order { number }
+ }
+}
+"""
+
+# Query without the 'representations' field is not allowed, it must provide it.
+INVALID_QUERY_MISSING_INPUT_FIELD = """
+query Federation {
+ _entities {
+ ... on Order { number }
+ }
+}
+"""
+
+
+ ("_case", "query", "variables", "expected_error_msg"),
+ [
+ (
+ "Error when missing 'representations' argument",
+ INVALID_QUERY_MISSING_INPUT_FIELD,
+ {},
+ ('Argument "representations" of required type [_Any!]!" was not provided.'),
+ ),
+ (
+ "Error when 'representations' is null",
+ INVALID_QUERY_NULL_LIST,
+ {"representations": None},
+ (
+ 'Variable "representations" of type "[_Any!]" used in position '
+ 'expecting type "[_Any!]!".'
+ ),
+ ),
+ (
+ "Error when an *item* in 'representations' is null",
+ INVALID_QUERY_NULL_LIST_ITEM,
+ {"representations": [None]},
+ (
+ 'Variable "representations" of type "[_Any]!" used in position '
+ 'expecting type "[_Any!]!".'
+ ),
+ ),
+ (
+ "Error when __typename is missing",
+ VALID_QUERY,
+ {"representations": [{"id": "foo"}]},
+ "Missing required field: __typename",
+ ),
+ (
+ "Error when __typename value is not supported",
+ VALID_QUERY,
+ {"representations": [{"__typename": "Invalid!"}]},
+ "Invalid value or unsupported model for __typename",
+ ),
+ (
+ "Error when __typename is incorrect type",
+ VALID_QUERY,
+ {"representations": [{"__typename": 1234}]},
+ "Invalid type for __typename: must be a string",
+ ),
+ (
+ "Error when representations is incorrect type",
+ VALID_QUERY,
+ {"representations": [1]},
+ "Invalid type for 'representation' field: must be an object",
+ ),
+ ],
+)
+def test_resolve_entities_handles_errors_invalid_input(
+ _case,
+ query: str,
+ variables: dict[str, Any],
+ expected_error_msg: str,
+ staff_api_client,
+):
+ """Ensure invalid inputs are handled properly."""
+
+ data = staff_api_client.post_graphql(query, variables).json()
+ error_list = data["errors"]
+ assert len(error_list) == 1
+
+ error_dict = data["errors"][0]
+
+ assert error_dict["message"] == expected_error_msg
+
+
+def test_resolve_entities_can_only_provide_fields(staff_api_client):
+ """Ensure only GraphQL fields can be provided.
+
+ Should only be able to provide things like "id", "userEmail", ...
+ and not things like `__name__`.
+ """
+
+ variables = {"representations": [{"__typename": "Order", "__name__": "foo"}]}
+ data = staff_api_client.post_graphql(VALID_QUERY, variables).json()
+ error_list = data["errors"]
+ assert len(error_list) == 1
+
+ error_dict = data["errors"][0]
+
+ assert error_dict["message"] == "Unknown field for Order: __name__"
+
+ # Sanity check: passing '__name__' to model should work
+ # WARNING: must NOT raise an error - this ensures that no one changes the
+ # underlying code of ``resolve_entities()`` to a ``getattr()``
+ # which would cause us to allow non-GraphQL fields
+ Order(__name__=1)
+
+
+def test_resolve_entity_should_return_object_when_found(
+ staff_user,
+ staff_api_client,
+ order_unconfirmed,
+ permission_group_manage_orders,
+):
+ """Ensure a valid request returns the matching Order object."""
+
+ order = order_unconfirmed
+ permission_group_manage_orders.user_set.add(staff_user)
+
+ pk = graphene.Node.to_global_id("Order", order.pk)
+ variables = {"representations": [{"__typename": "Order", "id": pk}]}
+ data = staff_api_client.post_graphql(
+ VALID_QUERY,
+ variables,
+ ).json()
+
+ assert "errors" not in data
+ assert data["data"] == {"_entities": [{"number": str(order.number)}]}
diff --git a/saleor/graphql/order/tests/queries/test_order_entity.py b/saleor/graphql/order/tests/queries/test_order_entity.py
index f3beb363b5..27b9a8c6f8 100644
--- a/saleor/graphql/order/tests/queries/test_order_entity.py
+++ b/saleor/graphql/order/tests/queries/test_order_entity.py
@@ -5,7 +5,7 @@ from .....order.models import Order
from ....tests.utils import get_graphql_content
ORDER_FEDERATION_QUERY = """
- query GetOrderInFederation($representations: [_Any]) {
+ query GetOrderInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on Order {
diff --git a/saleor/graphql/order/types.py b/saleor/graphql/order/types.py
index af168e059c..29a5435853 100644
--- a/saleor/graphql/order/types.py
+++ b/saleor/graphql/order/types.py
@@ -22,7 +22,9 @@ from ...graphql.core.context import (
get_database_connection_name,
)
from ...graphql.core.federation.entities import federated_entity
-from ...graphql.core.federation.resolvers import resolve_federation_references
+from ...graphql.core.federation.resolvers import (
+ resolve_federation_references,
+)
from ...graphql.order.resolvers import resolve_orders
from ...graphql.utils import get_user_or_app_from_context
from ...graphql.warehouse.dataloaders import StockByIdLoader, WarehouseByIdLoader
diff --git a/saleor/graphql/page/tests/benchmark/test_page_type.py b/saleor/graphql/page/tests/benchmark/test_page_type.py
index 8f692414a1..5fb4da15ae 100644
--- a/saleor/graphql/page/tests/benchmark/test_page_type.py
+++ b/saleor/graphql/page/tests/benchmark/test_page_type.py
@@ -162,7 +162,7 @@ def test_page_types_for_federation_query_count(
)
query = """
- query GetAppInFederation($representations: [_Any]) {
+ query GetAppInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on PageType {
diff --git a/saleor/graphql/page/tests/queries/test_page_type.py b/saleor/graphql/page/tests/queries/test_page_type.py
index 0fab900fa7..8930e4f31f 100644
--- a/saleor/graphql/page/tests/queries/test_page_type.py
+++ b/saleor/graphql/page/tests/queries/test_page_type.py
@@ -314,7 +314,7 @@ def test_query_page_types_for_federation(api_client, page_type):
],
}
query = """
- query GetPageTypeInFederation($representations: [_Any]) {
+ query GetPageTypeInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on PageType {
diff --git a/saleor/graphql/product/tests/benchmark/test_category.py b/saleor/graphql/product/tests/benchmark/test_category.py
index 6fcde7d255..e3a65728ac 100644
--- a/saleor/graphql/product/tests/benchmark/test_category.py
+++ b/saleor/graphql/product/tests/benchmark/test_category.py
@@ -228,7 +228,7 @@ def test_categories_for_federation_query_count(
)
query = """
- query GetCategoryInFederation($representations: [_Any]) {
+ query GetCategoryInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on Category {
diff --git a/saleor/graphql/product/tests/benchmark/test_collection.py b/saleor/graphql/product/tests/benchmark/test_collection.py
index 7ca6808e86..d2c6301643 100644
--- a/saleor/graphql/product/tests/benchmark/test_collection.py
+++ b/saleor/graphql/product/tests/benchmark/test_collection.py
@@ -395,7 +395,7 @@ def test_collections_for_federation_query_count(
count_queries,
):
query = """
- query GetCollectionInFederation($representations: [_Any]) {
+ query GetCollectionInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on Collection {
diff --git a/saleor/graphql/product/tests/benchmark/test_product.py b/saleor/graphql/product/tests/benchmark/test_product.py
index 4fb269778d..b0d17aeeb4 100644
--- a/saleor/graphql/product/tests/benchmark/test_product.py
+++ b/saleor/graphql/product/tests/benchmark/test_product.py
@@ -761,7 +761,7 @@ def test_products_for_federation_query_count(
count_queries,
):
query = """
- query GetProductInFederation($representations: [_Any]) {
+ query GetProductInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on Product {
@@ -829,7 +829,7 @@ def test_products_media_for_federation_query_count(
)
query = """
- query GetProductMediaInFederation($representations: [_Any]) {
+ query GetProductMediaInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on ProductMedia {
@@ -880,7 +880,7 @@ def test_products_types_for_federation_query_count(
count_queries,
):
query = """
- query GetProductTypeInFederation($representations: [_Any]) {
+ query GetProductTypeInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on ProductType {
diff --git a/saleor/graphql/product/tests/benchmark/test_variant.py b/saleor/graphql/product/tests/benchmark/test_variant.py
index 7dcc3e5f56..0ad8a5ac9d 100644
--- a/saleor/graphql/product/tests/benchmark/test_variant.py
+++ b/saleor/graphql/product/tests/benchmark/test_variant.py
@@ -361,7 +361,7 @@ def test_products_variants_for_federation_query_count(
count_queries,
):
query = """
- query GetProductVariantInFederation($representations: [_Any]) {
+ query GetProductVariantInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on ProductVariant {
diff --git a/saleor/graphql/product/tests/queries/test_category_query.py b/saleor/graphql/product/tests/queries/test_category_query.py
index 84f47109ec..66a1f37955 100644
--- a/saleor/graphql/product/tests/queries/test_category_query.py
+++ b/saleor/graphql/product/tests/queries/test_category_query.py
@@ -608,7 +608,7 @@ def test_query_category_for_federation(api_client, non_default_category):
],
}
query = """
- query GetCategoryInFederation($representations: [_Any]) {
+ query GetCategoryInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on Category {
diff --git a/saleor/graphql/product/tests/queries/test_collections_query.py b/saleor/graphql/product/tests/queries/test_collections_query.py
index ae11d3cb6e..1eb09e882b 100644
--- a/saleor/graphql/product/tests/queries/test_collections_query.py
+++ b/saleor/graphql/product/tests/queries/test_collections_query.py
@@ -254,7 +254,7 @@ def test_query_collection_for_federation(api_client, published_collection, chann
],
}
query = """
- query GetCollectionInFederation($representations: [_Any]) {
+ query GetCollectionInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on Collection {
diff --git a/saleor/graphql/product/tests/queries/test_product_query.py b/saleor/graphql/product/tests/queries/test_product_query.py
index 2d65b7c70a..aa68c547a5 100644
--- a/saleor/graphql/product/tests/queries/test_product_query.py
+++ b/saleor/graphql/product/tests/queries/test_product_query.py
@@ -2178,7 +2178,7 @@ def test_query_product_media_by_id_zero_size_value_original_image_returned(
QUERY_PRODUCT_IN_FEDERATION = """
-query GetProductInFederation($representations: [_Any]) {
+query GetProductInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on Product {
@@ -2436,7 +2436,7 @@ def test_query_product_media_for_federation(
],
}
query = """
- query GetProductMediaInFederation($representations: [_Any]) {
+ query GetProductMediaInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on ProductMedia {
diff --git a/saleor/graphql/product/tests/queries/test_product_type_query.py b/saleor/graphql/product/tests/queries/test_product_type_query.py
index 81e9e3e622..72bd33cd91 100644
--- a/saleor/graphql/product/tests/queries/test_product_type_query.py
+++ b/saleor/graphql/product/tests/queries/test_product_type_query.py
@@ -579,7 +579,7 @@ def test_query_product_type_for_federation(api_client, product, channel_USD):
],
}
query = """
- query GetProductTypeInFederation($representations: [_Any]) {
+ query GetProductTypeInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on ProductType {
diff --git a/saleor/graphql/product/tests/queries/test_product_variant_query.py b/saleor/graphql/product/tests/queries/test_product_variant_query.py
index f7a1f27f90..b0d73421cc 100644
--- a/saleor/graphql/product/tests/queries/test_product_variant_query.py
+++ b/saleor/graphql/product/tests/queries/test_product_variant_query.py
@@ -659,7 +659,7 @@ def test_fetch_variant_without_sku_anonymous(api_client, product, variant, chann
QUERY_PRODUCT_VARIANT_IN_FEDERATION = """
-query GetProductVariantInFederation($representations: [_Any]) {
+query GetProductVariantInFederation($representations: [_Any!]!) {
_entities(representations: $representations) {
__typename
... on ProductVariant {
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index ada317bcd3..47a6cb4d61 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -1662,7 +1662,7 @@ type Query {
"""External ID of the user."""
externalReference: String
): User @doc(category: "Users")
- _entities(representations: [_Any]): [_Entity]
+ _entities(representations: [_Any!]!): [_Entity]
_service: _Service
}