Skip to content

Contributing docs and refactor dev packages #35

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 16, 2020
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
.pytest_cache
.tox
.venv
.vscode

/build/
/dist/
Expand Down
38 changes: 16 additions & 22 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,28 +1,22 @@
language: python
sudo: false
python:
- 2.7
- 3.5
- 3.6
- 3.7
- 3.8
- 3.9-dev
- pypy
- pypy3
matrix:
include:
- python: "3.7"
env: TOX_ENV=black,flake8,mypy,py37
- python: "3.6"
env: TOX_ENV=py36
- python: "3.5"
env: TOX_ENV=py35
- python: "2.7"
env: TOX_ENV=py27
- python: pypy3
env: TOX_ENV=pypy3
- python: pypy
env: TOX_ENV=pypy
cache:
directories:
- "$HOME/.cache/pip"
- "$TRAVIS_BUILD_DIR/.tox"
install:
- pip install tox codecov
script:
- tox -e $TOX_ENV -- --cov-report term-missing --cov=graphql_server
after_success:
- codecov
- python: 3.6
env: TOXENV=flake8,black,import-order,mypy,manifest
cache: pip
install: pip install tox-travis codecov
script: tox
after_success: codecov
deploy:
provider: pypi
on:
Expand Down
93 changes: 93 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,93 @@
# Contributing

