Skip to content

Commit 38d6c87

Browse files
authored
add the data property in TransportQueryError (#136)
1 parent 12a7d0a commit 38d6c87

File tree

2 files changed

+11
-3
lines changed

2 files changed

+11
-3
lines changed

gql/client.py

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -240,7 +240,9 @@ def execute(self, document: DocumentNode, *args, **kwargs) -> Dict:
240240

241241
# Raise an error if an error is returned in the ExecutionResult object
242242
if result.errors:
243-
raise TransportQueryError(str(result.errors[0]), errors=result.errors)
243+
raise TransportQueryError(
244+
str(result.errors[0]), errors=result.errors, data=result.data
245+
)
244246

245247
assert (
246248
result.data is not None
@@ -315,7 +317,9 @@ async def subscribe(
315317

316318
# Raise an error if an error is returned in the ExecutionResult object
317319
if result.errors:
318-
raise TransportQueryError(str(result.errors[0]), errors=result.errors)
320+
raise TransportQueryError(
321+
str(result.errors[0]), errors=result.errors, data=result.data
322+
)
319323

320324
elif result.data is not None:
321325
yield result.data
@@ -340,7 +344,9 @@ async def execute(self, document: DocumentNode, *args, **kwargs) -> Dict:
340344

341345
# Raise an error if an error is returned in the ExecutionResult object
342346
if result.errors:
343-
raise TransportQueryError(str(result.errors[0]), errors=result.errors)
347+
raise TransportQueryError(
348+
str(result.errors[0]), errors=result.errors, data=result.data
349+
)
344350

345351
assert (
346352
result.data is not None

gql/transport/exceptions.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,12 @@ def __init__(
3030
msg: str,
3131
query_id: Optional[int] = None,
3232
errors: Optional[List[Any]] = None,
33+
data: Optional[Any] = None,
3334
):
3435
super().__init__(msg)
3536
self.query_id = query_id
3637
self.errors = errors
38+
self.data = data
3739

3840

3941
class TransportClosed(TransportError):

0 commit comments

Comments
 (0)