From 6ca723867ef7bc2823feb8e83fc789e610d1deaf Mon Sep 17 00:00:00 2001 From: Inex Code Date: Fri, 24 Jun 2022 19:28:58 +0300 Subject: [PATCH] once again --- selfprivacy_api/app.py | 2 +- selfprivacy_api/graphql/__init__.py | 27 ------------------- selfprivacy_api/graphql/queries/api.py | 23 ++++++---------- selfprivacy_api/graphql/queries/api_fields.py | 22 +++++++++++++++ selfprivacy_api/graphql/query.py | 18 +++++++++++++ selfprivacy_api/resolvers/api.py | 2 +- 6 files changed, 50 insertions(+), 44 deletions(-) create mode 100644 selfprivacy_api/graphql/queries/api_fields.py create mode 100644 selfprivacy_api/graphql/query.py diff --git a/selfprivacy_api/app.py b/selfprivacy_api/app.py index 6deba7c..594217b 100644 --- a/selfprivacy_api/app.py +++ b/selfprivacy_api/app.py @@ -23,7 +23,7 @@ from selfprivacy_api.migrations import run_migrations from selfprivacy_api.utils.auth import is_token_valid -from selfprivacy_api.graphql import schema +from selfprivacy_api.graphql.query import schema swagger_blueprint = get_swaggerui_blueprint( "/api/docs", "/api/swagger.json", config={"app_name": "SelfPrivacy API"} diff --git a/selfprivacy_api/graphql/__init__.py b/selfprivacy_api/graphql/__init__.py index d5cd8a9..e69de29 100644 --- a/selfprivacy_api/graphql/__init__.py +++ b/selfprivacy_api/graphql/__init__.py @@ -1,27 +0,0 @@ -"""GraphQL API for SelfPrivacy.""" -# pylint: disable=too-few-public-methods -import typing -import strawberry -from selfprivacy_api.graphql.queries.api import ApiDevice, ApiRecoveryKeyStatus - -from selfprivacy_api.graphql.queries.system import System - -from selfprivacy_api.resolvers.api import get_api_version, get_devices, get_recovery_key_status - -@strawberry.type -class Api: - """API access status""" - version: str = strawberry.field(resolver=get_api_version) - devices: typing.List[ApiDevice] = strawberry.field(resolver=get_devices) - recovery_key: ApiRecoveryKeyStatus = strawberry.field(resolver=get_recovery_key_status) - -@strawberry.type -class Query: - """Root schema for queries""" - system: System - @strawberry.field - def api(self) -> Api: - """API access status""" - return Api() - -schema = strawberry.Schema(query=Query) diff --git a/selfprivacy_api/graphql/queries/api.py b/selfprivacy_api/graphql/queries/api.py index 2e46d50..dbea5a1 100644 --- a/selfprivacy_api/graphql/queries/api.py +++ b/selfprivacy_api/graphql/queries/api.py @@ -1,22 +1,15 @@ """API access status""" # pylint: disable=too-few-public-methods -import datetime import typing import strawberry +from selfprivacy_api.graphql.queries.api_fields import ApiDevice, ApiRecoveryKeyStatus +from selfprivacy_api.resolvers.api import get_api_version, get_devices, get_recovery_key_status + @strawberry.type -class ApiDevice: - """A single device with SelfPrivacy app installed""" - name: str - creation_date: datetime.datetime - is_caller: bool - -@strawberry.type -class ApiRecoveryKeyStatus: - """Recovery key status""" - exists: bool - valid: bool - creation_date: typing.Optional[datetime.datetime] - expiration_date: typing.Optional[datetime.datetime] - uses_left: typing.Optional[int] +class Api: + """API access status""" + version: str = strawberry.field(resolver=get_api_version) + devices: typing.List[ApiDevice] = strawberry.field(resolver=get_devices) + recovery_key: ApiRecoveryKeyStatus = strawberry.field(resolver=get_recovery_key_status) diff --git a/selfprivacy_api/graphql/queries/api_fields.py b/selfprivacy_api/graphql/queries/api_fields.py new file mode 100644 index 0000000..2e46d50 --- /dev/null +++ b/selfprivacy_api/graphql/queries/api_fields.py @@ -0,0 +1,22 @@ +"""API access status""" +# pylint: disable=too-few-public-methods +import datetime +import typing +import strawberry + + +@strawberry.type +class ApiDevice: + """A single device with SelfPrivacy app installed""" + name: str + creation_date: datetime.datetime + is_caller: bool + +@strawberry.type +class ApiRecoveryKeyStatus: + """Recovery key status""" + exists: bool + valid: bool + creation_date: typing.Optional[datetime.datetime] + expiration_date: typing.Optional[datetime.datetime] + uses_left: typing.Optional[int] diff --git a/selfprivacy_api/graphql/query.py b/selfprivacy_api/graphql/query.py new file mode 100644 index 0000000..80b3d78 --- /dev/null +++ b/selfprivacy_api/graphql/query.py @@ -0,0 +1,18 @@ +"""GraphQL API for SelfPrivacy.""" +# pylint: disable=too-few-public-methods +import typing +import strawberry +from selfprivacy_api.graphql.queries.api import Api + +from selfprivacy_api.graphql.queries.system import System + +@strawberry.type +class Query: + """Root schema for queries""" + system: System + @strawberry.field + def api(self) -> Api: + """API access status""" + return Api() + +schema = strawberry.Schema(query=Query) diff --git a/selfprivacy_api/resolvers/api.py b/selfprivacy_api/resolvers/api.py index bbcebf9..f375dc8 100644 --- a/selfprivacy_api/resolvers/api.py +++ b/selfprivacy_api/resolvers/api.py @@ -3,7 +3,7 @@ import datetime import typing from flask import request -from selfprivacy_api.graphql.queries.api import ApiDevice, ApiRecoveryKeyStatus +from selfprivacy_api.graphql.queries.api_fields import ApiDevice, ApiRecoveryKeyStatus from selfprivacy_api.utils.auth import ( get_recovery_token_status,