Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
97 changes: 97 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
# Contributing

Thanks for helping to make gql awesome!

We welcome all kinds of contributions:

- Bug fixes
- Documentation improvements
- New features
- Refactoring & tidying


## Getting started

If you have a specific contribution in mind, be sure to check the
[issues](https://github.com/graphql-python/gql/issues)
and [pull requests](https://github.com/graphql-python/gql/pulls)
in progress - someone could already be working on something similar
and you can help out.

## Project setup

### Development with virtualenv (recommended)

After cloning this repo, create a virtualenv:

```console
virtualenv gql-dev
```

Activate the virtualenv and install dependencies by running:

```console
python pip install -e ".[test]"
```

If you are using Linux or MacOS, you can make use of Makefile command
`make dev-setup`, which is a shortcut for the above python command.

### Development on Conda

You must create a new env (e.g. `gql-dev`) with the following command:

```sh
conda create -n gql-dev python=3.8
```

Then activate the environment with `conda activate gql-dev`.

Proceed to install all dependencies by running:

```console
python pip install -e ".[test]"
```

And you ready to start development!

<!-- TODO: Provide environment.yml file for conda env -->

## Running tests

After developing, the full test suite can be evaluated by running:

```sh
pytest tests --cov=gql -vv
```

If you are using Linux or MacOS, you can make use of Makefile command
`make tests`, which is a shortcut for the above python command.

You can also test on several python environments by using tox.

### Running tox on virtualenv

Install tox:
```console
pip install tox
```

Run `tox` on your virtualenv (do not forget to activate it!)
and that's it!

### Running tox on Conda

In order to run `tox` command on conda, install
[tox-conda](https://github.com/tox-dev/tox-conda):

```sh
conda install -c conda-forge tox-conda
```

This install tox underneath so no need to install it before.

Then uncomment the `requires = tox-conda` line on `tox.ini` file.

Run `tox` and you will see all the environments being created
and all passing tests. :rocket:
2 changes: 2 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ include MANIFEST.in
include CODEOWNERS
include LICENSE
include README.md
include CONTRIBUTING.md

include dev_requirements.txt
include Makefile

include tox.ini

Expand Down
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
dev-setup:
python pip install -e ".[test]"

tests:
pytest tests --cov=gql -vv
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ client = Client(transport=RequestsHTTPTransport(
url='/graphql', headers={'Authorization': 'token'}), schema=schema)
```

## Contributing
See [CONTRIBUTING.md](contributing.md)

## License

[MIT License](https://github.com/graphql-python/gql/blob/master/LICENSE)
22 changes: 13 additions & 9 deletions gql/transport/requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,16 @@ def execute(self, document, variable_values=None, timeout=None):
'timeout': timeout or self.default_timeout,
data_key: payload
}
request = requests.post(self.url, **post_args)
request.raise_for_status()

result = request.json()
assert 'errors' in result or 'data' in result, 'Received non-compatible response "{}"'.format(result)
return ExecutionResult(
errors=result.get('errors'),
data=result.get('data')
)

response = requests.post(self.url, **post_args)
try:
result = response.json()
if not isinstance(result, dict):
raise ValueError
except ValueError:
result = {}

if 'errors' not in result and 'data' not in result:
response.raise_for_status()
raise requests.HTTPError("Server did not return a GraphQL result", response=response)
return ExecutionResult(errors=result.get('errors'), data=result.get('data'))
13 changes: 1 addition & 12 deletions gql/utils.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import re
"""Utilities to manipulate several python objects."""


# From this response in Stackoverflow
Expand All @@ -8,14 +8,3 @@ def to_camel_case(snake_str):
# We capitalize the first letter of each component except the first one
# with the 'title' method and join them together.
return components[0] + "".join(x.title() if x else '_' for x in components[1:])


# From this response in Stackoverflow
# http://stackoverflow.com/a/1176023/1072990
def to_snake_case(name):
s1 = re.sub('(.)([A-Z][a-z]+)', r'\1_\2', name)
return re.sub('([a-z0-9])([A-Z])', r'\1_\2', s1).lower()


def to_const(string):
return re.sub(r'[\W|^]+', '_', string).upper()
15 changes: 12 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,14 @@
'pytest==4.6.9',
'pytest-cov==2.8.1',
'mock==3.0.5',
'vcrpy==3.0.0'
'vcrpy==3.0.0',
]

dev_requires = [
'flake8==3.7.9',
'check-manifest>=0.40,<1',
] + tests_require

setup(
name='gql',
version='0.3.0',
Expand Down Expand Up @@ -42,6 +47,10 @@
install_requires=install_requires,
tests_require=tests_require,
extras_require={
'test': tests_require
}
'test': tests_require,
'dev': dev_requires,
},
include_package_data=True,
zip_safe=False,
platforms="any",
)
Loading