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 swh.graphql.backends import archive | from swh.graphql.backends import archive | ||||
from .base_node import BaseSWHNode | from .base_node import BaseSWHNode | ||||
from .directory_entry import DirectoryEntryNode | from .directory_entry import DirectoryEntryNode | ||||
from .release import BaseReleaseNode | from .release import BaseReleaseNode | ||||
from .snapshot_branch import SnapshotBranchNode | |||||
class BaseContentNode(BaseSWHNode): | class BaseContentNode(BaseSWHNode): | ||||
""" | """ | ||||
Base resolver for all the content nodes | Base resolver for all the content nodes | ||||
""" | """ | ||||
def _get_content_by_id(self, content_id): | def _get_content_by_id(self, content_id): | ||||
Show All 25 Lines | |||||
class TargetContentNode(BaseContentNode): | class TargetContentNode(BaseContentNode): | ||||
""" | """ | ||||
Node resolver for a content requested from a | Node resolver for a content requested from a | ||||
directory entry or from a release target | directory entry or from a release target | ||||
""" | """ | ||||
obj: Union[DirectoryEntryNode, BaseReleaseNode] | obj: Union[DirectoryEntryNode, BaseReleaseNode, SnapshotBranchNode] | ||||
def _get_node_data(self): | def _get_node_data(self): | ||||
content_id = self.obj.targetHash | content_id = self.obj.targetHash | ||||
return self._get_content_by_id(content_id) | return self._get_content_by_id(content_id) |