Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/resolvers/visit_status.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 swh.graphql.backends import archive | from swh.graphql.backends import archive | ||||
from swh.model.swhids import CoreSWHID, ObjectType | from swh.model.swhids import CoreSWHID, ObjectType | ||||
from .base_connection import BaseConnection | from .base_connection import BaseConnection | ||||
from .base_node import BaseNode | from .base_node import BaseNode | ||||
from .visit import BaseVisitNode | |||||
class BaseVisitStatusNode(BaseNode): | class BaseVisitStatusNode(BaseNode): | ||||
""" """ | """ | ||||
Base resolver for all the visit-status nodes | |||||
""" | |||||
@property | @property | ||||
def snapshotSWHID(self): # To support the schema naming convention | def snapshotSWHID(self): # To support the schema naming convention | ||||
return CoreSWHID(object_type=ObjectType.SNAPSHOT, object_id=self._node.snapshot) | return CoreSWHID(object_type=ObjectType.SNAPSHOT, object_id=self._node.snapshot) | ||||
class LatestVisitStatusNode(BaseVisitStatusNode): | class LatestVisitStatusNode(BaseVisitStatusNode): | ||||
""" | """ | ||||
Get the latest visit status for a visit | Node resolver for a visit-status requested from a visit | ||||
self.obj is the visit object here | |||||
self.obj.origin is the origin URL | |||||
""" | """ | ||||
obj: BaseVisitNode | |||||
def _get_node_data(self): | def _get_node_data(self): | ||||
# self.obj.origin is the origin URL | |||||
return archive.Archive().get_latest_visit_status( | return archive.Archive().get_latest_visit_status( | ||||
self.obj.origin, self.obj.visitId | self.obj.origin, self.obj.visitId | ||||
) | ) | ||||
class VisitStatusConnection(BaseConnection): | class VisitStatusConnection(BaseConnection): | ||||
""" | """ | ||||
self.obj is the visit object | Connection resolver for the visit-status objects in a visit | ||||
self.obj.origin is the origin URL | |||||
""" | """ | ||||
obj: BaseVisitNode | |||||
_node_class = BaseVisitStatusNode | _node_class = BaseVisitStatusNode | ||||
def _get_paged_result(self): | def _get_paged_result(self): | ||||
# self.obj.origin is the origin URL | |||||
return archive.Archive().get_visit_status( | return archive.Archive().get_visit_status( | ||||
self.obj.origin, | self.obj.origin, | ||||
self.obj.visitId, | self.obj.visitId, | ||||
after=self._get_after_arg(), | after=self._get_after_arg(), | ||||
first=self._get_first_arg(), | first=self._get_first_arg(), | ||||
) | ) |