def get_app():
    model = Model()
    app = web.Application()
    app.router.add_routes(all_routes)
    app['model'] = model
    GraphQLView.attach(app,
                       route_path='/api/graphql',
                       schema=Schema,
                       graphiql=True,
                       enable_async=True,
                       executor=GQLAIOExecutor())

    subscription_server = AiohttpSubscriptionServer(Schema)

    async def subscriptions(request):
        try:
            ws = web.WebSocketResponse(protocols=('graphql-ws', ))
            await ws.prepare(request)
            await subscription_server.handle(ws, {'request': request})
            return ws
        except Exception as e:
            logger.exception('subscriptions failed: %r', e)
            raise e

    app.router.add_get('/api/subscriptions', subscriptions)
    return app
Esempio n. 2
0
        async def subscriptions(request):
            subscription_server = AiohttpSubscriptionServer(
                graphene.Schema(subscription=Subscription))
            ws = web.WebSocketResponse(protocols=('graphql-ws', ))
            await ws.prepare(request)

            await subscription_server.handle(ws)
            return ws
Esempio n. 3
0
import logging
import json
from uuid import uuid4
from graphql_ws.aiohttp import AiohttpSubscriptionServer
from aiohttp import web, WSMsgType
from graphql import format_error

from modules.template import render_graphiql
from modules.webclient import Client
#from callbacks import api_commands_consumer, opc_tag_changes
#from commands.commands import CommandRunner
from data.query import schema

subscription_server = AiohttpSubscriptionServer(schema)


class Web(object):
    def configure(self, app):
        router = app.router
        router.add_route('GET',
                         '/graphiql',
                         self.graphiql_view,
                         name='graphiql_view')
        router.add_route('GET',
                         '/graphql',
                         self.graphql_view,
                         name='graphql_view')
        router.add_route('POST',
                         '/graphql',
                         self.graphql_view,
                         name='graphql_view')
Esempio n. 4
0
def test_subscription_server_smoke():
    AiohttpSubscriptionServer(schema=None)