diff --git a/gql/transport/aiohttp.py b/gql/transport/aiohttp.py index e6e3a782..2b155870 100644 --- a/gql/transport/aiohttp.py +++ b/gql/transport/aiohttp.py @@ -325,6 +325,9 @@ async def raise_response_error(resp: aiohttp.ClientResponse, reason: str): except Exception: await raise_response_error(resp, "Not a JSON answer") + if result is None: + await raise_response_error(resp, "Not a JSON answer") + if "errors" not in result and "data" not in result: await raise_response_error(resp, 'No "data" or "errors" keys in answer') diff --git a/tests/test_aiohttp.py b/tests/test_aiohttp.py index f4899c82..d78e4333 100644 --- a/tests/test_aiohttp.py +++ b/tests/test_aiohttp.py @@ -299,6 +299,12 @@ async def handler(request): 'No "data" or "errors" keys in answer: {"not_data_or_errors": 35}' ), }, + { + "response": "", + "expected_exception": ( + "Server did not return a GraphQL result: Not a JSON answer: " + ), + }, ]