Exemple #1
0
from wsgiref.simple_server import make_server

from sqlalchemy import create_engine
from sqlalchemy.pool import StaticPool

from hiku.engine import Engine
from hiku.sources import sqlalchemy as sa
from hiku.console.ui import ConsoleApplication
from hiku.executors.sync import SyncExecutor

from tests.test_source_sqlalchemy import SA_ENGINE_KEY, SyncQueries, setup_db
from tests.test_source_sqlalchemy import get_queries, get_graph


if __name__ == '__main__':
    engine = Engine(SyncExecutor())

    sa_engine = create_engine(
        'sqlite://',
        connect_args={'check_same_thread': False},
        poolclass=StaticPool,
    )
    setup_db(sa_engine)

    graph = get_graph(sa, get_queries(sa, SA_ENGINE_KEY, SyncQueries))

    app = ConsoleApplication(graph, engine, {SA_ENGINE_KEY: sa_engine},
                             debug=True)
    http_server = make_server('localhost', 5000, app)
    http_server.serve_forever()
Exemple #2
0
 def queries(self):
     return get_queries(hiku.sources.aiopg, SA_ENGINE_KEY, AsyncQueries)
Exemple #3
0
    try:
        query = read(data['query'], data.get('variables'))
        errors = validate(app.config['GRAPH'], query)
        if errors:
            result = {'errors': [{'message': e} for e in errors]}
        else:
            result = hiku_engine.execute(app.config['GRAPH'],
                                         query,
                                         ctx=app.config['HIKU_CTX'])
            result = {'data': denormalize(app.config['GRAPH'], result, query)}
    except Exception as err:
        result = {'errors': [{'message': repr(err)}]}
    return jsonify(result)


if __name__ == "__main__":
    sa_engine = create_engine('sqlite://',
                              connect_args={'check_same_thread': False},
                              poolclass=StaticPool)
    setup_db(sa_engine)

    app.config['HIKU_ENGINE'] = Engine(SyncExecutor())
    app.config['HIKU_CTX'] = {SA_ENGINE_KEY: sa_engine}

    graph = get_graph(get_queries(hiku.sources.sqlalchemy, SA_ENGINE_KEY,
                                  SyncQueries))
    graph = apply(graph, [GraphQLIntrospection()])
    app.config['GRAPH'] = graph

    app.run()
Exemple #4
0
 def queries(self):
     return get_queries(sa, SA_ENGINE_KEY, AsyncQueries)