graphql-python / gql

A GraphQL client in Python
https://gql.readthedocs.io
MIT License
1.53k stars 178 forks source link

Invalid or incomplete introspection with async transport #101

Closed dysphie closed 4 years ago

dysphie commented 4 years ago

Hi, I seem to be having issues migrating from a blocking implementation to async. The migrated code raises an exception.

Original:

from os import getenv
from gql import gql, Client
from gql.transport.requests import RequestsHTTPTransport

query = gql('''
    query {
        user(username:"Test") {
            username
        }
    }
''')

if __name__ == '__main__':

    transport = RequestsHTTPTransport(
        url='http://api.aidungeon.io/graphql/',
        headers={'X-Access-Token': getenv('AIDUNGEON_TOKEN')}
    )

    client = Client(
        transport=transport,
        fetch_schema_from_transport=True,
    )

    result = client.execute(query)
    print(result)

Output:

{'user': {'username': 'Test'}}

Migrated

from os import getenv
from gql import gql, Client
from gql.transport.aiohttp import AIOHTTPTransport
import asyncio

query = gql('''
    query {
        user(username:"Test") {
            username
        }
    }
''')

async def main():

    transport = AIOHTTPTransport(
    url='http://api.aidungeon.io/graphql/',
    headers={'X-Access-Token': getenv('AIDUNGEON_TOKEN')}
    )

    client = Client(
        transport=transport,
        fetch_schema_from_transport=True
    )

    async with client as session:
        result = await session.execute(query)
        print(result)

asyncio.run(main())

Output:

TypeError: Invalid or incomplete introspection result. Ensure that you are passing the 'data' attribute of an introspection response and no 'errors' were returned alongside: None.

Not sure how to proceed. Thanks

leszekhanusz commented 4 years ago

Hi,

This is a duplicate of bug #92 It is solved with PR #94

jsbroks commented 4 years ago

@leszekhanusz I've cloned master and did 'pip3 install .', but still get

Invalid or incomplete introspection result. Ensure that you are passing the 'data' attribute of an introspection response and no 'errors' were returned alongside: None.
jsbroks commented 4 years ago

@leszekhanusz Your PR does not fix the same error when using the WebsocketsTransport transport

megakid commented 2 years ago

Just a note to others, or maybe I was just being dumb, but I was missing a / at the end of the graphql URL:

e.g.

transport = AIOHTTPTransport(url="https://api.octopus.energy/v1/graphql/") # works

vs

transport = AIOHTTPTransport(url="https://api.octopus.energy/v1/graphql") # does not work