diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..47ff06b --- /dev/null +++ b/.gitignore @@ -0,0 +1,14 @@ +*.pyc +*.sw? +*~ +/.coverage +/.coverage.* +.eggs/ +__pycache__ +build +dist +swh.core.egg-info +version.txt +.tox +.hypothesis +.mypy_cache/ \ No newline at end of file diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..e202498 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,10 @@ +FROM python:3.7 + +RUN mkdir -p /usr/src/app +WORKDIR /usr/src/app + +ENV PYTHONPATH=/usr/src/app/ + +COPY requirements*.txt /usr/src/app/ +RUN pip install --upgrade pip +RUN pip install --no-cache-dir -r requirements.txt -r requirements-swh.txt diff --git a/README b/README new file mode 100644 index 0000000..ab12792 --- /dev/null +++ b/README @@ -0,0 +1,3 @@ +# To run + +* docker-compose up \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml new file mode 100644 index 0000000..8a86f45 --- /dev/null +++ b/docker-compose.yml @@ -0,0 +1,12 @@ +version: "3.4" + +services: + app: + build: + context: ./ + dockerfile: Dockerfile + volumes: + - ".:/usr/src/app" + ports: + - "8000:8000" + command: uvicorn swh.graphql.app:app --host 0.0.0.0 --port 8000 --reload diff --git a/mypy.ini b/mypy.ini new file mode 100644 index 0000000..e69de29 diff --git a/pytest.ini b/pytest.ini new file mode 100644 index 0000000..e69de29 diff --git a/requirements-swh.txt b/requirements-swh.txt new file mode 100644 index 0000000..61359d0 --- /dev/null +++ b/requirements-swh.txt @@ -0,0 +1,2 @@ +swh.core >= 0.0.95 + diff --git a/requirements-test.txt b/requirements-test.txt new file mode 100644 index 0000000..e079f8a --- /dev/null +++ b/requirements-test.txt @@ -0,0 +1 @@ +pytest diff --git a/requirements.txt b/requirements.txt new file mode 100644 index 0000000..cc7c65b --- /dev/null +++ b/requirements.txt @@ -0,0 +1,2 @@ +ariadne==0.13.0 +uvicorn==0.15.0 diff --git a/swh/__init__.py b/swh/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/swh/graphql/__init__.py b/swh/graphql/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/swh/graphql/app.py b/swh/graphql/app.py new file mode 100644 index 0000000..fc35f78 --- /dev/null +++ b/swh/graphql/app.py @@ -0,0 +1,10 @@ +from ariadne import ObjectType, 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/config/__init__.py b/swh/graphql/config/__init__.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/swh/graphql/config/__init__.py @@ -0,0 +1 @@ + diff --git a/swh/graphql/integrations/__init__.py b/swh/graphql/integrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/swh/graphql/integrations/archive.py b/swh/graphql/integrations/archive.py new file mode 100644 index 0000000..c0f6f28 --- /dev/null +++ b/swh/graphql/integrations/archive.py @@ -0,0 +1,2 @@ +""" +""" diff --git a/swh/graphql/middlewares/__init__.py b/swh/graphql/middlewares/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/swh/graphql/middlewares/asgi.py b/swh/graphql/middlewares/asgi.py new file mode 100644 index 0000000..20c9274 --- /dev/null +++ b/swh/graphql/middlewares/asgi.py @@ -0,0 +1,11 @@ +""" +For adding ASGI middleware +""" + + +def logger(): + pass + + +def auth(): + pass diff --git a/swh/graphql/middlewares/graphql.py b/swh/graphql/middlewares/graphql.py new file mode 100644 index 0000000..2cd953d --- /dev/null +++ b/swh/graphql/middlewares/graphql.py @@ -0,0 +1,11 @@ +""" +To implement graphql middleware +""" + + +def paginate(): + pass + + +def cost_limiter(): + pass diff --git a/swh/graphql/resolvers/__init__.py b/swh/graphql/resolvers/__init__.py new file mode 100644 index 0000000..3a4ab4c --- /dev/null +++ b/swh/graphql/resolvers/__init__.py @@ -0,0 +1,3 @@ +from ariadne import ObjectType + +query = ObjectType("Query") diff --git a/swh/graphql/resolvers/content.py b/swh/graphql/resolvers/content.py new file mode 100644 index 0000000..e69de29 diff --git a/swh/graphql/resolvers/directory.py b/swh/graphql/resolvers/directory.py new file mode 100644 index 0000000..e69de29 diff --git a/swh/graphql/resolvers/origin.py b/swh/graphql/resolvers/origin.py new file mode 100644 index 0000000..a61bb65 --- /dev/null +++ b/swh/graphql/resolvers/origin.py @@ -0,0 +1,20 @@ +from ariadne import ObjectType + +from . import query + +origin = ObjectType("Origin") + + +@query.field("origin") +def resolve_origin(_, info, url): + return {"url": "http://example.com"} + + +@origin.field("url") +def url(origin, info): + return origin["url"] + + +@origin.field("visits") +def visits(origin, info): + return [] diff --git a/swh/graphql/resolvers/revision.py b/swh/graphql/resolvers/revision.py new file mode 100644 index 0000000..e69de29 diff --git a/swh/graphql/resolvers/snapshot.py b/swh/graphql/resolvers/snapshot.py new file mode 100644 index 0000000..8b13789 --- /dev/null +++ b/swh/graphql/resolvers/snapshot.py @@ -0,0 +1 @@ + diff --git a/swh/graphql/schema/schema.gql b/swh/graphql/schema/schema.gql new file mode 100644 index 0000000..7190629 --- /dev/null +++ b/swh/graphql/schema/schema.gql @@ -0,0 +1,54 @@ +Initial Entry points +-------------------- + +origin(url) { + url + vsits(first:n) { + totalCount + edges { + node { + timestamp + } + cursor + } + } +} + +visit { + status + timestamp + snapshot +} + +snapshots(origin-url, limit) // not a must have + +snapshot(sha1) { + sha1 + origin + branches(limit) { + name + head revision + } +} + +revision(sha1) { + sha1 + author + ... + parent revisions(limit) + directory +} + +directory(sha1) { + sha1 + name + ... + contents(limit) + directories(limit) +} + +content(sha1) { + sha1 + name + ... +} diff --git a/swh/graphql/schema/schema.graphql b/swh/graphql/schema/schema.graphql new file mode 100644 index 0000000..a79183d --- /dev/null +++ b/swh/graphql/schema/schema.graphql @@ -0,0 +1,34 @@ +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/tests/__init__.py b/swh/graphql/tests/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/tox.ini b/tox.ini new file mode 100644 index 0000000..e69de29