pythonhttpsgql

python-gql async execute_batch error with httpx transport


I am following this example to implement client with httpx transport. However, I'm getting this error: AttributeError: 'AsyncClientSession' object has no attribute 'execute_batch'

This is the code that I'm trying to execute:

from gql import Client, GraphQLRequest
from gql.transport.httpx import HTTPXAsyncTransport
from itertools import batched
import asyncio

async def main():
    async with Client(
        transport=HTTPXAsyncTransport(url=GQL_URL, headers=GQL_HEADERS, timeout=3000), batch_interval=5
    ) as session:
        res = await session.execute_batch([
            GraphQLRequest(document=QUERY, variable_values=VARIABLES) for batch in batched(DATA, 1000)
        ])
        print(res)


asyncio.run(main())

Solution

  • The method execute_batch will be introduced in version 4 of gql library.

    Still in beta, so if you are not afraid of bugs, you can install it using:

    pip install gql==v4.0.0b0