Moved graphql stuff to own lib
This commit is contained in:
1
kdb-bot/src/bot_graphql/__init__.py
Normal file
1
kdb-bot/src/bot_graphql/__init__.py
Normal file
@@ -0,0 +1 @@
|
||||
# imports
|
0
kdb-bot/src/bot_graphql/abc/__init__.py
Normal file
0
kdb-bot/src/bot_graphql/abc/__init__.py
Normal file
5
kdb-bot/src/bot_graphql/abc/query_abc.py
Normal file
5
kdb-bot/src/bot_graphql/abc/query_abc.py
Normal file
@@ -0,0 +1,5 @@
|
||||
from ariadne import ObjectType
|
||||
|
||||
|
||||
class QueryABC(ObjectType):
|
||||
__abstract__ = True
|
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)
|
7
kdb-bot/src/bot_graphql/graphql_service.py
Normal file
7
kdb-bot/src/bot_graphql/graphql_service.py
Normal file
@@ -0,0 +1,7 @@
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
|
||||
|
||||
class GraphQLService:
|
||||
|
||||
def __init__(self, queries: list[QueryABC]):
|
||||
self._queries = queries
|
64
kdb-bot/src/bot_graphql/model.gql
Normal file
64
kdb-bot/src/bot_graphql/model.gql
Normal file
@@ -0,0 +1,64 @@
|
||||
type Query {
|
||||
servers: [Server]
|
||||
known_users: [User]
|
||||
}
|
||||
|
||||
type Server {
|
||||
id: ID
|
||||
discord_id: String
|
||||
clients: [Client]
|
||||
members: [User]
|
||||
level: [Level]
|
||||
}
|
||||
|
||||
type Client {
|
||||
id: ID
|
||||
discord_id: String
|
||||
sent_message_count: Int
|
||||
received_message_count: Int
|
||||
deleted_message_count: Int
|
||||
received_command_count: Int
|
||||
moved_users_count: Int
|
||||
|
||||
server: Server
|
||||
}
|
||||
|
||||
type User {
|
||||
id: ID
|
||||
discord_id: String
|
||||
name: String
|
||||
xp: Int
|
||||
ontime: Int
|
||||
level: Level
|
||||
|
||||
joined_servers: [UserJoinedServer]
|
||||
joined_voice_channel: [UserJoinedVoiceChannel]
|
||||
|
||||
server: Server
|
||||
}
|
||||
|
||||
type UserJoinedServer {
|
||||
id: ID
|
||||
user: User
|
||||
server: Server
|
||||
joined_on: String
|
||||
leaved_on: String
|
||||
}
|
||||
|
||||
type UserJoinedVoiceChannel {
|
||||
id: ID
|
||||
channel_id: String
|
||||
user: User
|
||||
joined_on: String
|
||||
leaved_on: String
|
||||
}
|
||||
|
||||
type Level {
|
||||
id: ID
|
||||
name: String
|
||||
color: String
|
||||
min_xp: Int
|
||||
permissions: String
|
||||
|
||||
server: Server
|
||||
}
|
0
kdb-bot/src/bot_graphql/queries/__init__.py
Normal file
0
kdb-bot/src/bot_graphql/queries/__init__.py
Normal file
19
kdb-bot/src/bot_graphql/queries/server_query.py
Normal file
19
kdb-bot/src/bot_graphql/queries/server_query.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from bot_graphql.abc.query_abc import QueryABC
|
||||
from bot_data.model.server import Server
|
||||
|
||||
|
||||
class ServerQuery(QueryABC):
|
||||
|
||||
def __init__(self):
|
||||
QueryABC.__init__(self, 'Server')
|
||||
|
||||
self.set_field('id', self.resolve_id)
|
||||
self.set_field('discord_id', self.resolve_discord_id)
|
||||
|
||||
@staticmethod
|
||||
def resolve_id(server: Server, *_):
|
||||
return server.server_id
|
||||
|
||||
@staticmethod
|
||||
def resolve_discord_id(server: Server, *_):
|
||||
return server.discord_server_id
|
19
kdb-bot/src/bot_graphql/query.py
Normal file
19
kdb-bot/src/bot_graphql/query.py
Normal file
@@ -0,0 +1,19 @@
|
||||
from ariadne import QueryType
|
||||
|
||||
from bot_graphql.filter.server_filter import ServerFilter
|
||||
from bot_data.service.server_repository_service import ServerRepositoryService
|
||||
|
||||
|
||||
class Query(QueryType):
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
servers: ServerRepositoryService
|
||||
):
|
||||
QueryType.__init__(self)
|
||||
self._servers = servers
|
||||
|
||||
self.set_field('servers', self.resolve_servers)
|
||||
|
||||
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
|
Reference in New Issue
Block a user