Skip to content

Commit 6b6d8fe

Browse files
committed
support Authorization header
1 parent 63b989b commit 6b6d8fe

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

graphqlclient/client.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,16 +4,23 @@
44
class GraphQLClient:
55
def __init__(self, endpoint):
66
self.endpoint = endpoint
7+
self.token = None
78

89
def execute(self, query, variables=None):
910
return self._send(query, variables)
1011

12+
def inject_token(self, token):
13+
self.token = token
14+
1115
def _send(self, query, variables):
1216
data = {'query': query,
1317
'variables': variables}
1418
headers = {'Accept': 'application/json',
1519
'Content-Type': 'application/json'}
1620

21+
if self.token is not None:
22+
headers['Authorization'] = 'Bearer %s' % self.token
23+
1724
req = urllib2.Request(self.endpoint, json.dumps(data), headers)
1825

1926
try:

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
from setuptools import setup
22

33
setup(name='graphqlclient',
4-
version='0.1.1',
4+
version='0.1.2',
55
description='Simple GraphQL client for Python 2.7+',
66
url='https://github.com/graphcool/python-graphql-client',
77
author='graph.cool',

0 commit comments

Comments
 (0)