Skip to content

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

Rename _resolve_nodes and add typing in csv export mutations file

IKarbowiak306defe01bd3
diff --git a/saleor/graphql/csv/mutations.py b/saleor/graphql/csv/mutations.py
index cf19c8b1fd..3fe49a549b 100644
--- a/saleor/graphql/csv/mutations.py
+++ b/saleor/graphql/csv/mutations.py
@@ -1,3 +1,5 @@
+from typing import Dict, List, Mapping, Union
+
import graphene
from django.core.exceptions import ValidationError
@@ -9,7 +11,7 @@ from ..core.mutations import BaseMutation
from ..core.types.common import CsvError
from ..product.filters import ProductFilterInput
from ..product.types import Product
-from ..utils import _resolve_nodes
+from ..utils import resolve_global_ids_to_primary_keys
from .enums import ExportScope
from .types import Job
@@ -54,16 +56,16 @@ class ExportProducts(BaseMutation):
return cls(job=job)
@classmethod
- def get_products_scope(cls, info, input):
+ def get_products_scope(cls, info, input) -> Mapping[str, Union[list, dict, str]]:
scope = input["scope"]
- if scope == ExportScope.IDS.value:
+ if scope == ExportScope.IDS.value: # type: ignore
return cls.clean_ids(input)
- elif scope == ExportScope.FILTER.value:
+ elif scope == ExportScope.FILTER.value: # type: ignore
return cls.clean_filter(input)
return {"all": ""}
@staticmethod
- def clean_ids(input):
+ def clean_ids(input) -> Dict[str, List[str]]:
ids = input.get("ids", [])
if not ids:
raise ValidationError(
@@ -74,11 +76,11 @@ class ExportProducts(BaseMutation):
)
}
)
- _, pks = _resolve_nodes(ids, graphene_type=Product)
+ _, pks = resolve_global_ids_to_primary_keys(ids, graphene_type=Product)
return {"ids": pks}
@staticmethod
- def clean_filter(input):
+ def clean_filter(input) -> Dict[str, dict]:
filter = input.get("filter")
if not filter:
raise ValidationError(
diff --git a/saleor/graphql/utils.py b/saleor/graphql/utils.py
index 6dca88f7dc..6e38884ffc 100644
--- a/saleor/graphql/utils.py
+++ b/saleor/graphql/utils.py
@@ -32,7 +32,7 @@ def _check_graphene_type(requested_graphene_type, received_type):
).format(str(requested_graphene_type))
-def _resolve_nodes(ids, graphene_type=None):
+def resolve_global_ids_to_primary_keys(ids, graphene_type=None):
pks = []
invalid_ids = []
used_type = graphene_type
@@ -76,7 +76,7 @@ def get_nodes(
If the `graphene_type` is of type str, the model keyword argument must be provided.
"""
- nodes_type, pks = _resolve_nodes(ids, graphene_type)
+ nodes_type, pks = resolve_global_ids_to_primary_keys(ids, graphene_type)
# If `graphene_type` was not provided, check if all resolved types are
# the same. This prevents from accidentally mismatching IDs of different