Changeset View
Changeset View
Standalone View
Standalone View
swh/graphql/resolvers/search.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.storage.interface import PagedResult | from swh.storage.interface import PagedResult | ||||
from .base_connection import BaseConnection | from .base_connection import BaseConnection, BaseList | ||||
from .base_node import BaseNode | from .base_node import BaseNode | ||||
class SearchResultNode(BaseNode): | class SearchResultNode(BaseNode): | ||||
""" """ | """ """ | ||||
@property | @property | ||||
def targetType(self): # To support the schema naming convention | def targetType(self): # To support the schema naming convention | ||||
return self._node.type | return self._node.type | ||||
class ResolveSwhidConnection(BaseConnection): | class ResolveSwhidList(BaseList): | ||||
_node_class = SearchResultNode | _node_class = SearchResultNode | ||||
def _get_paged_result(self) -> PagedResult: | def _get_results(self) -> list: | ||||
swhid = self.kwargs.get("swhid") | swhid = self.kwargs.get("swhid") | ||||
results = [] | results = [] | ||||
if self.archive.is_object_available(swhid.object_id, swhid.object_type): | if self.archive.is_object_available(swhid.object_id, swhid.object_type): | ||||
results = [ | results = [ | ||||
{ | { | ||||
"target_hash": swhid.object_id, | "target_hash": swhid.object_id, | ||||
"type": swhid.object_type.name.lower(), | "type": swhid.object_type.name.lower(), | ||||
} | } | ||||
] | ] | ||||
return PagedResult(results=results) | return results | ||||
class SearchConnection(BaseConnection): | class SearchConnection(BaseConnection): | ||||
_node_class = SearchResultNode | _node_class = SearchResultNode | ||||
def _get_paged_result(self) -> PagedResult: | def _get_paged_result(self) -> PagedResult: | ||||
origins = self.search.get_origins( | origins = self.search.get_origins( | ||||
Show All 10 Lines |