Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/resolvers/snapshot_branch.py
Show First 20 Lines • Show All 90 Lines • ▼ Show 20 Lines | class SnapshotBranchConnection(BaseConnection): | ||||
def _get_paged_result(self) -> PagedResult: | def _get_paged_result(self) -> PagedResult: | ||||
result = self.archive.get_snapshot_branches( | result = self.archive.get_snapshot_branches( | ||||
self.obj.swhid.object_id, | self.obj.swhid.object_id, | ||||
after=self._get_after_arg(), | after=self._get_after_arg(), | ||||
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(), | ||||
name_exclude_prefix=self._get_name_exclude_prefix_arg(), | |||||
) | ) | ||||
# endCursor is the last branch name, logic for that | # 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 | ||||
# this will be serialized in _get_node_from_data method in the node class | # this will be serialized in _get_node_from_data method in the node class | ||||
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): | def _get_after_arg(self): | ||||
# after argument must be an empty string by default | # after argument must be an empty string by default | ||||
after = super()._get_after_arg() | after = super()._get_after_arg() | ||||
return after.encode() if after else b"" | 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_name_exclude_prefix_arg(self): | |||||
name_exclude_prefix = self.kwargs.get("nameExcludePrefix", None) | |||||
return name_exclude_prefix.encode() if name_exclude_prefix else None | |||||
def _get_index_cursor(self, index: int, node: BaseSnapshotBranchNode): | def _get_index_cursor(self, index: int, node: BaseSnapshotBranchNode): | ||||
# 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) | return utils.get_encoded_cursor(node.name) |