How execute GraphQL query in parallel?

41 Views Asked by At

I used AsyncioExecutor to execute all queries in parallel, but it is throwing an error

graphql.error.located_error.GraphQLLocatedError: There is no current event loop in thread 'Thread-2'

Code:

from flask_graphql import GraphQLView
from graphql.execution.executors.asyncio import AsyncioExecutor

app = Flask(__name__)
schema = graphene.Schema(query=Query)

app.add_url_rule('/graphql-query', view_func=GraphQLView.as_view(
    name='graphql-query',
    schema=schema,
    graphiql=True,
    batch=True,
    executor=AsyncioExecutor(),
    middleware=[authorization_middleware]
))

if __name__ == '__main__':
    app.run()

My resolver function :

async def resolve_accounts(args, info, **kwargs):
    query = AccountObject.get_query(info=info)
    account = query.all()
    return account

My query class:

class Query(graphene.ObjectType):
    accounts = graphene.ConnectionField(AccountConnection,
                                        filterBy=AccountFilters(),
                                        offset=graphene.Int(),       resolver=accounts.resolve_accounts)
0

There are 0 best solutions below