diff --git a/swh/graphql/resolvers/origin.py b/swh/graphql/resolvers/origin.py index 871d9f6..2de74f8 100644 --- a/swh/graphql/resolvers/origin.py +++ b/swh/graphql/resolvers/origin.py @@ -1,55 +1,71 @@ from ariadne import ObjectType from . import query from swh.graphql.backends import archive origin = ObjectType("Origin") origins = ObjectType("OriginConnection") @query.field("origin") def resolve_origin(_, info, **kw): """ Top level query Get the origin matching the URL """ # return BaseNode.factory('origin').get(filters) return archive.Archive().get_origins().results[0] @origin.field("url") def origin_url(origin, info): return origin.url @origin.field("id") def origin_id(origin, info): return origin.id.hex() @query.field("origins") def resolve_origins(_, info, **kw): """ Top level query Get all the origins matching the criteria """ # return BaseList.factory('origin').get(filters, state) origins = archive.Archive().get_origins( after=kw.get("after"), first=kw.get("first") ) return origins @origins.field("nodes") def origin_nodes(origins, info, **kw): return origins.results @origins.field("pageInfo") def origin_pageinfo(origins, info, **kw): return { "hasNextPage": bool(origins.next_page_token), "endCursor": origins.next_page_token, } + + +@origin.field("visits") +def resolve_origin_visits(origin, info, **kw): + return { + "nodes": [ + { + "id": "1", + "status": "success" + }, + { + "id": "2", + "status": "success" + } + ] + } diff --git a/swh/graphql/schema/schema.graphql b/swh/graphql/schema/schema.graphql index 8258e14..8dfa820 100644 --- a/swh/graphql/schema/schema.graphql +++ b/swh/graphql/schema/schema.graphql @@ -1,51 +1,71 @@ interface Node { id: ID! } -interface SwhNode { - swhid: String! -} +# interface SwhNode { +# swhid: String! +# } + +scalar Date type PageInfo { endCursor: String hasNextPage: Boolean! } -# Origin - type Origin implements Node { url: String! id: ID! + visits( + first: Int + after: String + ): VisitConnection! } type OriginEdge { cursor: String! node: [Origin] } type OriginConnection { edges: [OriginEdge] nodes: [Origin] pageInfo: PageInfo! totalCount: Int } -# Origin end +type Visit implements Node { + id: ID! + date: Date + status: String +} + +type VisitEdge { + cursor: String! + node: [Visit] +} + +type VisitConnection { + edges: [VisitEdge] + nodes: [Visit] + pageInfo: PageInfo! + totalCount: Int +} type Query { """ Get an origin with its url """ origin( url: String! ): Origin """ Get a list of origins matching the given filters """ origins( first: Int after: String ): OriginConnection! }