Skip to content
2 changes: 2 additions & 0 deletions .coveragerc
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[report]
omit = */tests/*
25 changes: 14 additions & 11 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,17 @@
language: python
sudo: false
cache: pip
dist: xenial

install:
- pip install tox tox-travis

script:
- tox

after_success:
- pip install coveralls
- coveralls

matrix:
include:
- python: pypy
Expand All @@ -12,16 +24,7 @@ matrix:
env: TOX_ENV=py36
- python: '3.6'
env: TOX_ENV=import-order,flake8
cache:
directories:
- $HOME/.cache/pip
- $TRAVIS_BUILD_DIR/.tox
install:
- pip install tox coveralls
script:
- tox -e $TOX_ENV -- --cov=flask_graphql
after_success:
- coveralls

deploy:
provider: pypi
user: syrusakbary
Expand Down
49 changes: 49 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
# Contributing

Thanks for helping to make flask-graphql 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/flask-graphql/issues) and [projects](https://github.com/graphql-python/flask-graphql/projects) in progress - someone could already be working on something similar and you can help out.


## Project setup

After cloning this repo, ensure dependencies are installed by running:

```sh
make dev-setup
```

## Running tests

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

```sh
make tests
```

## Development on Conda

In order to run `tox` command on conda, you must create a new env (e.g. `flask-grapqhl-dev`) with the following command:

```sh
conda create -n flask-grapqhl-dev python=3.8
```

Then activate the environment with `conda activate flask-grapqhl-dev` and install [tox-conda](https://github.com/tox-dev/tox-conda):

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

Uncomment the `requires = tox-conda` line on `tox.ini` file and that's it! Run `tox` and you will see all the environments being created and all passing tests. :rocket:

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:
py.test tests --cov=flask_graphql -vv
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,6 @@ class UserRootValue(GraphQLView):
return request.user

```

## Contributing
See [CONTRIBUTING.md](contributing.md)
4 changes: 2 additions & 2 deletions flask_graphql/graphqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

from flask import Response, request
from flask.views import View

from graphql.type.schema import GraphQLSchema
from graphql_server import (HttpQueryError, default_format_error,
encode_execution_results, json_encode,
load_json_body, run_http_query)

from graphql.type.schema import GraphQLSchema

from .render_graphiql import render_graphiql


Expand Down
27 changes: 23 additions & 4 deletions setup.py
Original file line number Diff line number Diff line change
@@ -1,16 +1,31 @@
from setuptools import setup, find_packages

required_packages = [
install_requires = [
"graphql-core>=2.3,<3",
"flask>=0.7.0",
"graphql-server-core>=1.1,<2",
]

tests_requires = [
'pytest>=2.7.2',
'pytest-cov==2.8.1',
'pytest-flask>=0.10.0',
'graphql-core>=2.1,<3',
'graphql-server-core>=1.1,<2',
'Flask>=0.10.0',
]

dev_requires = [
'flake8==3.7.9',
'isort<4.0.0'
] + tests_requires

setup(
name="Flask-GraphQL",
version="2.0.1",
description="Adds GraphQL support to your Flask application",
long_description=open("README.rst").read(),
long_description=open("README.md").read(),
long_description_content_type="text/markdown",
url="https://github.com/graphql-python/flask-graphql",
download_url="https://github.com/graphql-python/flask-graphql/releases",
author="Syrus Akbary",
Expand All @@ -33,8 +48,12 @@
],
keywords="api graphql protocol rest flask",
packages=find_packages(exclude=["tests"]),
install_requires=required_packages,
tests_require=["pytest>=2.7.3"],
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
31 changes: 23 additions & 8 deletions tests/test_graphiqlview.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,29 @@

@pytest.fixture
def app():
return create_app(graphiql=True)
# import app factory pattern
app = create_app(graphiql=True)

# pushes an application context manually
ctx = app.app_context()
ctx.push()
return app

def test_graphiql_is_enabled(client):
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})

@pytest.fixture
def client(app):
return app.test_client()


def test_graphiql_is_enabled(app, client):
with app.test_request_context():
response = client.get(url_for('graphql', externals=False), headers={'Accept': 'text/html'})
assert response.status_code == 200


def test_graphiql_renders_pretty(client):
response = client.get(url_for('graphql', query='{test}'), headers={'Accept': 'text/html'})
def test_graphiql_renders_pretty(app, client):
with app.test_request_context():
response = client.get(url_for('graphql', query='{test}'), headers={'Accept': 'text/html'})
assert response.status_code == 200
pretty_response = (
'{\n'
Expand All @@ -28,12 +41,14 @@ def test_graphiql_renders_pretty(client):
assert pretty_response in response.data.decode('utf-8')


def test_graphiql_default_title(client):
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})
def test_graphiql_default_title(app, client):
with app.test_request_context():
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})
assert '<title>GraphiQL</title>' in response.data.decode('utf-8')


@pytest.mark.parametrize('app', [create_app(graphiql=True, graphiql_html_title="Awesome")])
def test_graphiql_custom_title(app, client):
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})
with app.test_request_context():
response = client.get(url_for('graphql'), headers={'Accept': 'text/html'})
assert '<title>Awesome</title>' in response.data.decode('utf-8')
Loading