diff --git a/swh/graphql/backends/search.py b/swh/graphql/backends/search.py new file mode 100644 --- /dev/null +++ b/swh/graphql/backends/search.py @@ -0,0 +1,14 @@ +# Copyright (C) 2022 The Software Heritage developers +# See the AUTHORS file at the top-level directory of this distribution +# License: GNU General Public License version 3, or any later version +# See top-level LICENSE file for more information + +from swh.graphql import server + + +class Search: + def __init__(self): + self.search = server.get_search() + + def origins(self, query): + return query diff --git a/swh/graphql/resolvers/search.py b/swh/graphql/resolvers/search.py --- a/swh/graphql/resolvers/search.py +++ b/swh/graphql/resolvers/search.py @@ -3,7 +3,7 @@ # License: GNU General Public License version 3, or any later version # See top-level LICENSE file for more information -from swh.graphql.backends import archive +from swh.graphql.backends import archive, search from swh.storage.interface import PagedResult from .base_connection import BaseConnection @@ -29,3 +29,13 @@ } ] return PagedResult(results=results) + + +class SearchConnection(BaseConnection): + + _node_class = SearchResultNode + + def _get_paged_result(self) -> PagedResult: + # obj_type = self.kwargs.get("type") + results = search.Search().origins(self.kwargs.get("query")) + return PagedResult(results=results) diff --git a/swh/graphql/schema/schema.graphql b/swh/graphql/schema/schema.graphql --- a/swh/graphql/schema/schema.graphql +++ b/swh/graphql/schema/schema.graphql @@ -921,6 +921,10 @@ target: SearchResultTarget } +enum SearchType { + origin +} + """ The query root of the GraphQL interface. """ @@ -1040,4 +1044,9 @@ """ swhid: SWHID! ): SearchResultConnection! + + search( + query: String! + type: SearchType! + ): SearchResultConnection! }