GraphQL Part1 (gql endpoint only) #162 #192
@ -6,6 +6,7 @@
|
||||
"bot-api": "src/bot_api/bot-api.json",
|
||||
"bot-core": "src/bot_core/bot-core.json",
|
||||
"bot-data": "src/bot_data/bot-data.json",
|
||||
"bot-graphql": "src/bot_graphql/bot-graphql.json",
|
||||
"auto-role": "src/modules/auto_role/auto-role.json",
|
||||
"base": "src/modules/base/base.json",
|
||||
"boot-log": "src/modules/boot_log/boot-log.json",
|
||||
@ -21,22 +22,16 @@
|
||||
"Scripts": {
|
||||
"sv": "cpl set-version $ARGS",
|
||||
"set-version": "cpl run set-version $ARGS --dev; echo '';",
|
||||
|
||||
"gv": "cpl get-version",
|
||||
"get-version": "export VERSION=$(cpl run get-version --dev); echo $VERSION;",
|
||||
|
||||
"pre-build": "cpl set-version $ARGS",
|
||||
"post-build": "cpl run post-build --dev",
|
||||
|
||||
"pre-prod": "cpl build",
|
||||
"prod": "export KDB_ENVIRONMENT=production; export KDB_NAME=KDB-Prod; cpl start;",
|
||||
|
||||
"pre-stage": "cpl build",
|
||||
"stage": "export KDB_ENVIRONMENT=staging; export KDB_NAME=KDB-Stage; cpl start;",
|
||||
|
||||
"pre-dev": "cpl build",
|
||||
"dev": "export KDB_ENVIRONMENT=development; export KDB_NAME=KDB-Dev; cpl start;",
|
||||
|
||||
"docker-build": "cpl build $ARGS; docker build -t kdb-bot/kdb-bot:$(cpl gv) .;",
|
||||
"dc-up": "docker-compose up -d",
|
||||
"dc-down": "docker-compose down",
|
||||
|
@ -57,6 +57,7 @@
|
||||
"../bot_api/bot-api.json",
|
||||
"../bot_core/bot-core.json",
|
||||
"../bot_data/bot-data.json",
|
||||
"../bot_graphql/bot-graphql.json",
|
||||
"../modules/auto_role/auto-role.json",
|
||||
"../modules/base/base.json",
|
||||
"../modules/boot_log/boot-log.json",
|
||||
|
@ -4,6 +4,7 @@ from bot_api.api_module import ApiModule
|
||||
from bot_core.core_extension.core_extension_module import CoreExtensionModule
|
||||
from bot_core.core_module import CoreModule
|
||||
from bot_data.data_module import DataModule
|
||||
from bot_graphql.graphql_module import GraphQLModule
|
||||
from modules.auto_role.auto_role_module import AutoRoleModule
|
||||
from modules.base.base_module import BaseModule
|
||||
from modules.boot_log.boot_log_module import BootLogModule
|
||||
@ -22,6 +23,7 @@ class ModuleList:
|
||||
return List(type, [
|
||||
CoreModule, # has to be first!
|
||||
DataModule,
|
||||
GraphQLModule,
|
||||
PermissionModule,
|
||||
DatabaseModule,
|
||||
AutoRoleModule,
|
||||
|
@ -21,7 +21,7 @@ from bot_api.exception.service_exception import ServiceException
|
||||
from bot_api.logging.api_logger import ApiLogger
|
||||
from bot_api.model.error_dto import ErrorDTO
|
||||
from bot_api.route.route import Route
|
||||
from bot_data.graphql.graphql_service import GraphQLService
|
||||
from bot_graphql.graphql_service import GraphQLService
|
||||
|
||||
|
||||
class Api(Flask):
|
||||
|
@ -1,14 +1,12 @@
|
||||
from ariadne import graphql_sync
|
||||
from ariadne.constants import PLAYGROUND_HTML
|
||||
from ariadne_graphql_modules import make_executable_schema
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
from flask import request, jsonify
|
||||
|
||||
from bot_api.logging.api_logger import ApiLogger
|
||||
from bot_api.route.route import Route
|
||||
from bot_data.graphql.query import Query
|
||||
from bot_data.graphql.schema import Schema
|
||||
from bot_graphql.schema import Schema
|
||||
|
||||
|
||||
class GraphQLController:
|
||||
|
@ -10,17 +10,11 @@ from bot_data.abc.auto_role_repository_abc import AutoRoleRepositoryABC
|
||||
from bot_data.abc.client_repository_abc import ClientRepositoryABC
|
||||
from bot_data.abc.known_user_repository_abc import KnownUserRepositoryABC
|
||||
from bot_data.abc.level_repository_abc import LevelRepositoryABC
|
||||
from bot_data.abc.query_abc import QueryABC
|
||||
from bot_data.abc.server_repository_abc import ServerRepositoryABC
|
||||
from bot_data.abc.statistic_repository_abc import StatisticRepositoryABC
|
||||
from bot_data.abc.user_joined_server_repository_abc import UserJoinedServerRepositoryABC
|
||||
from bot_data.abc.user_joined_voice_channel_abc import UserJoinedVoiceChannelRepositoryABC
|
||||
from bot_data.abc.user_repository_abc import UserRepositoryABC
|
||||
from bot_data.graphql.graphql_service import GraphQLService
|
||||
from bot_data.graphql.query import Query
|
||||
from bot_data.graphql.schema import Schema
|
||||
from bot_data.graphql.server_query import ServerQuery
|
||||
from bot_data.graphql.types.server_query_type import ServerQueryType
|
||||
from bot_data.service.auth_user_repository_service import AuthUserRepositoryService
|
||||
from bot_data.service.auto_role_repository_service import AutoRoleRepositoryService
|
||||
from bot_data.service.client_repository_service import ClientRepositoryService
|
||||
@ -54,10 +48,4 @@ class DataModule(ModuleABC):
|
||||
services.add_transient(LevelRepositoryABC, LevelRepositoryService)
|
||||
services.add_transient(StatisticRepositoryABC, StatisticRepositoryService)
|
||||
|
||||
services.add_singleton(Schema)
|
||||
services.add_singleton(GraphQLService)
|
||||
services.add_singleton(Query)
|
||||
# services.add_transient(QueryABC, ServerQuery)
|
||||
services.add_transient(QueryABC, ServerQueryType)
|
||||
|
||||
services.add_transient(SeederService)
|
||||
|
@ -1,31 +0,0 @@
|
||||
from ariadne import make_executable_schema, gql
|
||||
from graphql import GraphQLSchema
|
||||
|
||||
from bot_data.graphql.query import Query
|
||||
from bot_data.graphql.server_query import ServerQuery
|
||||
from bot_data.graphql.types.server_query_type import ServerQueryType
|
||||
|
||||
|
||||
class Schema:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
query: Query,
|
||||
server_query: ServerQuery,
|
||||
server_query_type: ServerQueryType
|
||||
):
|
||||
type_defs = gql("""
|
||||
type Query {
|
||||
servers: [Server]
|
||||
}
|
||||
|
||||
type Server {
|
||||
id: Int
|
||||
discord_id: String
|
||||
}
|
||||
""")
|
||||
self._schema = make_executable_schema(type_defs, query, server_query_type)
|
||||
|
||||
@property
|
||||
def schema(self) -> GraphQLSchema:
|
||||
return self._schema
|
@ -1,20 +0,0 @@
|
||||
from bot_data.abc.query_abc import QueryABC
|
||||
from bot_data.graphql.query import Query
|
||||
from bot_data.service.server_repository_service import ServerRepositoryService
|
||||
|
||||
|
||||
class ServerQuery(QueryABC):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
query: Query,
|
||||
servers: ServerRepositoryService
|
||||
):
|
||||
QueryABC.__init__(self, 'servers')
|
||||
self._query = query
|
||||
self._servers = servers
|
||||
|
||||
query.set_field('servers', self.resolve_servers)
|
||||
|
||||
async def resolve_servers(self):
|
||||
return self._servers.get_servers()
|
1
kdb-bot/src/bot_graphql/__init__.py
Normal file
1
kdb-bot/src/bot_graphql/__init__.py
Normal file
@ -0,0 +1 @@
|
||||
# imports
|
44
kdb-bot/src/bot_graphql/bot-graphql.json
Normal file
44
kdb-bot/src/bot_graphql/bot-graphql.json
Normal file
@ -0,0 +1,44 @@
|
||||
{
|
||||
"ProjectSettings": {
|
||||
"Name": "bot-data",
|
||||
"Version": {
|
||||
"Major": "0",
|
||||
"Minor": "1",
|
||||
"Micro": "0"
|
||||
},
|
||||
"Author": "Sven Heidemann",
|
||||
"AuthorEmail": "sven.heidemann@sh-edraft.de",
|
||||
"Description": "Keksdose bot - graphql",
|
||||
"LongDescription": "Discord bot for the Keksdose discord Server - graphql package",
|
||||
"URL": "https://www.sh-edraft.de",
|
||||
"CopyrightDate": "2023",
|
||||
"CopyrightName": "sh-edraft.de",
|
||||
"LicenseName": "MIT",
|
||||
"LicenseDescription": "MIT, see LICENSE for more details.",
|
||||
"Dependencies": [
|
||||
"cpl-core>=2022.12.1"
|
||||
],
|
||||
"DevDependencies": [
|
||||
"cpl-cli>=2022.12.1"
|
||||
],
|
||||
"PythonVersion": ">=3.10.4",
|
||||
"PythonPath": {},
|
||||
"Classifiers": []
|
||||
},
|
||||
"BuildSettings": {
|
||||
"ProjectType": "library",
|
||||
"SourcePath": "",
|
||||
"OutputPath": "../../dist",
|
||||
"Main": "",
|
||||
"EntryPoint": "",
|
||||
"IncludePackageData": false,
|
||||
"Included": [],
|
||||
"Excluded": [
|
||||
"*/__pycache__",
|
||||
"*/logs",
|
||||
"*/tests"
|
||||
],
|
||||
"PackageData": {},
|
||||
"ProjectReferences": []
|
||||
}
|
||||
}
|
0
kdb-bot/src/bot_graphql/filter/__init__.py
Normal file
0
kdb-bot/src/bot_graphql/filter/__init__.py
Normal file
2
kdb-bot/src/bot_graphql/filter/server_filter.py
Normal file
2
kdb-bot/src/bot_graphql/filter/server_filter.py
Normal file
@ -0,0 +1,2 @@
|
||||
class ServerFilter:
|
||||
pass
|
31
kdb-bot/src/bot_graphql/graphql_module.py
Normal file
31
kdb-bot/src/bot_graphql/graphql_module.py
Normal file
@ -0,0 +1,31 @@
|
||||
from cpl_core.configuration import ConfigurationABC
|
||||
from cpl_core.dependency_injection import ServiceCollectionABC
|
||||
from cpl_core.environment import ApplicationEnvironmentABC
|
||||
from cpl_discord.service.discord_collection_abc import DiscordCollectionABC
|
||||
|
||||
from bot_core.abc.module_abc import ModuleABC
|
||||
from bot_core.configuration.feature_flags_enum import FeatureFlagsEnum
|
||||
from bot_data.service.seeder_service import SeederService
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
from bot_graphql.graphql_service import GraphQLService
|
||||
from bot_graphql.queries.server_query import ServerQuery
|
||||
from bot_graphql.query import Query
|
||||
from bot_graphql.schema import Schema
|
||||
|
||||
|
||||
class GraphQLModule(ModuleABC):
|
||||
|
||||
def __init__(self, dc: DiscordCollectionABC):
|
||||
ModuleABC.__init__(self, dc, FeatureFlagsEnum.data_module)
|
||||
|
||||
def configure_configuration(self, config: ConfigurationABC, env: ApplicationEnvironmentABC):
|
||||
pass
|
||||
|
||||
def configure_services(self, services: ServiceCollectionABC, env: ApplicationEnvironmentABC):
|
||||
|
||||
services.add_singleton(Schema)
|
||||
services.add_singleton(GraphQLService)
|
||||
services.add_singleton(Query)
|
||||
services.add_transient(QueryABC, ServerQuery)
|
||||
|
||||
services.add_transient(SeederService)
|
@ -1,4 +1,4 @@
|
||||
from bot_data.abc.query_abc import QueryABC
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
|
||||
|
||||
class GraphQLService:
|
0
kdb-bot/src/bot_graphql/queries/__init__.py
Normal file
0
kdb-bot/src/bot_graphql/queries/__init__.py
Normal file
@ -1,10 +1,8 @@
|
||||
from ariadne import ObjectType
|
||||
|
||||
from bot_data.abc.query_abc import QueryABC
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
class ServerQueryType(QueryABC):
|
||||
class ServerQuery(QueryABC):
|
||||
|
||||
def __init__(self):
|
||||
QueryABC.__init__(self, 'Server')
|
@ -1,5 +1,6 @@
|
||||
from ariadne import QueryType
|
||||
|
||||
from bot_graphql.filter.server_filter import ServerFilter
|
||||
from bot_data.service.server_repository_service import ServerRepositoryService
|
||||
|
||||
|
||||
@ -14,5 +15,5 @@ class Query(QueryType):
|
||||
|
||||
self.set_field('servers', self.resolve_servers)
|
||||
|
||||
def resolve_servers(self, *_):
|
||||
def resolve_servers(self, filter: ServerFilter, *_):
|
||||
return self._servers.get_servers()
|
22
kdb-bot/src/bot_graphql/schema.py
Normal file
22
kdb-bot/src/bot_graphql/schema.py
Normal file
@ -0,0 +1,22 @@
|
||||
import os
|
||||
|
||||
from ariadne import make_executable_schema, load_schema_from_path
|
||||
from graphql import GraphQLSchema
|
||||
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
from bot_graphql.query import Query
|
||||
|
||||
|
||||
class Schema:
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
query: Query,
|
||||
queries: list[QueryABC]
|
||||
):
|
||||
type_defs = load_schema_from_path(os.path.join(os.path.dirname(os.path.realpath(__file__)), 'model.gql'))
|
||||
self._schema = make_executable_schema(type_defs, query, *queries)
|
||||
|
||||
@property
|
||||
def schema(self) -> GraphQLSchema:
|
||||
return self._schema
|
Loading…
Reference in New Issue
Block a user