Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/resolvers/resolver_factory.py
| # Copyright (C) 2022 The Software Heritage developers | # Copyright (C) 2022 The Software Heritage developers | ||||
| # See the AUTHORS file at the top-level directory of this distribution | # See the AUTHORS file at the top-level directory of this distribution | ||||
| # License: GNU General Public License version 3, or any later version | # License: GNU General Public License version 3, or any later version | ||||
| # See top-level LICENSE file for more information | # See top-level LICENSE file for more information | ||||
| from typing import ClassVar, Dict, Type | from typing import ClassVar, Dict, Type | ||||
| from swh.graphql.errors import NullableObjectError | from swh.graphql.errors import NullableObjectError | ||||
| from .base_connection import BaseConnection, BaseList | from .base_connection import BaseConnection, BaseList | ||||
| from .base_node import BaseNode | from .base_node import BaseNode | ||||
| from .content import ContentNode, HashContentNode, TargetContentNode | from .content import ContentNode, HashContentNode, TargetContentNode | ||||
| from .directory import DirectoryNode, RevisionDirectoryNode, TargetDirectoryNode | from .directory import DirectoryNode, RevisionDirectoryNode, TargetDirectoryNode | ||||
| from .directory_entry import DirectoryEntryConnection, DirectoryEntryNode | from .directory_entry import DirectoryEntryConnection, DirectoryEntryNode | ||||
| from .origin import OriginConnection, OriginNode, TargetOriginNode | from .origin import OriginConnection, OriginNode, TargetOriginNode | ||||
| from .person import ReleaseAuthorList, RevisionAuthorList, RevisionCommitterList | |||||
| from .release import ReleaseNode, TargetReleaseNode | from .release import ReleaseNode, TargetReleaseNode | ||||
| from .revision import ( | from .revision import ( | ||||
| LogRevisionConnection, | LogRevisionConnection, | ||||
| ParentRevisionConnection, | ParentRevisionConnection, | ||||
| RevisionNode, | RevisionNode, | ||||
| TargetRevisionNode, | TargetRevisionNode, | ||||
| ) | ) | ||||
| from .search import ResolveSwhidList, SearchConnection | from .search import ResolveSwhidList, SearchConnection | ||||
| ▲ Show 20 Lines • Show All 76 Lines • ▼ Show 20 Lines | def create(cls, connection_type: str, obj, info, *args, **kw): | ||||
| if not resolver: | if not resolver: | ||||
| raise AttributeError(f"Invalid connection type: {connection_type}") | raise AttributeError(f"Invalid connection type: {connection_type}") | ||||
| return resolver(obj, info, *args, **kw) | return resolver(obj, info, *args, **kw) | ||||
| class SimpleListFactory: | class SimpleListFactory: | ||||
| mapping: ClassVar[Dict[str, Type[BaseList]]] = { | mapping: ClassVar[Dict[str, Type[BaseList]]] = { | ||||
| "resolve-swhid": ResolveSwhidList, | "resolve-swhid": ResolveSwhidList, | ||||
| "revision-author": RevisionAuthorList, | |||||
| "revision-committer": RevisionCommitterList, | |||||
| "release-author": ReleaseAuthorList, | |||||
| } | } | ||||
| @classmethod | @classmethod | ||||
| def create(cls, list_type: str, obj, info, *args, **kw): | def create(cls, list_type: str, obj, info, *args, **kw): | ||||
| resolver = cls.mapping.get(list_type) | resolver = cls.mapping.get(list_type) | ||||
| if not resolver: | if not resolver: | ||||
| raise AttributeError(f"Invalid list type: {list_type}") | raise AttributeError(f"Invalid list type: {list_type}") | ||||
| # invoke the get_results method to return the list | # invoke the get_results method to return the list | ||||
| return resolver(obj, info, *args, **kw).get_results() | return resolver(obj, info, *args, **kw).get_results() | ||||