Skip to content

Data loading (batching) for sync apps #915

Answered by pylipp
pylipp asked this question in Q&A
Discussion options

You must be logged in to vote

I found a way to integrate aiodataloader in my WSGI flask app like so:

# routes.py
import asyncio
from ariadne import graphql
from flask import Flask, request, jsonify
from .loaders import AuthorLoader
from .schema import full_api_schema

app = Flask(__name__)
# omitting database config with peewee via playhouse.flask_utils

@app.route("/graphql", methods=["POST"])
def graphql_server():
    # Start async event loop, required for DataLoader construction, cf.
    # https://github.com/graphql-python/graphql-core/issues/71#issuecomment-620106364
    loop = asyncio.new_event_loop()
    asyncio.set_event_loop(loop)

    # Create DataLoaders and persist them for the time of processing the request

Replies: 2 comments 1 reply

Comment options

You must be logged in to vote
0 replies
Answer selected by pylipp
Comment options

You must be logged in to vote
1 reply
@shoelessness
Comment options

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants