File tree Expand file tree Collapse file tree 3 files changed +31
-4
lines changed
integration/entrypoints/client Expand file tree Collapse file tree 3 files changed +31
-4
lines changed Original file line number Diff line number Diff line change 44import os
55import threading
66import time
7+ import warnings
78from pathlib import Path
89from typing import Any , Optional , Union
910from urllib .parse import urlparse
@@ -325,6 +326,7 @@ def _raw_execute(
325326 res = self ._gql_client .execute (
326327 document = document ,
327328 variable_values = variables ,
329+ get_execution_result = True ,
328330 extra_args = {
329331 "headers" : {
330332 ** (self ._gql_transport .headers or {}),
@@ -333,9 +335,24 @@ def _raw_execute(
333335 },
334336 ** kwargs ,
335337 )
338+
339+ extensions = getattr (res , "extensions" , None )
340+ if isinstance (extensions , dict ):
341+ for item in extensions .get ("deprecations" ) or []:
342+ warnings .warn (
343+ f"[Kili SDK] Deprecated GraphQL field used: "
344+ f"{ item .get ('path' )} – { item .get ('reason' )} "
345+ )
346+
336347 transport = self ._gql_client .transport
337348 if transport :
338349 headers = transport .response_headers # pyright: ignore[reportAttributeAccessIssue]
339350 returned_complexity = int (headers .get ("x-complexity" , 0 )) if headers else 0
340351 self .complexity_consumed += returned_complexity
341- return res
352+
353+ if res .data is None :
354+ raise kili .exceptions .GraphQLError (
355+ error = "GraphQL response contains no data" ,
356+ )
357+
358+ return res .data
Original file line number Diff line number Diff line change 77import pytest
88import pytest_mock
99from filelock import FileLock
10+ from graphql import ExecutionResult
1011
1112from kili .adapters .kili_api_gateway .kili_api_gateway import KiliAPIGateway
1213from kili .client import Kili
@@ -147,7 +148,10 @@ def test_complexity_increases_with_calls(
147148 mocker : pytest_mock .MockerFixture ,
148149):
149150 graphql_mock = mocker .MagicMock ()
150- graphql_mock .execute .return_value = {"data" : 1 }
151+ graphql_mock .execute .return_value = ExecutionResult (
152+ data = {"data" : 1 },
153+ extensions = None ,
154+ )
151155 graphql_mock .transport .response_headers = {"x-complexity" : "125" }
152156
153157 # Given
@@ -172,7 +176,10 @@ def test_complexity_compatibility_with_legacy(
172176 mocker : pytest_mock .MockerFixture ,
173177):
174178 graphql_mock = mocker .MagicMock ()
175- graphql_mock .execute .return_value = {"data" : 1 }
179+ graphql_mock .execute .return_value = ExecutionResult (
180+ data = {"data" : 1 },
181+ extensions = None ,
182+ )
176183 graphql_mock .transport .response_headers = {}
177184
178185 # Given
Original file line number Diff line number Diff line change 55import pytest_mock
66from gql import Client
77from gql .transport import exceptions
8+ from graphql import ExecutionResult
89from pyrate_limiter import Duration , Rate
910from pyrate_limiter .limiter import Limiter
1011
@@ -88,9 +89,11 @@ def mock_execute(*args, **kwargs):
8889 nonlocal before_last_call_timestamp
8990 before_last_call_timestamp = last_call_timestamp
9091 last_call_timestamp = time ()
92+ return ExecutionResult ({"data" : 1 }, extensions = None )
9193
9294 client ._gql_client = mocker .MagicMock ()
9395 client ._gql_client .execute .side_effect = mock_execute
96+ client ._gql_client .transport .response_headers = {}
9497
9598 # first calls should not be rate limited
9699 for _ in range (MAX_CALLS_PER_MINUTE ):
@@ -162,7 +165,7 @@ def mocked_backend_response(*args, **kwargs):
162165 nonlocal nb_times_called
163166 nb_times_called += 1
164167 if nb_times_called > 2 :
165- return {"data" : "all good" }
168+ return ExecutionResult ( {"data" : "all good" }, extensions = None )
166169 raise exceptions .TransportQueryError (
167170 msg = (
168171 "[unexpectedRetrieving] Unexpected error when retrieving runtime information."
You can’t perform that action at this time.
0 commit comments