Skip to content

Commit f779d32

Browse files
authored
Provide contributing docs, test suite fixes and return graphql errors (#60)
1 parent 6ceb1fc commit f779d32

File tree

11 files changed

+207
-220
lines changed

11 files changed

+207
-220
lines changed

CONTRIBUTING.md

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
# Contributing
2+
3+
Thanks for helping to make gql awesome!
4+
5+
We welcome all kinds of contributions:
6+
7+
- Bug fixes
8+
- Documentation improvements
9+
- New features
10+
- Refactoring & tidying
11+
12+
13+
## Getting started
14+
15+
If you have a specific contribution in mind, be sure to check the
16+
[issues](https://github.com/graphql-python/gql/issues)
17+
and [pull requests](https://github.com/graphql-python/gql/pulls)
18+
in progress - someone could already be working on something similar
19+
and you can help out.
20+
21+
## Project setup
22+
23+
### Development with virtualenv (recommended)
24+
25+
After cloning this repo, create a virtualenv:
26+
27+
```console
28+
virtualenv gql-dev
29+
```
30+
31+
Activate the virtualenv and install dependencies by running:
32+
33+
```console
34+
python pip install -e ".[test]"
35+
```
36+
37+
If you are using Linux or MacOS, you can make use of Makefile command
38+
`make dev-setup`, which is a shortcut for the above python command.
39+
40+
### Development on Conda
41+
42+
You must create a new env (e.g. `gql-dev`) with the following command:
43+
44+
```sh
45+
conda create -n gql-dev python=3.8
46+
```
47+
48+
Then activate the environment with `conda activate gql-dev`.
49+
50+
Proceed to install all dependencies by running:
51+
52+
```console
53+
python pip install -e ".[test]"
54+
```
55+
56+
And you ready to start development!
57+
58+
<!-- TODO: Provide environment.yml file for conda env -->
59+
60+
## Running tests
61+
62+
After developing, the full test suite can be evaluated by running:
63+
64+
```sh
65+
pytest tests --cov=gql -vv
66+
```
67+
68+
If you are using Linux or MacOS, you can make use of Makefile command
69+
`make tests`, which is a shortcut for the above python command.
70+
71+
You can also test on several python environments by using tox.
72+
73+
### Running tox on virtualenv
74+
75+
Install tox:
76+
```console
77+
pip install tox
78+
```
79+
80+
Run `tox` on your virtualenv (do not forget to activate it!)
81+
and that's it!
82+
83+
### Running tox on Conda
84+
85+
In order to run `tox` command on conda, install
86+
[tox-conda](https://github.com/tox-dev/tox-conda):
87+
88+
```sh
89+
conda install -c conda-forge tox-conda
90+
```
91+
92+
This install tox underneath so no need to install it before.
93+
94+
Then uncomment the `requires = tox-conda` line on `tox.ini` file.
95+
96+
Run `tox` and you will see all the environments being created
97+
and all passing tests. :rocket:

MANIFEST.in

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@ include MANIFEST.in
33
include CODEOWNERS
44
include LICENSE
55
include README.md
6+
include CONTRIBUTING.md
67

78
include dev_requirements.txt
9+
include Makefile
810

911
include tox.ini
1012

Makefile

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
dev-setup:
2+
python pip install -e ".[test]"
3+
4+
tests:
5+
pytest tests --cov=gql -vv

README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ client = Client(transport=RequestsHTTPTransport(
5454
url='/graphql', headers={'Authorization': 'token'}), schema=schema)
5555
```
5656

57+
## Contributing
58+
See [CONTRIBUTING.md](contributing.md)
59+
5760
## License
5861

5962
[MIT License](https://github.com/graphql-python/gql/blob/master/LICENSE)

gql/transport/requests.py

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,16 @@ def execute(self, document, variable_values=None, timeout=None):
3535
'timeout': timeout or self.default_timeout,
3636
data_key: payload
3737
}
38-
request = requests.post(self.url, **post_args)
39-
request.raise_for_status()
40-
41-
result = request.json()
42-
assert 'errors' in result or 'data' in result, 'Received non-compatible response "{}"'.format(result)
43-
return ExecutionResult(
44-
errors=result.get('errors'),
45-
data=result.get('data')
46-
)
38+
39+
response = requests.post(self.url, **post_args)
40+
try:
41+
result = response.json()
42+
if not isinstance(result, dict):
43+
raise ValueError
44+
except ValueError:
45+
result = {}
46+
47+
if 'errors' not in result and 'data' not in result:
48+
response.raise_for_status()
49+
raise requests.HTTPError("Server did not return a GraphQL result", response=response)
50+
return ExecutionResult(errors=result.get('errors'), data=result.get('data'))

gql/utils.py

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import re
1+
"""Utilities to manipulate several python objects."""
22

33

44
# From this response in Stackoverflow
@@ -8,14 +8,3 @@ def to_camel_case(snake_str):
88
# We capitalize the first letter of each component except the first one
99
# with the 'title' method and join them together.
1010
return components[0] + "".join(x.title() if x else '_' for x in components[1:])
11-
12-
13-
# From this response in Stackoverflow
14-
# http://stackoverflow.com/a/1176023/1072990
15-
def to_snake_case(name):
16-
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
17-
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()
18-
19-
20-
def to_const(string):
21-
return re.sub(r'[\W|^]+', '_', string).upper()

setup.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,14 @@
1111
'pytest==4.6.9',
1212
'pytest-cov==2.8.1',
1313
'mock==3.0.5',
14-
'vcrpy==3.0.0'
14+
'vcrpy==3.0.0',
1515
]
1616

17+
dev_requires = [
18+
'flake8==3.7.9',
19+
'check-manifest>=0.40,<1',
20+
] + tests_require
21+
1722
setup(
1823
name='gql',
1924
version='0.3.0',
@@ -42,6 +47,10 @@
4247
install_requires=install_requires,
4348
tests_require=tests_require,
4449
extras_require={
45-
'test': tests_require
46-
}
50+
'test': tests_require,
51+
'dev': dev_requires,
52+
},
53+
include_package_data=True,
54+
zip_safe=False,
55+
platforms="any",
4756
)

0 commit comments

Comments
 (0)