From da22acc0e10cd3d322f07958daecaae41d607e47 Mon Sep 17 00:00:00 2001 From: Jonathan Leitschuh Date: Mon, 3 Oct 2022 18:18:06 -0400 Subject: [PATCH 1/3] Handle JSON response being `None` --- gql/transport/aiohttp.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/gql/transport/aiohttp.py b/gql/transport/aiohttp.py index f4f38b69..8635a030 100644 --- a/gql/transport/aiohttp.py +++ b/gql/transport/aiohttp.py @@ -321,6 +321,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') From e485b612d915be831d69bbb1939aa166a52c2511 Mon Sep 17 00:00:00 2001 From: Hanusz Leszek Date: Mon, 7 Nov 2022 23:07:56 +0100 Subject: [PATCH 2/3] Running 'make check' --- gql/transport/aiohttp.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/gql/transport/aiohttp.py b/gql/transport/aiohttp.py index 8635a030..52ca3559 100644 --- a/gql/transport/aiohttp.py +++ b/gql/transport/aiohttp.py @@ -321,7 +321,7 @@ 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") From 0336607adcc4c003245909507e9f9cdb11688f44 Mon Sep 17 00:00:00 2001 From: Hanusz Leszek Date: Mon, 7 Nov 2022 23:20:12 +0100 Subject: [PATCH 3/3] Add test for empty json response --- tests/test_aiohttp.py | 6 ++++++ 1 file changed, 6 insertions(+) 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: " + ), + }, ]