Skip to content

Commit

Permalink
Merge pull request #3 from simonsobs/dev
Browse files Browse the repository at this point in the history
Add a GraphQL query `version`
  • Loading branch information
TaiSakuma authored Feb 8, 2024
2 parents dff3c7f + 3985d67 commit 726485e
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 7 deletions.
3 changes: 2 additions & 1 deletion src/nextline_alert/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
__all__ = ['Plugin']
__all__ = ['__version__', 'Plugin']


from .__about__ import __version__
from .plugin import Plugin
15 changes: 12 additions & 3 deletions src/nextline_alert/plugin.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
from collections.abc import Mapping
from logging import getLogger
from pathlib import Path
from typing import Optional, cast

Expand All @@ -7,7 +8,9 @@
from nextline import Nextline
from nextlinegraphql.hook import spec

from .__about__ import __version__
from .emitter import Emitter
from .schema import Mutation, Query, Subscription

HERE = Path(__file__).resolve().parent
DEFAULT_CONFIG_PATH = HERE / 'default.toml'
Expand Down Expand Up @@ -37,13 +40,19 @@ def dynaconf_validators(self) -> Optional[tuple[Validator, ...]]:

@spec.hookimpl
def configure(self, settings: Dynaconf):
self._url = settings.alert.campana_url
self._platform = settings.alert.platform
logger = getLogger(__name__)
logger.info(f'{__package__} version: {__version__}')
url = settings.alert.campana_url
platform = settings.alert.platform
self._emitter = Emitter(url=url, platform=platform)

@spec.hookimpl
def schema(self) -> tuple[type, type | None, type | None]:
return (Query, Mutation, Subscription)

@spec.hookimpl
@asynccontextmanager
async def lifespan(self, context: Mapping):
self._emitter = Emitter(url=self._url, platform=self._platform)
nextline = cast(Nextline, context['nextline'])
nextline.register(self._emitter)
yield
Empty file added src/nextline_alert/py.typed
Empty file.
14 changes: 14 additions & 0 deletions src/nextline_alert/schema/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
__all__ = ['Query', 'Mutation', 'Subscription']
import strawberry

from .query import Query


@strawberry.type
class Mutation:
pass


@strawberry.type
class Subscription:
pass
15 changes: 15 additions & 0 deletions src/nextline_alert/schema/query.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import strawberry

import nextline_alert


@strawberry.type
class AlertRDB:
version: str = nextline_alert.__version__


@strawberry.type
class Query:
@strawberry.field
async def alert(self) -> AlertRDB:
return AlertRDB()
3 changes: 0 additions & 3 deletions tests/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
# SPDX-FileCopyrightText: 2024-present Tai Sakuma <[email protected]>
#
# SPDX-License-Identifier: MIT
6 changes: 6 additions & 0 deletions tests/test_version.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
import nextline_alert


def test_version():
'''Confirm that the version string is attached to the module'''
nextline_alert.__version__

0 comments on commit 726485e

Please sign in to comment.