Skip to content

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

Remove graphene federation dependency (#9184)

Rafał Pitońdd43364f784a
diff --git a/.isort.cfg b/.isort.cfg
index b4042edb7b..a07b817657 100644
--- a/.isort.cfg
+++ b/.isort.cfg
@@ -1,2 +1,2 @@
[settings]
-known_third_party = Adyen,PIL,authorizenet,babel,boto3,botocore,braintree,celery,cryptography,dateutil,dj_database_url,dj_email_url,django,django_cache_url,django_countries,django_filters,django_measurement,django_prices,django_prices_openexchangerates,django_prices_vatlayer,draftjs_sanitizer,faker,freezegun,google,google_measurement_protocol,graphene,graphene_federation,graphql,graphql_relay,html2text,html_to_draftjs,i18naddress,jaeger_client,jwt,kombu,lxml,markdown,measurement,micawber,mptt,oauthlib,openpyxl,opentracing,petl,phonenumber_field,phonenumbers,pkg_resources,posuto,prices,promise,pybars,pytest,pythonjsonlogger,pytimeparse,pytz,razorpay,requests,sendgrid,sentry_sdk,storages,stripe,urllib3,uvicorn,versatileimagefield,weasyprint
+known_third_party = Adyen,PIL,authorizenet,babel,boto3,botocore,braintree,celery,cryptography,dateutil,dj_database_url,dj_email_url,django,django_cache_url,django_countries,django_filters,django_measurement,django_prices,django_prices_openexchangerates,django_prices_vatlayer,draftjs_sanitizer,faker,freezegun,google,google_measurement_protocol,graphene,graphql,graphql_relay,html2text,html_to_draftjs,i18naddress,jaeger_client,jwt,kombu,lxml,markdown,measurement,micawber,mptt,oauthlib,openpyxl,opentracing,petl,phonenumber_field,phonenumbers,pkg_resources,posuto,prices,promise,pybars,pytest,pythonjsonlogger,pytimeparse,pytz,razorpay,requests,sendgrid,sentry_sdk,storages,stripe,urllib3,uvicorn,versatileimagefield,weasyprint
diff --git a/CHANGELOG.md b/CHANGELOG.md
index feebe52bdb..c378fde979 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,6 +11,8 @@ All notable, unreleased changes to this project will be documented in this file.
- Filter Customer/Order/Sale/Product/ProductVariant by datetime of last modification - #9137 by @rafalp
- Add possibility for plugins to execute code before each mutation - #9193 by @NyanKiyoshi
- Add support for hiding plugins - #9219 by @NyanKiyoshi
+- Remove `graphene-federation` dependency - #9184 by @rafalp
+
# 3.1.0
diff --git a/poetry.lock b/poetry.lock
index e4dc405c5d..c46dbef869 100644
--- a/poetry.lock
+++ b/poetry.lock
@@ -1100,17 +1100,6 @@ dev = ["black (==19.10b0)", "flake8 (==3.7.9)", "flake8-black (==0.1.1)", "flake
rest_framework = ["djangorestframework (>=3.6.3)"]
test = ["pytest (>=3.6.3)", "pytest-cov", "coveralls", "mock", "pytz", "pytest-django (>=3.3.2)", "djangorestframework (>=3.6.3)", "django-filter (<2)", "django-filter (>=2)"]
-[[package]]
-name = "graphene-federation"
-version = "0.1.0"
-description = "Federation implementation for graphene"
-category = "main"
-optional = false
-python-versions = "*"
-
-[package.dependencies]
-graphene = ">=2.1.0,<3"
-
[[package]]
name = "graphql-core"
version = "2.3.2"
@@ -2772,7 +2761,7 @@ python-versions = "*"
[metadata]
lock-version = "1.1"
python-versions = "~3.9"
-content-hash = "f82542398fb3311a48f2972228b2cc5b56ed297038e43fd86b0ac7b12996e0d9"
+content-hash = "df25060b9b384f5522faf88e936a5498cde70f9747ffcc1aa57b79388defedba"
[metadata.files]
adyen = [
@@ -3339,9 +3328,6 @@ graphene-django = [
{file = "graphene-django-2.15.0.tar.gz", hash = "sha256:b78c9b05bc899016b9cc5bf13faa1f37fe1faa8c5407552c6ddd1a28f46fc31a"},
{file = "graphene_django-2.15.0-py2.py3-none-any.whl", hash = "sha256:02671d195f0c09c8649acff2a8f4ad4f297d0f7d98ea6e6cdf034b81bab92880"},
]
-graphene-federation = [
- {file = "graphene-federation-0.1.0.tar.gz", hash = "sha256:e44e8e354d0c8eeb03547d5c262d01c868d4ea7d1458512c994176eed80fd2bf"},
-]
graphql-core = [
{file = "graphql-core-2.3.2.tar.gz", hash = "sha256:aac46a9ac524c9855910c14c48fc5d60474def7f99fd10245e76608eba7af746"},
{file = "graphql_core-2.3.2-py2.py3-none-any.whl", hash = "sha256:44c9bac4514e5e30c5a595fac8e3c76c1975cae14db215e8174c7fe995825bad"},
diff --git a/pyproject.toml b/pyproject.toml
index e0ddd76a0f..a22b9311e2 100644
--- a/pyproject.toml
+++ b/pyproject.toml
@@ -32,7 +32,6 @@ documentation = "https://docs.saleor.io/"
google-cloud-storage = "^2.0.0"
google-i18n-address = "^2.3.5"
google-measurement-protocol = "^1.0"
- graphene-federation = "^0.1.0"
html-to-draftjs = "^1.0.1"
markdown = "^3.1.1"
maxminddb = ">=1.5.4,<3.0.0"
@@ -67,6 +66,7 @@ documentation = "https://docs.saleor.io/"
django-celery-beat = "^2.2.1"
posuto = "^2021.10.0"
cryptography = "^36.0.0"
+ graphene = "<3.0"
[tool.poetry.dependencies.celery]
version = ">=4.4.5,<6.0.0"
diff --git a/requirements.txt b/requirements.txt
index 95a24dfc50..97202657c0 100644
--- a/requirements.txt
+++ b/requirements.txt
@@ -59,7 +59,6 @@ google-i18n-address==2.5.0
google-measurement-protocol==1.1.0
google-resumable-media==2.2.1; python_version >= "3.7"
googleapis-common-protos==1.55.0; python_version >= "3.7"
-graphene-federation==0.1.0
graphene==2.1.9
graphql-core==2.3.2
graphql-relay==2.0.1
diff --git a/requirements_dev.txt b/requirements_dev.txt
index 67b72fcc0a..185f707cce 100644
--- a/requirements_dev.txt
+++ b/requirements_dev.txt
@@ -1,6 +1,6 @@
adyen==4.0.0
amqp==5.0.9; python_version >= "3.7"
-aniso8601==7.0.0
+aniso8601==7.0.0; python_version >= "3.6" and python_version < "4.0"
asgiref==3.5.0; python_version >= "3.7" and python_version < "4.0"
astroid==2.9.3; python_full_version >= "3.6.2"
atomicwrites==1.4.0; python_version >= "3.7" and python_full_version < "3.0.0" and sys_platform == "win32" and python_version < "4.0" or sys_platform == "win32" and python_version >= "3.7" and python_full_version >= "3.4.0" and python_version < "4.0"
@@ -80,10 +80,9 @@ google-measurement-protocol==1.1.0
google-resumable-media==2.2.1; python_version >= "3.7"
googleapis-common-protos==1.55.0; python_version >= "3.7"
graphene-django==2.15.0; python_version >= "3.6" and python_version < "4.0"
-graphene-federation==0.1.0
-graphene==2.1.9; python_version >= "3.6" and python_version < "4.0"
+graphene==2.1.9
graphql-core==2.3.2; python_version >= "3.6" and python_version < "4.0"
-graphql-relay==2.0.1
+graphql-relay==2.0.1; python_version >= "3.6" and python_version < "4.0"
grpc-google-iam-v1==0.12.3; python_version >= "3.6"
grpcio-status==1.44.0; python_version >= "3.7"
grpcio==1.44.0; python_version >= "3.7"
@@ -179,12 +178,12 @@ razorpay==1.3.0
redis==4.1.4; python_version >= "3.6"
requests==2.27.1; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.6.0")
rsa==4.8; python_version >= "3.6" and python_version < "4" and (python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.6.0" and python_version >= "3.7")
-rx==1.6.1; python_version >= "3.6" and python_version < "4.0"
+rx==1.6.1
s3transfer==0.5.1; python_version >= "3.6"
sendgrid==6.9.6; (python_version >= "2.7" and python_full_version < "3.0.0") or (python_full_version >= "3.5.0")
sentry-sdk==1.5.6
singledispatch==3.7.0; python_version >= "3.6" and python_version < "4.0"
-six==1.16.0; python_full_version >= "3.6.1" and python_version < "3.10" and python_version >= "3.7" and (python_version >= "3.5" and python_full_version < "3.0.0" or python_full_version >= "3.3.0" and python_version >= "3.5") and (python_version >= "3.6" and python_full_version < "3.0.0" and python_version < "4.0" or python_version >= "3.6" and python_version < "4.0" and python_full_version >= "3.3.0") and (python_version >= "2.7" and python_full_version < "3.0.0" or python_full_version >= "3.3.0")
+six==1.16.0; python_full_version >= "3.6.1" and python_version < "3.10" and python_version >= "3.7" and (python_version >= "3.5" and python_full_version < "3.0.0" or python_full_version >= "3.3.0" and python_version >= "3.5") and (python_version >= "3.6" and python_full_version < "3.0.0" and python_version < "4.0" or python_version >= "3.6" and python_version < "4.0" and python_full_version >= "3.3.0")
smmap==5.0.0; python_version >= "3.7" and python_full_version < "3.0.0" or python_full_version >= "3.4.0" and python_version < "3.10" and python_version >= "3.7"
snowballstemmer==2.2.0; python_version >= "3.6"
soupsieve==2.3.1; python_version >= "3.6"
diff --git a/saleor/graphql/account/types.py b/saleor/graphql/account/types.py
index 0d416b287d..4fbe2d179b 100644
--- a/saleor/graphql/account/types.py
+++ b/saleor/graphql/account/types.py
@@ -4,7 +4,6 @@ import graphene
from django.contrib.auth import get_user_model
from django.contrib.auth import models as auth_models
from graphene import relay
-from graphene_federation import key
from ...account import models
from ...checkout.utils import get_user_checkout
@@ -20,7 +19,7 @@ from ..checkout.types import Checkout
from ..core.connection import CountableConnection, create_connection_slice
from ..core.descriptions import DEPRECATED_IN_3X_FIELD
from ..core.enums import LanguageCodeEnum
-from ..core.federation import resolve_federation_references
+from ..core.federation import federated_entity, resolve_federation_references
from ..core.fields import ConnectionField
from ..core.scalars import UUID
from ..core.types import CountryDisplay, Image, ModelObjectType, Permission
@@ -49,7 +48,7 @@ class AddressInput(graphene.InputObjectType):
phone = graphene.String(description="Phone number.")
-@key(fields="id")
+@federated_entity("id")
class Address(ModelObjectType):
id = graphene.GlobalID(required=True)
first_name = graphene.String(required=True)
@@ -215,8 +214,8 @@ class UserPermission(Permission):
return groups
-@key(fields="id")
-@key(fields="email")
+@federated_entity("id")
+@federated_entity("email")
class User(ModelObjectType):
id = graphene.GlobalID(required=True)
email = graphene.String(required=True)
@@ -497,7 +496,7 @@ class StaffNotificationRecipient(graphene.ObjectType):
return root.get_email()
-@key(fields="id")
+@federated_entity("id")
class Group(ModelObjectType):
id = graphene.GlobalID(required=True)
name = graphene.String(required=True)
diff --git a/saleor/graphql/api.py b/saleor/graphql/api.py
index 44e43a1a13..667b169cc0 100644
--- a/saleor/graphql/api.py
+++ b/saleor/graphql/api.py
@@ -8,7 +8,7 @@ from .attribute.schema import AttributeMutations, AttributeQueries
from .channel.schema import ChannelMutations, ChannelQueries
from .checkout.schema import CheckoutMutations, CheckoutQueries
from .core.enums import unit_enums
-from .core.federation import build_federated_schema
+from .core.federation.schema import build_federated_schema
from .core.schema import CoreMutations, CoreQueries
from .csv.schema import CsvMutations, CsvQueries
from .discount.schema import DiscountMutations, DiscountQueries
@@ -83,4 +83,4 @@ class Mutation(
pass
-schema = build_federated_schema(Query, mutation=Mutation, types=unit_enums)
+schema = build_federated_schema(query=Query, mutation=Mutation, types=unit_enums)
diff --git a/saleor/graphql/app/types.py b/saleor/graphql/app/types.py
index 332dfbf6da..ca4ccfe40e 100644
--- a/saleor/graphql/app/types.py
+++ b/saleor/graphql/app/types.py
@@ -1,7 +1,6 @@
from typing import List
import graphene
-from graphene_federation import key
from ...app import models
from ...app.types import AppExtensionTarget
@@ -9,7 +8,7 @@ from ...core.exceptions import PermissionDenied
from ...core.permissions import AppPermission
from ..core.connection import CountableConnection
from ..core.descriptions import ADDED_IN_31, PREVIEW_FEATURE
-from ..core.federation import resolve_federation_references
+from ..core.federation import federated_entity, resolve_federation_references
from ..core.types import ModelObjectType, Permission
from ..core.types.common import Job
from ..decorators import permission_required
@@ -163,7 +162,7 @@ class AppToken(graphene.ObjectType):
return root.auth_token[-4:]
-@key(fields="id")
+@federated_entity("id")
class App(ModelObjectType):
id = graphene.GlobalID(required=True)
permissions = graphene.List(
diff --git a/saleor/graphql/core/federation.py b/saleor/graphql/core/federation.py
deleted file mode 100644
index e8a78f1d5a..0000000000
--- a/saleor/graphql/core/federation.py
+++ /dev/null
@@ -1,95 +0,0 @@
-from collections import defaultdict
-
-from django.conf import settings
-from graphene.utils.str_converters import to_snake_case
-from graphene_federation import build_schema
-from graphene_federation.entity import custom_entities
-from graphql import GraphQLError
-
-from ..channel import ChannelContext
-from .utils import from_global_id_or_error
-
-
-def build_federated_schema(query=None, mutation=None, **kwargs):
- schema = build_schema(query, mutation, **kwargs)
- set_entity_resolver(schema)
- set_entity_type_resolver(schema)
- return schema
-
-
-def set_entity_resolver(schema):
- """Set type resolver aware of ChannelContext on _Entity union."""
- entity = schema.get_type("Query")
- entity.fields["_entities"].resolver = resolve_entities
-
-
-def resolve_entities(parent, info, representations):
- max_representations = settings.FEDERATED_QUERY_MAX_ENTITIES
- if max_representations and len(representations) > max_representations:
- representations_count = len(representations)
- raise GraphQLError(
- f"Federated query exceeded entity limit: {representations_count} "
- f"items requested over {max_representations}."
- )
-
- resolvers = {}
- for representation in representations:
- if representation["__typename"] not in resolvers:
- try:
- model = custom_entities[representation["__typename"]]
- resolvers[representation["__typename"]] = getattr(
- model, "_%s__resolve_references" % representation["__typename"]
- )
- except AttributeError:
- pass
-
- batches = defaultdict(list)
- for representation in representations:
- model = custom_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)
-
- entities = []
- for typename, batch in batches.items():
- if typename not in resolvers:
- continue
-
- resolver = resolvers[typename]
- entities.extend(resolver(batch, info))
-
- return entities
-
-
-def set_entity_type_resolver(schema):
- """Set type resolver aware of ChannelContext on _Entity union."""
- entity = schema.get_type("_Entity")
-
- def resolve_entity_type(instance, info):
- # Use new strategy to resolve GraphQL Type for `ObjectType`
- if isinstance(instance, ChannelContext):
- model = type(instance.node)
- else:
- model = type(instance)
-
- model_type = schema.get_type(model._meta.object_name)
- if model_type is None:
- raise ValueError(
- f"GraphQL type for model {model} could not be found. "
- "This is caused by federated type missing get_model method."
- )
-
- return model_type
-
- entity.resolve_type = resolve_entity_type
-
-
-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
- ]
- 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/__init__.py b/saleor/graphql/core/federation/__init__.py
new file mode 100644
index 0000000000..89f12e9555
--- /dev/null
+++ b/saleor/graphql/core/federation/__init__.py
@@ -0,0 +1,4 @@
+from .entities import federated_entity
+from .resolvers import resolve_federation_references
+
+__all__ = ["federated_entity", "resolve_federation_references"]
diff --git a/saleor/graphql/core/federation/entities.py b/saleor/graphql/core/federation/entities.py
new file mode 100644
index 0000000000..9217c2c1ab
--- /dev/null
+++ b/saleor/graphql/core/federation/entities.py
@@ -0,0 +1,26 @@
+from typing import Dict
+
+import graphene
+
+federated_entities: Dict[str, graphene.ObjectType] = {}
+
+
+def federated_entity(key_fields: str):
+ def federate_entity(graphql_type: graphene.ObjectType):
+ # Add entity to registry
+ federated_entities[graphql_type.__name__] = graphql_type
+
+ # Override it's SDL to contain federation's @key directive
+ type_sdl: str = getattr(graphql_type, "_sdl", "")
+ key_sdl = f'@key(fields: "{key_fields}")'
+
+ if type_sdl:
+ type_sdl = f"{key_sdl} {type_sdl}"
+ else:
+ type_sdl = key_sdl
+
+ setattr(graphql_type, "_sdl", type_sdl)
+
+ return graphql_type
+
+ return federate_entity
diff --git a/saleor/graphql/core/federation/resolvers.py b/saleor/graphql/core/federation/resolvers.py
new file mode 100644
index 0000000000..9f815012c2
--- /dev/null
+++ b/saleor/graphql/core/federation/resolvers.py
@@ -0,0 +1,10 @@
+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
+ ]
+ 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
new file mode 100644
index 0000000000..227870c831
--- /dev/null
+++ b/saleor/graphql/core/federation/schema.py
@@ -0,0 +1,161 @@
+from collections import defaultdict
+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 ...channel import ChannelContext
+from .entities import federated_entities
+
+
+class _Any(graphene.Scalar):
+ """_Any value scalar as defined by Federation spec."""
+
+ __typename = graphene.String(required=True)
+
+ @staticmethod
+ def serialize(any_value: Any):
+ return any_value
+
+ @staticmethod
+ def parse_literal(any_value: Any):
+ raise any_value
+
+ @staticmethod
+ def parse_value(any_value: Any):
+ return any_value
+
+
+class _Entity(graphene.Union):
+ """_Entity union as defined by Federation spec."""
+
+ class Meta:
+ types = tuple(federated_entities.values())
+
+
+class _Service(graphene.ObjectType):
+ """_Service manifest as defined by Federation spec."""
+
+ sdl = graphene.String()
+
+
+def build_federated_schema(query=None, mutation=None, types=None):
+ """Create GraphQL schema that supports Apollo Federation."""
+ schema = graphene.Schema(
+ query=query,
+ mutation=mutation,
+ types=list(types) + [_Any, _Entity, _Service],
+ )
+
+ entity_type = schema.get_type("_Entity")
+ entity_type.resolve_type = create_entity_type_resolver(schema)
+
+ query_type = schema.get_type("Query")
+ query_type.fields["_entities"] = GraphQLField(
+ GraphQLList(entity_type),
+ args={
+ "representations": GraphQLArgument(
+ GraphQLList(schema.get_type("_Any")),
+ ),
+ },
+ resolver=resolve_entities,
+ )
+ query_type.fields["_service"] = GraphQLField(
+ schema.get_type("_Service"),
+ resolver=create_service_sdl_resolver(schema),
+ )
+
+ return schema
+
+
+def create_entity_type_resolver(schema):
+ """Create type resolver aware of ChannelContext on _Entity union."""
+
+ def resolve_entity_type(instance, info):
+ # Use new strategy to resolve GraphQL Type for `ObjectType`
+ if isinstance(instance, ChannelContext):
+ model = type(instance.node)
+ else:
+ model = type(instance)
+
+ model_type = schema.get_type(model._meta.object_name)
+ if model_type is None:
+ raise ValueError(
+ f"GraphQL type for model {model} could not be found. "
+ "This is caused by federated type missing get_model method."
+ )
+
+ return model_type
+
+ return resolve_entity_type
+
+
+def resolve_entities(_, info, *, representations):
+ max_representations = settings.FEDERATED_QUERY_MAX_ENTITIES
+ if max_representations and len(representations) > max_representations:
+ representations_count = len(representations)
+ raise GraphQLError(
+ f"Federated query exceeded entity limit: {representations_count} "
+ f"items requested over {max_representations}."
+ )
+
+ resolvers = {}
+ for representation in representations:
+ if representation["__typename"] not in resolvers:
+ try:
+ model = federated_entities[representation["__typename"]]
+ resolvers[representation["__typename"]] = getattr(
+ model, "_%s__resolve_references" % 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)
+
+ entities = []
+ for typename, batch in batches.items():
+ if typename not in resolvers:
+ continue
+
+ resolver = resolvers[typename]
+ entities.extend(resolver(batch, info))
+
+ return entities
+
+
+def create_service_sdl_resolver(schema):
+ # Render schema to string
+ federated_schema_sdl = str(schema)
+
+ # Remove "schema { ... }"
+ schema_start = federated_schema_sdl.find("schema {")
+ schema_end = federated_schema_sdl.find("}", schema_start) + 1
+ federated_schema_sdl = (
+ federated_schema_sdl[:schema_start] + federated_schema_sdl[schema_end:]
+ ).lstrip()
+
+ # Append "@key" to federated types
+ for type_name, graphql_type in federated_entities.items():
+ type_sdl = f"type {type_name} "
+ type_start = federated_schema_sdl.find(type_sdl)
+ type_fields_open = federated_schema_sdl.find("{", type_start)
+ federated_schema_sdl = (
+ federated_schema_sdl[:type_fields_open]
+ + getattr(graphql_type, "_sdl")
+ + " "
+ + federated_schema_sdl[type_fields_open:]
+ )
+
+ def resolve_service_sdl(*_args):
+ return {"sdl": federated_schema_sdl}
+
+ return resolve_service_sdl
diff --git a/saleor/graphql/page/types.py b/saleor/graphql/page/types.py
index 51a3126f06..384a457578 100644
--- a/saleor/graphql/page/types.py
+++ b/saleor/graphql/page/types.py
@@ -1,7 +1,6 @@
from typing import List
import graphene
-from graphene_federation import key
from ...attribute import models as attribute_models
from ...core.permissions import PagePermissions
@@ -14,7 +13,7 @@ from ..core.connection import (
filter_connection_queryset,
)
from ..core.descriptions import DEPRECATED_IN_3X_FIELD
-from ..core.federation import resolve_federation_references
+from ..core.federation import federated_entity, resolve_federation_references
from ..core.fields import FilterConnectionField
from ..core.types import ModelObjectType
from ..decorators import permission_required
@@ -29,7 +28,7 @@ from .dataloaders import (
)
-@key(fields="id")
+@federated_entity("id")
class PageType(ModelObjectType):
id = graphene.GlobalID(required=True)
name = graphene.String(required=True)
diff --git a/saleor/graphql/product/types/products.py b/saleor/graphql/product/types/products.py
index c13cad9f85..c5196edbbf 100644
--- a/saleor/graphql/product/types/products.py
+++ b/saleor/graphql/product/types/products.py
@@ -6,7 +6,6 @@ from typing import List, Optional
import graphene
from django_countries.fields import Country
from graphene import relay
-from graphene_federation import key
from ....attribute import models as attribute_models
from ....core.permissions import (
@@ -53,7 +52,7 @@ from ...core.descriptions import (
PREVIEW_FEATURE,
)
from ...core.enums import ReportingPeriod
-from ...core.federation import resolve_federation_references
+from ...core.federation import federated_entity, resolve_federation_references
from ...core.fields import ConnectionField, FilterConnectionField
from ...core.types import (
Image,
@@ -218,7 +217,7 @@ class PreorderData(graphene.ObjectType):
return root.global_sold_units
-@key(fields="id channel")
+@federated_entity("id channel")
class ProductVariant(ChannelContextTypeWithMetadata, ModelObjectType):
id = graphene.GlobalID(required=True)
name = graphene.String(required=True)
@@ -723,7 +722,7 @@ class ProductVariantCountableConnection(CountableConnection):
node = ProductVariant
-@key(fields="id channel")
+@federated_entity("id channel")
class Product(ChannelContextTypeWithMetadata, ModelObjectType):
id = graphene.GlobalID(required=True)
seo_title = graphene.String()
@@ -1200,7 +1199,7 @@ class ProductCountableConnection(CountableConnection):
node = Product
-@key(fields="id")
+@federated_entity("id")
class ProductType(ModelObjectType):
id = graphene.GlobalID(required=True)
name = graphene.String(required=True)
@@ -1369,7 +1368,7 @@ class ProductTypeCountableConnection(CountableConnection):
node = ProductType
-@key(fields="id channel")
+@federated_entity("id channel")
class Collection(ChannelContextTypeWithMetadata, ModelObjectType):
id = graphene.GlobalID(required=True)
seo_title = graphene.String()
@@ -1484,7 +1483,7 @@ class CollectionCountableConnection(CountableConnection):
node = Collection
-@key(fields="id")
+@federated_entity("id")
class Category(ModelObjectType):
id = graphene.GlobalID(required=True)
seo_title = graphene.String()
@@ -1603,7 +1602,7 @@ class CategoryCountableConnection(CountableConnection):
node = Category
-@key(fields="id")
+@federated_entity("id")
class ProductMedia(ModelObjectType):
id = graphene.GlobalID(required=True)
sort_order = graphene.Int()