Skip to content

Commit 3421a40

Browse files
committed
use **kargs
1 parent 5af59e2 commit 3421a40

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ Set `options` to `{"verify": False}` ether when instantiating the `GraphqlClient
8181
```py
8282
from python_graphql_client import GraphqlClient
8383

84-
client = GraphqlClient(endpoint="wss://www.your-api.com/graphql", options={"verify": False})
84+
client = GraphqlClient(endpoint="wss://www.your-api.com/graphql", verify=False)
8585
```
8686

8787
Alternatively, you can set it when calling the `execute` method.
@@ -90,7 +90,7 @@ Alternatively, you can set it when calling the `execute` method.
9090
from python_graphql_client import GraphqlClient
9191

9292
client = GraphqlClient(endpoint="wss://www.your-api.com/graphql"
93-
client.execute(query="<Your Query>", options={"verify": False}))
93+
client.execute(query="<Your Query>", verify=False))
9494
```
9595

9696
### Custom Authentication

python_graphql_client/graphql_client.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
"""Module containing graphQL client."""
22
import json
33
import logging
4-
from typing import Callable
4+
from typing import Any, Callable
55

66
import aiohttp
77
import requests
@@ -13,11 +13,11 @@
1313
class GraphqlClient:
1414
"""Class which represents the interface to make graphQL requests through."""
1515

16-
def __init__(self, endpoint: str, headers: dict = {}, options: dict = {}):
16+
def __init__(self, endpoint: str, headers: dict = {}, **kwargs: Any):
1717
"""Insantiate the client."""
1818
self.endpoint = endpoint
1919
self.headers = headers
20-
self.options = options
20+
self.options = kwargs
2121

2222
def __request_body(
2323
self, query: str, variables: dict = None, operation_name: str = None
@@ -38,7 +38,7 @@ def execute(
3838
variables: dict = None,
3939
operation_name: str = None,
4040
headers: dict = {},
41-
options: dict = {},
41+
**kwargs: Any,
4242
):
4343
"""Make synchronous request to graphQL server."""
4444
request_body = self.__request_body(
@@ -49,7 +49,7 @@ def execute(
4949
self.endpoint,
5050
json=request_body,
5151
headers={**self.headers, **headers},
52-
**{**self.options, **options},
52+
**{**self.options, **kwargs},
5353
)
5454

5555
result.raise_for_status()

tests/test_graphql_client.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,10 +105,10 @@ def test_execute_query_with_options(self, post_mock):
105105
auth = HTTPBasicAuth("fake@example.com", "not_a_real_password")
106106
client = GraphqlClient(
107107
endpoint="http://www.test-api.com/",
108-
options={"auth": auth},
108+
auth=auth,
109109
)
110110
query = ""
111-
client.execute(query=query, options={"verify": False})
111+
client.execute(query=query, verify=False)
112112

113113
post_mock.assert_called_once_with(
114114
"http://www.test-api.com/",

0 commit comments

Comments
 (0)