Moved to ariadne
This commit is contained in:
@@ -1,4 +1,3 @@
|
||||
import re
|
||||
import sys
|
||||
import textwrap
|
||||
import uuid
|
||||
@@ -12,7 +11,6 @@ from eventlet import wsgi
|
||||
from flask import Flask, request, jsonify, Response
|
||||
from flask_cors import CORS
|
||||
from flask_socketio import SocketIO
|
||||
from graphql_server.flask import GraphQLView
|
||||
from werkzeug.exceptions import NotFound
|
||||
|
||||
from bot_api.configuration.api_settings import ApiSettings
|
||||
@@ -23,7 +21,6 @@ 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 import GraphQL
|
||||
|
||||
|
||||
class Api(Flask):
|
||||
@@ -64,16 +61,6 @@ class Api(Flask):
|
||||
|
||||
self._requests = {}
|
||||
|
||||
gql = GraphQL()
|
||||
self.add_url_rule(
|
||||
'/api/graphql',
|
||||
view_func=GraphQLView.as_view(
|
||||
'graphql',
|
||||
schema=gql.schema,
|
||||
graphiql=True # for having the GraphiQL interface
|
||||
)
|
||||
)
|
||||
|
||||
@staticmethod
|
||||
def _get_methods_from_registered_route() -> Union[list[str], str]:
|
||||
methods = ['Unknown']
|
||||
|
@@ -14,6 +14,7 @@ from bot_api.api_thread import ApiThread
|
||||
from bot_api.controller.auth_controller import AuthController
|
||||
from bot_api.controller.auth_discord_controller import AuthDiscordController
|
||||
from bot_api.controller.discord.server_controller import ServerController
|
||||
from bot_api.controller.grahpql_controller import GraphQLController
|
||||
from bot_api.controller.gui_controller import GuiController
|
||||
from bot_api.event.bot_api_on_ready_event import BotApiOnReadyEvent
|
||||
from bot_api.service.auth_service import AuthService
|
||||
@@ -47,6 +48,7 @@ class ApiModule(ModuleABC):
|
||||
services.add_transient(GuiController)
|
||||
services.add_transient(DiscordService)
|
||||
services.add_transient(ServerController)
|
||||
services.add_transient(GraphQLController)
|
||||
|
||||
# cpl-discord
|
||||
self._dc.add_event(DiscordEventTypesEnum.on_ready.value, BotApiOnReadyEvent)
|
||||
|
44
kdb-bot/src/bot_api/controller/grahpql_controller.py
Normal file
44
kdb-bot/src/bot_api/controller/grahpql_controller.py
Normal file
@@ -0,0 +1,44 @@
|
||||
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.abc.query_abc import QueryABC
|
||||
from bot_data.graphql.query import Query
|
||||
|
||||
|
||||
class GraphQLController:
|
||||
BasePath = f'/api/graphql'
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
config: ConfigurationABC,
|
||||
env: ApplicationEnvironmentABC,
|
||||
logger: ApiLogger,
|
||||
):
|
||||
self._config = config
|
||||
self._env = env
|
||||
self._logger = logger
|
||||
|
||||
@Route.get(f'{BasePath}/playground')
|
||||
async def playground(self):
|
||||
return PLAYGROUND_HTML, 200
|
||||
|
||||
@Route.post(f'{BasePath}')
|
||||
async def graphql(self):
|
||||
QueryABC.init()
|
||||
data = request.get_json()
|
||||
|
||||
# Note: Passing the request to the context is optional.
|
||||
# In Flask, the current request is always accessible as flask.request
|
||||
success, result = graphql_sync(
|
||||
make_executable_schema(Query),
|
||||
data,
|
||||
context_value=request
|
||||
)
|
||||
|
||||
return jsonify(result), 200 if success else 400
|
Reference in New Issue
Block a user