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 swh.graphql.errors import InvalidInputError | from swh.graphql.errors import InvalidInputError | ||||
from swh.model import hashutil | from swh.model import hashutil | ||||
from .base_node import BaseSWHNode | from .base_node import BaseSWHNode | ||||
from .directory_entry import BaseDirectoryEntryNode | from .target import TargetNode | ||||
from .release import BaseReleaseNode | |||||
from .search import SearchResultNode | |||||
from .snapshot_branch import BaseSnapshotBranchNode | |||||
class BaseContentNode(BaseSWHNode): | class BaseContentNode(BaseSWHNode): | ||||
""" | """ | ||||
Base resolver for all the content nodes | Base resolver for all the content nodes | ||||
""" | """ | ||||
def _get_content_by_hashes(self, hashes: dict): | def _get_content_by_hashes(self, hashes: dict): | ||||
▲ Show 20 Lines • Show All 71 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, | |||||
BaseDirectoryEntryNode, | |||||
BaseReleaseNode, | |||||
BaseSnapshotBranchNode, | |||||
] | |||||
def _get_node_data(self): | def _get_node_data(self): | ||||
return self._get_content_by_hashes(hashes={"sha1_git": self.obj.target_hash}) | return self._get_content_by_hashes(hashes={"sha1_git": self.obj.target_id}) |