Thanks for helping to make graphql-server-core 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/graphql-server-core/issues) and [pull requests](https://github.com/graphql-python/graphql-server-core/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 graphql-server-core-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. `graphql-sc-dev`) with the following command:

```sh
conda create -n graphql-sc-dev python=3.8
```

Then activate the environment with `conda activate graphql-sc-dev`.

Proceed to install all dependencies by running:

```console
pip install -e ".[dev]"
```

And you ready to start development!

## Running tests

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

```sh
pytest tests --cov=graphql-server-core -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:
11 changes: 11 additions & 0 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,2 +1,13 @@
include MANIFEST.in

include README.md
include LICENSE
include CONTRIBUTING.md

include codecov.yml
include tox.ini

graft tests
prune bin

global-exclude *.py[co] __pycache__
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,6 @@ You can also use one of the existing integrations listed above as
blueprint to build your own integration or GraphQL server implementations.

Please let us know when you have built something new, so we can list it here.

## Contributing
See [CONTRIBUTING.md](CONTRIBUTING.md)
20 changes: 11 additions & 9 deletions graphql_server/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@

import six

from promise import promisify, is_thenable
from promise import promisify, is_thenable, Promise

from graphql import get_default_backend
from graphql.error import format_error as default_format_error
Expand Down Expand Up @@ -266,6 +266,7 @@ def execute_graphql_request(
backend=None, # type: GraphQLBackend
**kwargs # type: Any
):
# type: (...) -> ExecutionResult
"""Execute a GraphQL request and return an ExecutionResult.

You need to pass the GraphQL schema and the GraphQLParams that you can get
Expand Down Expand Up @@ -318,18 +319,20 @@ def get_response(
allow_only_query=False, # type: bool
**kwargs # type: Any
):
# type: (...) -> Optional[ExecutionResult]
# type: (...) -> Optional[Union[ExecutionResult, Promise[ExecutionResult]]]
"""Get an individual execution result as response, with option to catch errors.

This does the same as execute_graphql_request() except that you can catch errors
that belong to an exception class that you need to pass as a parameter.
"""
# noinspection PyBroadException
# Note: PyCharm will display a error due to the triple dot being used on Callable.
execute = (
execute_graphql_request_as_promise
if kwargs.get("return_promise", False)
else execute_graphql_request
)
execute_graphql_request
) # type: Callable[..., Union[Promise[ExecutionResult], ExecutionResult]]
if kwargs.get("return_promise", False):
execute = execute_graphql_request_as_promise

# noinspection PyBroadException
try:
execution_result = execute(schema, params, allow_only_query, **kwargs)
except catch_exc:
Expand All @@ -350,11 +353,10 @@ def format_execution_result(
"""
status_code = 200

response = None
if execution_result:
if execution_result.invalid:
status_code = 400
response = execution_result.to_dict(format_error=format_error)
else:
response = None

return FormattedResult(response, status_code)
2 changes: 1 addition & 1 deletion setup.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ max-line-length = 88
known_first_party=graphql_server

[tool:pytest]
norecursedirs = venv .venv .tox .git .cache .mypy_cache .pytest_cache
norecursedirs = venv .venv .tox .git .cache .mypy_cache .pytest_cache

[bdist_wheel]
universal=1
28 changes: 23 additions & 5 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,22 @@
from setuptools import setup, find_packages

required_packages = ["graphql-core>=2.3,<3", "promise>=2.3,<3"]
tests_require = ["pytest==4.6.9", "pytest-cov==2.8.1"]
install_requires = [
"graphql-core>=2.3,<3",
"promise>=2.3,<3",
]

tests_requires = [
"pytest==4.6.9",
"pytest-cov==2.8.1"
]

dev_requires = [
'flake8==3.7.9',
'isort<4.0.0',
'black==19.10b0',
'mypy==0.761',
'check-manifest>=0.40,<1',
] + tests_requires

setup(
name="graphql-server-core",
Expand Down Expand Up @@ -30,9 +45,12 @@
],
keywords="api graphql protocol rest",
packages=find_packages(exclude=["tests"]),
install_requires=required_packages,
tests_require=tests_require,
extras_require={"test": tests_require},
install_requires=install_requires,
tests_require=tests_requires,
extras_require={
'test': tests_requires,
'dev': dev_requires,
},
include_package_data=True,
zip_safe=False,
platforms="any",
Expand Down
13 changes: 4 additions & 9 deletions tests/test_asyncio.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,10 @@
import asyncio

from promise import Promise

from graphql.execution.executors.asyncio import AsyncioExecutor
from graphql.type.definition import (
GraphQLField,
GraphQLNonNull,
GraphQLObjectType,
)
from graphql.type.definition import GraphQLField, GraphQLNonNull, GraphQLObjectType
from graphql.type.scalars import GraphQLString
from graphql.type.schema import GraphQLSchema
from promise import Promise

import asyncio
from graphql_server import RequestParams, run_http_query

from .utils import as_dicts
Expand Down
2 changes: 1 addition & 1 deletion tests/test_helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from graphql.error import GraphQLError
from graphql.execution import ExecutionResult
from graphql.language.location import SourceLocation
from pytest import raises

from graphql_server import (
HttpQueryError,
Expand All @@ -12,7 +13,6 @@
json_encode_pretty,
load_json_body,
)
from pytest import raises


def test_json_encode():
Expand Down
6 changes: 2 additions & 4 deletions tests/test_query.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
import json

from pytest import raises

from promise import Promise

from graphql.error import GraphQLError, GraphQLSyntaxError
from graphql.execution import ExecutionResult
from promise import Promise
from pytest import raises

from graphql_server import (
HttpQueryError,
Expand Down
41 changes: 25 additions & 16 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -1,38 +1,47 @@
[tox]
envlist = black,flake8,mypy,py{38,37,36,35,py27,py3,py}
skipsdist = true
envlist =
black,flake8,import-order,mypy,manifest,
py{27,35,36,37,38,39-dev,py,py3}
; requires = tox-conda

[testenv]
passenv = *
setenv =
PYTHONPATH = {toxinidir}
deps =
.[test]
install_command = python -m pip install --ignore-installed {opts} {packages}
deps = -e.[test]
whitelist_externals =
python
commands =
pytest tests {posargs}
pip install -U setuptools
pytest --cov-report=term-missing --cov=graphql_server tests {posargs}

[testenv:black]
basepython=python3.7
deps = black==19.10b0
basepython=python3.6
deps = -e.[dev]
commands =
black --check graphql_server tests

[testenv:flake8]
basepython=python3.7
deps = flake8==3.7.9
basepython=python3.6
deps = -e.[dev]
commands =
flake8 setup.py graphql_server tests

[testenv:isort]
basepython=python3.7
deps =
isort
graphql-core>=2.3,<3
[testenv:import-order]
basepython=python3.6
deps = -e.[dev]
commands =
isort -rc graphql_server/ tests/

[testenv:mypy]
basepython=python3.7
deps = mypy==0.761
basepython=python3.6
deps = -e.[dev]
commands =
mypy graphql_server tests --ignore-missing-imports

[testenv:manifest]
basepython = python3.6
deps = -e.[dev]
commands =
check-manifest -v