Skip to content

Commit

Permalink
Merge pull request #26 from simonsobs/dev
Browse files Browse the repository at this point in the history
Add an internal plugin `dev`
  • Loading branch information
TaiSakuma authored Jan 29, 2024
2 parents f3ac962 + eee23e9 commit 382870c
Show file tree
Hide file tree
Showing 5 changed files with 47 additions and 1 deletion.
3 changes: 2 additions & 1 deletion nextlinegraphql/hook/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

from apluggy import PluginManager

from nextlinegraphql.plugins import ctrl, graphql
from nextlinegraphql.plugins import ctrl, dev, graphql

from . import spec

Expand All @@ -17,6 +17,7 @@ def load_plugins() -> PluginManager:
# https://pluggy.readthedocs.io/en/stable/#call-time-order
pm.register(graphql.Plugin(), name='graphql')
pm.register(ctrl.Plugin(), name='ctrl')
pm.register(dev.Plugin(), name='dev')
# pm.set_blocked('schedule')
pm.load_setuptools_entrypoints(spec.PROJECT_NAME)

Expand Down
3 changes: 3 additions & 0 deletions nextlinegraphql/plugins/dev/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__all__ = ['Plugin']

from .plugin import Plugin
16 changes: 16 additions & 0 deletions nextlinegraphql/plugins/dev/plugin.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
from apluggy import PluginManager
from dynaconf import Dynaconf

from nextlinegraphql.hook import spec

from .schema import Query


class Plugin:
@spec.hookimpl
def configure(self, settings: Dynaconf, hook: PluginManager) -> None:
self._settings = settings

@spec.hookimpl
def schema(self):
return (Query, None, None)
3 changes: 3 additions & 0 deletions nextlinegraphql/plugins/dev/schema/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
__all__ = ['Query']

from .query import Query
23 changes: 23 additions & 0 deletions nextlinegraphql/plugins/dev/schema/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import json
from typing import cast

import strawberry
from starlette.requests import Request
from strawberry.types import Info


def query_headers(info: Info) -> str:
request = cast(Request, info.context['request'])
return json.dumps(dict(request.headers))


@strawberry.type
class QueryDev:
headers: str = strawberry.field(resolver=query_headers)


@strawberry.type
class Query:
@strawberry.field
def dev(self) -> QueryDev:
return QueryDev()

0 comments on commit 382870c

Please sign in to comment.