Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/resolvers/snapshot_branch.py
Show First 20 Lines • Show All 45 Lines • ▼ Show 20 Lines | class SnapshotBranchConnection(BaseConnection): | ||||
from .snapshot import SnapshotNode | from .snapshot import SnapshotNode | ||||
obj: SnapshotNode | obj: SnapshotNode | ||||
_node_class = SnapshotBranchNode | _node_class = SnapshotBranchNode | ||||
def _get_paged_result(self): | def _get_paged_result(self): | ||||
# self.obj.swhid is the snapshot SWHID | # after argument must be an empty string by default | ||||
after = self._get_after_arg() if self._get_after_arg() else "" | |||||
result = archive.Archive().get_snapshot_branches( | result = archive.Archive().get_snapshot_branches( | ||||
self.obj.swhid.object_id, | self.obj.swhid.object_id, | ||||
after=self._get_after_arg(), | after=after.encode(), | ||||
first=self._get_first_arg(), | first=self._get_first_arg(), | ||||
target_types=self.kwargs.get("types"), | target_types=self.kwargs.get("types"), | ||||
name_include=self._get_name_include_arg(), | name_include=self._get_name_include_arg(), | ||||
) | ) | ||||
# FIXME Cursor must be a hex to be consistent with | |||||
# the base class, hack to make that work | # endCursor is the last branch name, logic for that | ||||
end_cusrsor = ( | end_cusrsor = ( | ||||
result["next_branch"] if result["next_branch"] is not None else None | result["next_branch"] if result["next_branch"] is not None else None | ||||
) | ) | ||||
# FIXME, this pagination is not consistent with other connections | # FIXME, this pagination is not consistent with other connections | ||||
# FIX in swh-storage to return PagedResult | # FIX in swh-storage to return PagedResult | ||||
# STORAGE-TODO | # STORAGE-TODO | ||||
return PagedResult( | return PagedResult( | ||||
results=result["branches"].items(), next_page_token=end_cusrsor | results=result["branches"].items(), next_page_token=end_cusrsor | ||||
) | ) | ||||
def _get_after_arg(self): | |||||
# Snapshot branch is using a different cursor; logic to handle that | |||||
after = utils.get_decoded_cursor(self.kwargs.get("after", "")) | |||||
return after.encode() if after else b"" | |||||
def _get_name_include_arg(self): | def _get_name_include_arg(self): | ||||
name_include = self.kwargs.get("nameInclude", None) | name_include = self.kwargs.get("nameInclude", None) | ||||
return name_include.encode() if name_include else None | return name_include.encode() if name_include else None | ||||
def _get_index_cursor(self, index: int, node: SnapshotBranchNode): | def _get_index_cursor(self, index: int, node: SnapshotBranchNode): | ||||
# Snapshot branch is using a different cursor, hence the override | # Snapshot branch is using a different cursor, hence the override | ||||
return utils.get_encoded_cursor(node.name.hex()) | return utils.get_encoded_cursor(node.name) |