Skip to content

Commit d48669a

Browse files
authored
Merge pull request #57 from Tom1204/master
add passing options
2 parents a3371e0 + 081283a commit d48669a

File tree

2 files changed

+36
-2
lines changed

2 files changed

+36
-2
lines changed

python_graphql_client/graphql_client.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Module containing graphQL client."""
2+
23
import json
34
import logging
45
from typing import Any, Callable
@@ -60,6 +61,7 @@ async def execute_async(
6061
variables: dict = None,
6162
operation_name: str = None,
6263
headers: dict = {},
64+
**kwargs: Any,
6365
):
6466
"""Make asynchronous request to graphQL server."""
6567
request_body = self.__request_body(
@@ -69,8 +71,12 @@ async def execute_async(
6971
async with aiohttp.ClientSession() as session:
7072
async with session.post(
7173
self.endpoint,
72-
json=request_body,
73-
headers={**self.headers, **headers},
74+
**{
75+
**self.options,
76+
**kwargs,
77+
"headers": {**self.headers, **headers},
78+
"json": request_body,
79+
},
7480
) as response:
7581
return await response.json()
7682

tests/test_graphql_client.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -171,6 +171,34 @@ async def test_execute_basic_query(self, mock_post):
171171
"http://www.test-api.com/", json={"query": query}, headers={}
172172
)
173173

174+
@patch("aiohttp.ClientSession.post")
175+
async def test_execute_basic_query_with_aiohttp_parameters(self, mock_post):
176+
"""Sends a graphql POST request to an endpoint."""
177+
mock_post.return_value.__aenter__.return_value.json = AsyncMock()
178+
client = GraphqlClient(endpoint="http://www.test-api.com/")
179+
query = """
180+
{
181+
tests {
182+
status
183+
}
184+
}
185+
"""
186+
187+
await client.execute_async(
188+
query,
189+
timeout=10,
190+
verify_ssl=False,
191+
headers={"Authorization": "Bearer token"},
192+
)
193+
194+
mock_post.assert_called_once_with(
195+
"http://www.test-api.com/",
196+
json={"query": query},
197+
headers={"Authorization": "Bearer token"},
198+
timeout=10,
199+
verify_ssl=False,
200+
)
201+
174202
@patch("aiohttp.ClientSession.post")
175203
async def test_execute_query_with_variables(self, mock_post):
176204
"""Sends a graphql POST request with variables."""

0 commit comments

Comments
 (0)