diff --git a/pyproject.toml b/pyproject.toml index 77278c2..0180d86 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -21,7 +21,7 @@ classifiers = [ requires-python = ">=3.9" dependencies = [ "aiohttp[speedups]~=3.8", - "gql[aiohttp,requests]>=3.5.1,<5", + "gql[aiohttp,requests]>=4,<5", "pyjwt[crypto]~=2.8", "requests~=2.31", ] diff --git a/src/simple_github/client.py b/src/simple_github/client.py index d2e1d5c..13b59f8 100644 --- a/src/simple_github/client.py +++ b/src/simple_github/client.py @@ -208,7 +208,9 @@ def execute(self, query: str, variables: RequestData = None) -> Dict[str, Any]: Dict: The result of the executed query. """ session = self._get_gql_session() - return session.execute(gql(query), variable_values=variables) + gql_query = gql(query) + gql_query.variable_values = variables + return session.execute(gql_query) class AsyncClient(Client): @@ -350,4 +352,6 @@ async def execute( Dict: The result of the executed query. """ session = await self._get_gql_session() - return await session.execute(gql(query), variable_values=variables) + gql_query = gql(query) + gql_query.variable_values = variables + return await session.execute(gql_query) diff --git a/test/test_client.py b/test/test_client.py index d163964..3c372f3 100644 --- a/test/test_client.py +++ b/test/test_client.py @@ -219,17 +219,41 @@ def test_sync_client_rest_with_text(responses, sync_client): @pytest.mark.asyncio async def test_async_client_graphql(aioresponses, async_client): client = async_client + aioresponses.post( - GITHUB_GRAPHQL_ENDPOINT, status=200, payload={"data": {"foo": "bar"}} + GITHUB_GRAPHQL_ENDPOINT, + status=200, + payload={"data": {"foo": "bar"}}, ) query = "query { viewer { login }}" result = await client.execute(query) assert result == {"foo": "bar"} + aioresponses.post( + GITHUB_GRAPHQL_ENDPOINT, + status=200, + payload={"data": {"user": {"email": "octocat@github.com"}}}, + ) + query = "query($user:String!) { user(login: $user) { email }}" + variables = {"user": "octocat"} + result = await client.execute(query, variables) + assert result == {"user": {"email": "octocat@github.com"}} + def test_sync_client_graphql(responses, sync_client): client = sync_client + responses.post(GITHUB_GRAPHQL_ENDPOINT, status=200, json={"data": {"foo": "bar"}}) query = "query { viewer { login }}" result = client.execute(query) assert result == {"foo": "bar"} + + responses.post( + GITHUB_GRAPHQL_ENDPOINT, + status=200, + json={"data": {"user": {"email": "octocat@github.com"}}}, + ) + query = "query($user:String!) { user(login: $user) { email }}" + variables = {"user": "octocat"} + result = client.execute(query, variables) + assert result == {"user": {"email": "octocat@github.com"}} diff --git a/uv.lock b/uv.lock index 3d625d7..ef3de5e 100644 --- a/uv.lock +++ b/uv.lock @@ -1616,7 +1616,7 @@ dev = [ [package.metadata] requires-dist = [ { name = "aiohttp", extras = ["speedups"], specifier = "~=3.8" }, - { name = "gql", extras = ["aiohttp", "requests"], specifier = ">=3.5.1,<5" }, + { name = "gql", extras = ["aiohttp", "requests"], specifier = ">=4,<5" }, { name = "pyjwt", extras = ["crypto"], specifier = "~=2.8" }, { name = "requests", specifier = "~=2.31" }, ]