Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Upgrade gql-optimizer to 0.6.0
NyanKiyoshifdb78dad9b76
diff --git a/saleor/graphql/product/resolvers.py b/saleor/graphql/product/resolvers.pyindex 95a7189baa..733833e65f 100644--- a/saleor/graphql/product/resolvers.py+++ b/saleor/graphql/product/resolvers.py@@ -124,11 +124,11 @@ def resolve_products(qs = filter_products_by_attributes(qs, attributes)if categories:- categories = get_nodes(categories, "Category")+ categories = get_nodes(categories, "Category", models.Category)qs = filter_products_by_categories(qs, categories)if collections:- collections = get_nodes(collections, "Collection")+ collections = get_nodes(collections, "Collection", models.Collection)qs = filter_products_by_collections(qs, collections)if stock_availability:qs = filter_products_by_stock_availability(qs, stock_availability)diff --git a/saleor/graphql/utils.py b/saleor/graphql/utils.pyindex 67e7ae8776..dee24db1ae 100644--- a/saleor/graphql/utils.py+++ b/saleor/graphql/utils.py@@ -1,3 +1,5 @@+from typing import Union+import graphenefrom django.db.models import Qfrom django.utils import timezone@@ -17,9 +19,8 @@ registry = get_global_registry()def get_database_id(info, node_id, only_type):"""Get a database ID from a node ID of given type."""_type, _id = graphene.relay.Node.from_global_id(node_id)- graphene_type = info.schema.get_type(_type).graphene_type- if graphene_type != only_type:- raise AssertionError("Must receive a %s id." % only_type._meta.name)+ if _type != str(only_type):+ raise AssertionError("Must receive a %s id." % str(only_type))return _id@@ -62,13 +63,17 @@ def _resolve_graphene_type(type_name):raise AssertionError("Could not resolve the type {}".format(type_name))-def get_nodes(ids, graphene_type=None, qs=None):+def get_nodes(+ ids, graphene_type: Union[graphene.ObjectType, str] = None, model=None, qs=None+):"""Return a list of nodes.If the `graphene_type` argument is provided, the IDs will be validatedagainst this type. If the type was not provided, it will be looked up inthe Graphene's registry. Raises an error if not all IDs are of the sametype.++ If the `graphene_type` is of type str, the model keyword argument must be provided."""nodes_type, pks = _resolve_nodes(ids, graphene_type)@@ -78,7 +83,7 @@ def get_nodes(ids, graphene_type=None, qs=None):if nodes_type and not graphene_type:graphene_type = _resolve_graphene_type(nodes_type)- if qs is None:+ if qs is None and not isinstance(graphene_type, str):qs = graphene_type._meta.model.objectsnodes = list(qs.filter(pk__in=pks))