diff --git a/swh/graphql/app.py b/swh/graphql/app.py index fc35f78..e580e33 100644 --- a/swh/graphql/app.py +++ b/swh/graphql/app.py @@ -1,10 +1,10 @@ -from ariadne import ObjectType, load_schema_from_path, make_executable_schema +from ariadne import load_schema_from_path, make_executable_schema from ariadne.asgi import GraphQL from .resolvers import origin, query type_defs = load_schema_from_path("swh/graphql/schema/schema.graphql") schema = make_executable_schema(type_defs, query, origin.origin) app = GraphQL(schema, debug=True) diff --git a/swh/graphql/integrations/__init__.py b/swh/graphql/backends/__init__.py similarity index 100% copy from swh/graphql/integrations/__init__.py copy to swh/graphql/backends/__init__.py diff --git a/swh/graphql/backends/archive.py b/swh/graphql/backends/archive.py new file mode 100644 index 0000000..156bfb1 --- /dev/null +++ b/swh/graphql/backends/archive.py @@ -0,0 +1,2 @@ +def get_origin(): + return {"url": "example.com"} diff --git a/swh/graphql/config/__init__.py b/swh/graphql/config/__init__.py index 8b13789..e69de29 100644 --- a/swh/graphql/config/__init__.py +++ b/swh/graphql/config/__init__.py @@ -1 +0,0 @@ - diff --git a/swh/graphql/integrations/archive.py b/swh/graphql/integrations/archive.py deleted file mode 100644 index c0f6f28..0000000 --- a/swh/graphql/integrations/archive.py +++ /dev/null @@ -1,2 +0,0 @@ -""" -""" diff --git a/swh/graphql/resolvers/origin.py b/swh/graphql/resolvers/origin.py index 43d75a6..82df2e0 100644 --- a/swh/graphql/resolvers/origin.py +++ b/swh/graphql/resolvers/origin.py @@ -1,20 +1,28 @@ from ariadne import ObjectType from . import query +from ..backends import archive origin = ObjectType("Origin") @query.field("origin") def resolve_origin(_, info, url): - return {"url": "http://example.com"} + """ + """ + origin = archive.get_origin() + return origin @origin.field("url") def url(origin, info): + """ + """ return origin["url"] @origin.field("visits") def visits(origin, info): + """ + """ return [{"status": "success"}] diff --git a/swh/graphql/schema/schema.graphql b/swh/graphql/schema/schema.graphql index a79183d..abb6c2b 100644 --- a/swh/graphql/schema/schema.graphql +++ b/swh/graphql/schema/schema.graphql @@ -1,34 +1,12 @@ type Query { origin(url: String!): Origin - snapshots: [Snapshot]! - revision: Revision - directory: Directory - content: Content } type Origin { url: String! visits: [Visit]! } type Visit { - # date: status: String - snapshot: Snapshot -} - -type Snapshot { - sha1: String -} - -type Revision { - sha1: String -} - -type Directory { - sha1: String -} - -type Content { - sha1: String } diff --git a/swh/graphql/integrations/__init__.py b/swh/graphql/tests/backends/__init__.py similarity index 100% copy from swh/graphql/integrations/__init__.py copy to swh/graphql/tests/backends/__init__.py diff --git a/swh/graphql/tests/backends/test_archive.py b/swh/graphql/tests/backends/test_archive.py new file mode 100644 index 0000000..c6083cd --- /dev/null +++ b/swh/graphql/tests/backends/test_archive.py @@ -0,0 +1,5 @@ +from swh.graphql.backends import archive + + +def test_get_origin(): + assert archive.get_origin() == {"url": "example.com"} diff --git a/swh/graphql/integrations/__init__.py b/swh/graphql/tests/resolvers/__init__.py similarity index 100% rename from swh/graphql/integrations/__init__.py rename to swh/graphql/tests/resolvers/__init__.py diff --git a/swh/graphql/tests/resolvers/test_origin.py b/swh/graphql/tests/resolvers/test_origin.py new file mode 100644 index 0000000..2ae2839 --- /dev/null +++ b/swh/graphql/tests/resolvers/test_origin.py @@ -0,0 +1 @@ +pass diff --git a/tox.ini b/tox.ini index c27d4ab..265ed6c 100644 --- a/tox.ini +++ b/tox.ini @@ -1,73 +1,72 @@ [tox] envlist=black,flake8,mypy,py3 [testenv] extras = testing deps = pytest-cov commands = - pytest --doctest-modules \ - {envsitepackagesdir}/swh/foo \ - --cov={envsitepackagesdir}/swh/foo \ + pytest {envsitepackagesdir}/swh/graphql \ + --cov={envsitepackagesdir}/swh/graphql \ --cov-branch {posargs} [testenv:black] skip_install = true deps = black==19.10b0 commands = {envpython} -m black --check swh [testenv:flake8] skip_install = true deps = flake8 commands = {envpython} -m flake8 [testenv:mypy] extras = testing deps = mypy==0.920 commands = mypy swh # build documentation outside swh-environment using the current # git HEAD of swh-docs, is executed on CI for each diff to prevent # breaking doc build [testenv:sphinx] whitelist_externals = make usedevelop = true extras = testing deps = # fetch and install swh-docs in develop mode -e git+https://forge.softwareheritage.org/source/swh-docs#egg=swh.docs setenv = SWH_PACKAGE_DOC_TOX_BUILD = 1 # turn warnings into errors SPHINXOPTS = -W commands = make -I ../.tox/sphinx/src/swh-docs/swh/ -C docs # build documentation only inside swh-environment using local state # of swh-docs package [testenv:sphinx-dev] whitelist_externals = make usedevelop = true extras = testing deps = # install swh-docs in develop mode -e ../swh-docs setenv = SWH_PACKAGE_DOC_TOX_BUILD = 1 # turn warnings into errors SPHINXOPTS = -W commands = make -I ../.tox/sphinx-dev/src/swh-docs/swh/ -C docs