Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/resolvers/content.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 Union | # from typing import Union | ||||
from .base_node import BaseSWHNode | from .base_node import BaseSWHNode | ||||
from .directory_entry import BaseDirectoryEntryNode | |||||
from .release import BaseReleaseNode | # from .directory_entry import BaseDirectoryEntryNode | ||||
from .search import SearchResultNode | # from .release import BaseReleaseNode | ||||
from .snapshot_branch import BaseSnapshotBranchNode | # from .search import SearchResultNode | ||||
# from .snapshot_branch import BaseSnapshotBranchNode | |||||
from .target import TargetNode | |||||
class BaseContentNode(BaseSWHNode): | class BaseContentNode(BaseSWHNode): | ||||
""" | """ | ||||
Base resolver for all the content nodes | Base resolver for all the content nodes | ||||
""" | """ | ||||
def _get_content_by_hash(self, checksums: dict): | def _get_content_by_hash(self, checksums: dict): | ||||
▲ Show 20 Lines • Show All 62 Lines • ▼ Show 20 Lines | |||||
class TargetContentNode(BaseContentNode): | class TargetContentNode(BaseContentNode): | ||||
""" | """ | ||||
Node resolver for a content requested as a target | Node resolver for a content requested as a target | ||||
""" | """ | ||||
_can_be_null = True | _can_be_null = True | ||||
obj: Union[ | obj: TargetNode | ||||
SearchResultNode, | # Union[ | ||||
BaseDirectoryEntryNode, | # SearchResultNode, | ||||
BaseReleaseNode, | # BaseDirectoryEntryNode, | ||||
BaseSnapshotBranchNode, | # BaseReleaseNode, | ||||
] | # BaseSnapshotBranchNode, | ||||
# ] | |||||
def _get_node_data(self): | def _get_node_data(self): | ||||
return self._get_content_by_hash(checksums={"sha1_git": self.obj.target_hash}) | return self._get_content_by_hash(checksums={"sha1_git": self.obj.target_id}) |