Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/resolvers/snapshot.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 NullableObjectError | from swh.graphql.errors import NullableObjectError | ||||
from swh.graphql.utils import utils | from swh.graphql.utils import utils | ||||
from swh.model.model import Snapshot | from swh.model.model import Snapshot | ||||
from swh.model.swhids import ObjectType | from swh.model.swhids import 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 .origin import OriginNode | from .origin import OriginNode | ||||
from .search import SearchResultNode | from .target import TargetNode | ||||
from .visit_status import BaseVisitStatusNode | from .visit_status import BaseVisitStatusNode | ||||
class BaseSnapshotNode(BaseSWHNode): | class BaseSnapshotNode(BaseSWHNode): | ||||
""" | """ | ||||
Base resolver for all the snapshot nodes | Base resolver for all the snapshot nodes | ||||
""" | """ | ||||
Show All 40 Lines | def _get_node_data(self): | ||||
return self._get_snapshot_by_id(snapshot_id) | return self._get_snapshot_by_id(snapshot_id) | ||||
class TargetSnapshotNode(BaseSnapshotNode): | class TargetSnapshotNode(BaseSnapshotNode): | ||||
""" | """ | ||||
Node resolver for a snapshot requested as a target | Node resolver for a snapshot requested as a target | ||||
""" | """ | ||||
from .snapshot_branch import BaseSnapshotBranchNode | |||||
_can_be_null = True | _can_be_null = True | ||||
obj: Union[SearchResultNode, BaseSnapshotBranchNode] | obj: TargetNode | ||||
def _get_node_data(self): | def _get_node_data(self): | ||||
snapshot_id = self.obj.target_hash | snapshot_id = self.obj.target_id | ||||
return self._get_snapshot_by_id(snapshot_id) | return self._get_snapshot_by_id(snapshot_id) | ||||
class OriginSnapshotConnection(BaseConnection): | class OriginSnapshotConnection(BaseConnection): | ||||
""" | """ | ||||
Connection resolver for the snapshots in an origin | Connection resolver for the snapshots in an origin | ||||
""" | """ | ||||
Show All 11 Lines |