Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/resolvers/revision.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.utils import utils | from swh.graphql.utils import utils | ||||
from swh.model.model import Revision | from swh.model.model import Revision | ||||
from swh.model.swhids import CoreSWHID, ObjectType | from swh.model.swhids import CoreSWHID, ObjectType | ||||
from swh.storage.interface import PagedResult | from swh.storage.interface import PagedResult | ||||
from .base_connection import BaseConnection | from .base_connection import BaseConnection | ||||
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 BaseRevisionNode(BaseSWHNode): | class BaseRevisionNode(BaseSWHNode): | ||||
""" | """ | ||||
Base resolver for all the revision nodes | Base resolver for all the revision nodes | ||||
""" | """ | ||||
def _get_revision_by_id(self, revision_id): | def _get_revision_by_id(self, revision_id): | ||||
Show All 34 Lines | |||||
class TargetRevisionNode(BaseRevisionNode): | class TargetRevisionNode(BaseRevisionNode): | ||||
""" | """ | ||||
Node resolver for a revision requested as a target | Node resolver for a revision requested as a target | ||||
""" | """ | ||||
_can_be_null = True | _can_be_null = True | ||||
obj: Union[ | obj: TargetNode | ||||
BaseSnapshotBranchNode, | |||||
BaseReleaseNode, | |||||
BaseDirectoryEntryNode, | |||||
SearchResultNode, | |||||
] | |||||
def _get_node_data(self): | def _get_node_data(self): | ||||
# self.obj.target_hash is the requested revision id | return self._get_revision_by_id(self.obj.target_id) | ||||
return self._get_revision_by_id(self.obj.target_hash) | |||||
class ParentRevisionConnection(BaseConnection): | class ParentRevisionConnection(BaseConnection): | ||||
""" | """ | ||||
Connection resolver for parent revisions in a revision | Connection resolver for parent revisions in a revision | ||||
""" | """ | ||||
obj: BaseRevisionNode | obj: BaseRevisionNode | ||||
Show All 35 Lines |