Skip to content

Commit dc114f6

Browse files
committed
execute() returns now a tuple
1 parent 5860a08 commit dc114f6

File tree

5 files changed

+19
-12
lines changed

5 files changed

+19
-12
lines changed

README.md

+4-4
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ query = '''
1818
hello
1919
}
2020
'''
21-
result = graphql.execute(query)
21+
data, errors = graphql.execute(query)
2222
```
2323

2424
### Authentication
@@ -34,7 +34,7 @@ graphql.unset_headers()
3434

3535
Or directly provide them on every execution:
3636
```python
37-
result = graphql.execute(query, headers={'Authorization': 'Bearer xxxxx'})
37+
data, errors = graphql.execute(query, headers={'Authorization': 'Bearer xxxxx'})
3838
```
3939

4040
## Examples
@@ -54,7 +54,7 @@ query = '''
5454
}
5555
}
5656
'''
57-
result = graphql.execute(query)
57+
data, errors = graphql.execute(query)
5858
```
5959

6060
```json
@@ -108,7 +108,7 @@ query = '''
108108
}
109109
'''
110110
variables = {"id": "ZmlsbXM6MQ=="}
111-
result = graphql.execute(query, variables)
111+
data, errors = graphql.execute(query, variables)
112112
```
113113

114114
```json

easygraphql/__init__.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33

44
from .easygraphql import *
55

6-
__version__ = '0.0.1b0'
6+
__version__ = '0.0.2b0'

easygraphql/easygraphql.py

+10-3
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,16 @@ def execute(self, operation, variables=None, headers=None):
2424
if headers is None:
2525
headers = self.headers
2626

27-
response = requests.post(self.endpoint, json=payload, headers=headers)
27+
response = requests.post(self.endpoint, json=payload, headers=headers).json()
2828

2929
try:
30-
return response.json()['data']
30+
data = response['data']
3131
except KeyError:
32-
return response.json()['errors']
32+
data = None
33+
34+
try:
35+
errors = response['errors']
36+
except KeyError:
37+
errors = None
38+
39+
return data, errors

examples/query_film_variables.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -14,5 +14,5 @@
1414
}
1515
'''
1616
variables = {"id": "ZmlsbXM6MQ=="}
17-
result = graphql.execute(query, variables)
18-
print(json.dumps(result, indent=4))
17+
data, errors = graphql.execute(query, variables)
18+
print(json.dumps(data, indent=4))

examples/query_films.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -15,5 +15,5 @@
1515
}
1616
}
1717
'''
18-
result = graphql.execute(query)
19-
print(json.dumps(result, indent=4))
18+
data, errors = graphql.execute(query)
19+
print(json.dumps(data, indent=4))

0 commit comments

Comments
 (0)