diff --git a/swh/graphql/app.py b/swh/graphql/app.py index e580e33..74581b5 100644 --- a/swh/graphql/app.py +++ b/swh/graphql/app.py @@ -1,10 +1,10 @@ -from ariadne import load_schema_from_path, make_executable_schema +from ariadne import load_schema_from_path, make_executable_schema, gql from ariadne.asgi import GraphQL from .resolvers import origin, query -type_defs = load_schema_from_path("swh/graphql/schema/schema.graphql") +type_defs = gql(load_schema_from_path("swh/graphql/schema/schema.graphql")) -schema = make_executable_schema(type_defs, query, origin.origin) +schema = make_executable_schema(type_defs, query, origin.origin, origin.originSearch) app = GraphQL(schema, debug=True) diff --git a/swh/graphql/backends/archive.py b/swh/graphql/backends/archive.py index d5d7f67..c8a65f4 100644 --- a/swh/graphql/backends/archive.py +++ b/swh/graphql/backends/archive.py @@ -1,15 +1,15 @@ class Origin: - url = "test" + def __init__(self, url, id): + self.url = url + self.id = id def get_origins(): - # return Origin() return [ - {"url": "test1.example.com"}, - {"url": "test2.example.com"}, - {"url": "test3.example.com"}, - {"url": "test4.example.com"}, - {"url": "test5.example.com"}, - {"url": "test6.example.com"}, - {"url": "test7.example.com"}, + Origin("test1.example.com", "1"), + Origin("test2.example.com", "2"), + Origin("test3.example.com", "3"), + Origin("test4.example.com", "4"), + Origin("test5.example.com", "5"), + Origin("test6.example.com", "6"), ] diff --git a/swh/graphql/resolvers/origin.py b/swh/graphql/resolvers/origin.py index a7693fd..16f210b 100644 --- a/swh/graphql/resolvers/origin.py +++ b/swh/graphql/resolvers/origin.py @@ -1,29 +1,33 @@ 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): """ + Get the origin matching the URL """ origin = archive.get_origins() return origin[0] @origin.field("url") -def url(origin, info): - """ - """ - # return origin.url - return origin["url"] +def origin_url(origin, info): + return origin.url -@origin.field("visits") -def visits(origin, info): +@query.field("originSearch") +def resolve_origin_search(_, info, **kw): """ """ - return [{"status": "success"}] + return archive.get_origins() + + +@originSearch.field("nodes") +def origin_nodes(origins, info, **kw): + return origins diff --git a/swh/graphql/schema/schema.graphql b/swh/graphql/schema/schema.graphql index 2fe7f86..69d0303 100644 --- a/swh/graphql/schema/schema.graphql +++ b/swh/graphql/schema/schema.graphql @@ -1,12 +1,39 @@ -type Origin { +interface Node { + id: String! +} + +type PageInfo { + endCursor: String + startCursor: String + hasNextPage: Boolean! + hasPreviousPage: Boolean! +} + +type Origin implements Node { url: String! - visits: [Visit]! + id: String! } -type Visit { - status: String +type OriginConnection { + nodes: [Origin]! + # PageInfo: PageInfo! } type Query { - origin(url: String!): Origin + """ + Get an origin with its url + """ + origin( + url: String! + ): Origin + + """ + Get a list of origins + matching the given filters + """ + originSearch( + after: String + before: String + first: Int + ): OriginConnection! }