Skip to content

Commit 368a33c

Browse files
author
bruce
committed
Merge branch 'master' of https://github.com/alaptseu/python-graphql-client into alaptseu-master
Resolve minor conflicts with updates from alaptseu PR prisma-labs#10
2 parents 7eecc87 + 28fcb39 commit 368a33c

File tree

3 files changed

+15
-0
lines changed

3 files changed

+15
-0
lines changed

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
.DS_Store
22
*.egg-info
33
*.pyc
4+
*.idea
5+
example2_run.py

README.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,13 @@ An alternative http header name for the token can be set by passing in the alter
4343
client.inject_token('very-long-and-secure-token','x-api-key')
4444
```
4545

46+
If you need more options for headers use
47+
48+
```py
49+
client.inject_headers({'your_custom_header_name' : 'your_custom_header_value' ,
50+
'your_custom_header_name_2' :'your_custom_header_value_2'})
51+
```
52+
4653
## License
4754

4855
[MIT License](http://opensource.org/licenses/MIT)

graphqlclient/client.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ def __init__(self, endpoint):
66
self.endpoint = endpoint
77
self.token = None
88
self.headername = None
9+
self.headersDict = None
910

1011
def execute(self, query, variables=None):
1112
return self._send(query, variables)
@@ -14,6 +15,9 @@ def inject_token(self, token, headername='Authorization'):
1415
self.token = token
1516
self.headername = headername
1617

18+
def inject_headers(self, headersDict):
19+
self.headersDict = headersDict
20+
1721
def _send(self, query, variables):
1822
data = {'query': query,
1923
'variables': variables}
@@ -22,6 +26,8 @@ def _send(self, query, variables):
2226

2327
if self.token is not None:
2428
headers[self.headername] = '{}'.format(self.token)
29+
if self.headersDict is not None:
30+
headers.update(self.headersDict)
2531

2632
req = urllib.request.Request(self.endpoint, json.dumps(data).encode('utf-8'), headers)
2733

0 commit comments

Comments
 (0)