diff --git a/swh/graphql/middlewares/asgi.py b/swh/graphql/middlewares/asgi.py index 20c9274..75868bc 100644 --- a/swh/graphql/middlewares/asgi.py +++ b/swh/graphql/middlewares/asgi.py @@ -1,11 +1,3 @@ """ For adding ASGI middleware """ - - -def logger(): - pass - - -def auth(): - pass diff --git a/swh/graphql/middlewares/graphql.py b/swh/graphql/middlewares/graphql.py index 2cd953d..0841dda 100644 --- a/swh/graphql/middlewares/graphql.py +++ b/swh/graphql/middlewares/graphql.py @@ -1,11 +1,7 @@ """ To implement graphql middleware """ -def paginate(): - pass - - def cost_limiter(): pass diff --git a/swh/graphql/resolvers/base_connection.py b/swh/graphql/resolvers/base_connection.py new file mode 100644 index 0000000..dd7dc30 --- /dev/null +++ b/swh/graphql/resolvers/base_connection.py @@ -0,0 +1,38 @@ +""" +""" +# from dataclasses import dataclass + + +# class PageInfo: +# """ +# dataclass +# """ + +# class Arguments: +# """ +# dataclass +# """ +# after # Elements that come after the specified cursor +# first # Returns the first n elements + + +class BaseConnection: + + # @property + # def edges(self): + # pass + + @property + def nodes(self): + pass + + @property + def page_info(self): + return { + "hasNextPage": True, + "endCursor": "", + } + + @property + def total_count(self): + return None diff --git a/swh/graphql/resolvers/base_node.py b/swh/graphql/resolvers/base_node.py new file mode 100644 index 0000000..001946f --- /dev/null +++ b/swh/graphql/resolvers/base_node.py @@ -0,0 +1,8 @@ +""" +""" + + +class BaseNode: + @property + def id(self): + pass diff --git a/swh/graphql/resolvers/origin.py b/swh/graphql/resolvers/origin.py index 16f210b..da7f36f 100644 --- a/swh/graphql/resolvers/origin.py +++ b/swh/graphql/resolvers/origin.py @@ -1,33 +1,43 @@ from ariadne import ObjectType from . import query from swh.graphql.backends import archive origin = ObjectType("Origin") originSearch = ObjectType("OriginConnection") @query.field("origin") def resolve_origin(_, info, url): """ + Top level query Get the origin matching the URL """ origin = archive.get_origins() return origin[0] @origin.field("url") def origin_url(origin, info): return origin.url -@query.field("originSearch") +@query.field("origins") def resolve_origin_search(_, info, **kw): """ + Top level query + Get all the origins matching the criteria """ + # return BaseList.factory('origin').get(filters, state) + return archive.get_origins() @originSearch.field("nodes") def origin_nodes(origins, info, **kw): return origins + + +@originSearch.field("pageInfo") +def origin_pageinfo(origins, info, **kw): + return {"hasNextPage": True, "hasPreviousPage": True} diff --git a/swh/graphql/schema/schema.graphql b/swh/graphql/schema/schema.graphql index 69d0303..da4bba2 100644 --- a/swh/graphql/schema/schema.graphql +++ b/swh/graphql/schema/schema.graphql @@ -1,39 +1,51 @@ interface Node { - id: String! + id: ID! } +# interface SwhArtifact { +# swhid: String! +# } + type PageInfo { endCursor: String - startCursor: String hasNextPage: Boolean! - hasPreviousPage: Boolean! } +# Origin + type Origin implements Node { url: String! - id: String! + id: ID! } +# type OriginEdge { +# cursor: String! +# node: [Origin] +# } + type OriginConnection { - nodes: [Origin]! - # PageInfo: PageInfo! + # edges: [OriginEdge] + nodes: [Origin] + pageInfo: PageInfo! + totalCount: Int! } +# Origin end + type Query { """ Get an origin with its url """ origin( url: String! ): Origin """ Get a list of origins matching the given filters """ - originSearch( - after: String - before: String + origins( first: Int + after: String ): OriginConnection! }