Skip to content
Permalink

Comparing changes

Choose two branches to see what’s changed or to start a new pull request. If you need to, you can also or learn more about diff comparisons.

Open a pull request

Create a new pull request by comparing changes across two branches. If you need to, you can also . Learn more about diff comparisons here.
base repository: graphql-python/flask-graphql
Failed to load repositories. Confirm that selected base ref is valid, then try again.
Loading
base: v2.0rc0
Choose a base ref
...
head repository: graphql-python/flask-graphql
Failed to load repositories. Confirm that selected head ref is valid, then try again.
Loading
compare: master
Choose a head ref
  • 17 commits
  • 17 files changed
  • 5 contributors

Commits on Jul 19, 2018

  1. Copy the full SHA
    3d607a0 View commit details
  2. Copy the full SHA
    64bab07 View commit details
  3. Updated version to 2.0.0

    syrusakbary committed Jul 19, 2018
    Copy the full SHA
    4183613 View commit details

Commits on Jun 28, 2019

  1. Pin graphql-core to <3

    jkimbo authored Jun 28, 2019
    Copy the full SHA
    9a75ebc View commit details

Commits on Dec 3, 2019

  1. Fix (hopefully) travis builds

    Stefano authored Dec 3, 2019
    Copy the full SHA
    000169f View commit details
  2. Pin graphql-core in test deps as well

    Stefano authored Dec 3, 2019
    Copy the full SHA
    f331f17 View commit details

Commits on Dec 5, 2019

  1. Fix travis builds (#65)

    Fix travis builds
    jkimbo authored Dec 5, 2019
    Copy the full SHA
    4aa86e3 View commit details
  2. Pin graphql-core to <3 (#60)

    Pin graphql-core to <3
    jkimbo authored Dec 5, 2019
    Copy the full SHA
    e22153e View commit details
  3. v2.0.1

    jkimbo authored Dec 5, 2019
    Copy the full SHA
    0137ca1 View commit details

Commits on Feb 25, 2020

  1. Update context and root executor options (#74)

    * Pass context and root value to executor opts
    
    * Bump graphql-core minimum version to 2.3
    
    * Fix graphqlview custom context test
    
    * Pass app fixture on graphiqlview
    KingDarBoja authored Feb 25, 2020
    Copy the full SHA
    d29cc6f View commit details

Commits on Mar 14, 2020

  1. Contributing docs and refactor tox config (#77)

    * chore: contributing docs and tox config
    
    * chore: add pytest-cov and syntax fixes
    
    * chore: sort imports on graphqlview
    
    * chore: comment out tox-conda on tox file
    
    * chore: remove readme rst
    
    * chore: add check manifest to dev dependencies
    
    * chore: remove matrix jobs on travis
    
    * chore: add pyversions to Travis CI
    
    * chore: remove py33 and py34 from classifiers
    KingDarBoja authored Mar 14, 2020
    Copy the full SHA
    88089b6 View commit details
  2. Add anaconda cloud badge to flask-graphql (#73)

    * Add anaconda cloud badge to flask-graphql
    
    * docs: update readme and contributing link
    KingDarBoja authored Mar 14, 2020
    Copy the full SHA
    9691baf View commit details

Commits on Aug 7, 2020

  1. Copy the full SHA
    5f79ab8 View commit details
  2. Copy the full SHA
    dfd863d View commit details
  3. Copy the full SHA
    d1ac3a5 View commit details
  4. Copy the full SHA
    2f627ed View commit details
  5. Merge pull request #82 from KingDarBoja/flask-graphql-v3

    chore: use graphql-server to re-export flask
    syrusakbary authored Aug 7, 2020
    Copy the full SHA
    0d45561 View commit details
Showing with 779 additions and 809 deletions.
  1. +201 −7 .gitignore
  2. +13 −19 .travis.yml
  3. +9 −2 MANIFEST.in
  4. +5 −0 Makefile
  5. +56 −9 README.md
  6. +0 −63 README.rst
  7. +2 −3 flask_graphql/__init__.py
  8. +0 −17 flask_graphql/blueprint.py
  9. +0 −154 flask_graphql/graphqlview.py
  10. +0 −138 flask_graphql/render_graphiql.py
  11. +3 −3 setup.cfg
  12. +42 −29 setup.py
  13. +7 −8 tests/app.py
  14. +30 −21 tests/schema.py
  15. +39 −18 tests/test_graphiqlview.py
  16. +351 −298 tests/test_graphqlview.py
  17. +21 −20 tox.ini
208 changes: 201 additions & 7 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,10 +1,204 @@
*.pyc
.idea
.cache
.tox

# Created by https://www.gitignore.io/api/python,intellij+all,visualstudiocode
# Edit at https://www.gitignore.io/?templates=python,intellij+all,visualstudiocode

### Intellij+all ###
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839

# User-specific stuff
.idea/**/workspace.xml
.idea/**/tasks.xml
.idea/**/usage.statistics.xml
.idea/**/dictionaries
.idea/**/shelf

# Generated files
.idea/**/contentModel.xml

# Sensitive or high-churn files
.idea/**/dataSources/
.idea/**/dataSources.ids
.idea/**/dataSources.local.xml
.idea/**/sqlDataSources.xml
.idea/**/dynamic.xml
.idea/**/uiDesigner.xml
.idea/**/dbnavigator.xml

# Gradle
.idea/**/gradle.xml
.idea/**/libraries

# Gradle and Maven with auto-import
# When using Gradle or Maven with auto-import, you should exclude module files,
# since they will be recreated, and may cause churn. Uncomment if using
# auto-import.
# .idea/modules.xml
# .idea/*.iml
# .idea/modules
# *.iml
# *.ipr

# CMake
cmake-build-*/

# Mongo Explorer plugin
.idea/**/mongoSettings.xml

# File-based project format
*.iws

# IntelliJ
out/

# mpeltonen/sbt-idea plugin
.idea_modules/

# JIRA plugin
atlassian-ide-plugin.xml

# Cursive Clojure plugin
.idea/replstate.xml

# Crashlytics plugin (for Android Studio and IntelliJ)
com_crashlytics_export_strings.xml
crashlytics.properties
crashlytics-build.properties
fabric.properties

# Editor-based Rest Client
.idea/httpRequests

# Android studio 3.1+ serialized cache file
.idea/caches/build_file_checksums.ser

### Intellij+all Patch ###
# Ignores the whole .idea folder and all .iml files
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360

.idea/

# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023

*.iml
modules.xml
.idea/misc.xml
*.ipr

# Sonarlint plugin
.idea/sonarlint

### Python ###
# Byte-compiled / optimized / DLL files
__pycache__/
*.py[cod]
*$py.class

# C extensions
*.so

# Distribution / packaging
.Python
build/
develop-eggs/
dist/
downloads/
eggs/
.eggs/
lib/
lib64/
parts/
sdist/
var/
wheels/
pip-wheel-metadata/
share/python-wheels/
*.egg-info/
.installed.cfg
*.egg
*.egg-info
MANIFEST

# PyInstaller
# Usually these files are written by a python script from a template
# before PyInstaller builds the exe, so as to inject date/other infos into it.
*.manifest
*.spec

# Installer logs
pip-log.txt
pip-delete-this-directory.txt

# Unit test / coverage reports
htmlcov/
.tox/
.nox/
.venv/
.coverage
/build/
.coverage.*
.cache
nosetests.xml
coverage.xml
*.cover
.hypothesis/
.pytest_cache/

# Translations
*.mo
*.pot

# Scrapy stuff:
.scrapy

# Sphinx documentation
docs/_build/

# PyBuilder
target/

# pyenv
.python-version

# pipenv
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
# However, in case of collaboration, if having platform-specific dependencies or dependencies
# having no cross-platform support, pipenv may install dependencies that don't work, or not
# install all needed dependencies.
#Pipfile.lock

# celery beat schedule file
celerybeat-schedule

# SageMath parsed files
*.sage.py

# Spyder project settings
.spyderproject
.spyproject

# Rope project settings
.ropeproject

# Mr Developer
.mr.developer.cfg
.project
.pydevproject

# mkdocs documentation
/site

# mypy
.mypy_cache/
.dmypy.json
dmypy.json

# Pyre type checker
.pyre/

### VisualStudioCode ###
.vscode

### VisualStudioCode Patch ###
# Ignore all local history of files
.history

/dist/
# End of https://www.gitignore.io/api/python,intellij+all,visualstudiocode
32 changes: 13 additions & 19 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
language: python
sudo: false
matrix:
include:
- python: pypy
env: TOX_ENV=pypy
- python: '2.7'
env: TOX_ENV=py27
- python: '3.4'
env: TOX_ENV=py34
- python: '3.5'
env: TOX_ENV=py35
- python: '3.6'
env: TOX_ENV=py36,import-order,flake8
cache:
directories:
- $HOME/.cache/pip
- $TRAVIS_BUILD_DIR/.tox
python:
- 3.6
- 3.7
- 3.8
cache: pip

install:
- pip install tox coveralls
- pip install tox-travis

script:
- tox -e $TOX_ENV -- --cov=flask_graphql
- tox

after_success:
- coveralls
- pip install coveralls
- coveralls

deploy:
provider: pypi
user: syrusakbary
11 changes: 9 additions & 2 deletions MANIFEST.in
Original file line number Diff line number Diff line change
@@ -1,3 +1,10 @@
include LICENSE
include README.md
recursive-include flask_graphql/static *
recursive-include flask_graphql/templates *

include tox.ini
include Makefile

recursive-include flask_graphql *.py
recursive-include tests *.py

global-exclude *.py[co] __pycache__
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
65 changes: 56 additions & 9 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,34 +1,78 @@
# Flask-GraphQL

[![Build Status](https://travis-ci.org/graphql-python/flask-graphql.svg?branch=master)](https://travis-ci.org/graphql-python/flask-graphql) [![Coverage Status](https://coveralls.io/repos/graphql-python/flask-graphql/badge.svg?branch=master&service=github)](https://coveralls.io/github/graphql-python/flask-graphql?branch=master) [![PyPI version](https://badge.fury.io/py/flask-graphql.svg)](https://badge.fury.io/py/flask-graphql)

Adds GraphQL support to your Flask application.

[![travis][travis-image]][travis-url]
[![pypi][pypi-image]][pypi-url]
[![Anaconda-Server Badge][conda-image]][conda-url]
[![coveralls][coveralls-image]][coveralls-url]

[travis-image]: https://travis-ci.org/graphql-python/flask-graphql.svg?branch=master
[travis-url]: https://travis-ci.org/graphql-python/flask-graphql
[pypi-image]: https://img.shields.io/pypi/v/flask-graphql.svg?style=flat
[pypi-url]: https://pypi.org/project/flask-graphql/
[coveralls-image]: https://coveralls.io/repos/graphql-python/flask-graphql/badge.svg?branch=master&service=github
[coveralls-url]: https://coveralls.io/github/graphql-python/flask-graphql?branch=master
[conda-image]: https://img.shields.io/conda/vn/conda-forge/flask-graphql.svg
[conda-url]: https://anaconda.org/conda-forge/flask-graphql

## Usage

Just use the `GraphQLView` view from `flask_graphql`

```python
from flask import Flask
from flask_graphql import GraphQLView

app.add_url_rule('/graphql', view_func=GraphQLView.as_view('graphql', schema=schema, graphiql=True))
from schema import schema

app = Flask(__name__)

app.add_url_rule('/graphql', view_func=GraphQLView.as_view(
'graphql',
schema=schema,
graphiql=True,
))

# Optional, for adding batch query support (used in Apollo-Client)
app.add_url_rule('/graphql/batch', view_func=GraphQLView.as_view('graphql', schema=schema, batch=True))
app.add_url_rule('/graphql/batch', view_func=GraphQLView.as_view(
'graphql',
schema=schema,
batch=True
))

if __name__ == '__main__':
app.run()
```

This will add `/graphql` and `/graphiql` endpoints to your app.
This will add `/graphql` endpoint to your app and enable the GraphiQL IDE.

### Special Note for Graphene v3

If you are using the `Schema` type of [Graphene](https://github.com/graphql-python/graphene) library, be sure to use the `graphql_schema` attribute to pass as schema on the `GraphQLView` view. Otherwise, the `GraphQLSchema` from `graphql-core` is the way to go.

More info at [Graphene v3 release notes](https://github.com/graphql-python/graphene/wiki/v3-release-notes#graphene-schema-no-longer-subclasses-graphqlschema-type) and [GraphQL-core 3 usage](https://github.com/graphql-python/graphql-core#usage).


### Supported options for GraphQLView

### Supported options
* `schema`: The `GraphQLSchema` object that you want the view to execute when it gets a valid request.
* `context`: A value to pass as the `context` to the `graphql()` function.
* `root_value`: The `root_value` you want to provide to `executor.execute`.
* `context`: A value to pass as the `context_value` to graphql `execute` function. By default is set to `dict` with request object at key `request`.
* `root_value`: The `root_value` you want to provide to graphql `execute`.
* `pretty`: Whether or not you want the response to be pretty printed JSON.
* `executor`: The `Executor` that you want to use to execute queries.
* `graphiql`: If `True`, may present [GraphiQL](https://github.com/graphql/graphiql) when loaded directly from a browser (a useful tool for debugging and exploration).
* `graphiql_version`: The graphiql version to load. Defaults to **"1.0.3"**.
* `graphiql_template`: Inject a Jinja template string to customize GraphiQL.
* `graphiql_html_title`: The graphiql title to display. Defaults to **"GraphiQL"**.
* `batch`: Set the GraphQL view as batch (for using in [Apollo-Client](http://dev.apollodata.com/core/network.html#query-batching) or [ReactRelayNetworkLayer](https://github.com/nodkz/react-relay-network-layer))
* `middleware`: A list of graphql [middlewares](http://docs.graphene-python.org/en/latest/execution/middleware/).
* `encode`: the encoder to use for responses (sensibly defaults to `graphql_server.json_encode`).
* `format_error`: the error formatter to use for responses (sensibly defaults to `graphql_server.default_format_error`.
* `subscriptions`: The GraphiQL socket endpoint for using subscriptions in graphql-ws.
* `headers`: An optional GraphQL string to use as the initial displayed request headers, if not provided, the stored headers will be used.
* `default_query`: An optional GraphQL string to use when no query is provided and no stored query exists from a previous session. If not provided, GraphiQL will use its own default query.
* `header_editor_enabled`: An optional boolean which enables the header editor when true. Defaults to **false**.
* `should_persist_headers`: An optional boolean which enables to persist headers to storage when true. Defaults to **false**.

You can also subclass `GraphQLView` and overwrite `get_root_value(self, request)` to have a dynamic root value
per request.
@@ -39,3 +83,6 @@ class UserRootValue(GraphQLView):
return request.user

```

## Contributing
Since v3, `flask-graphql` code lives at [graphql-server](https://github.com/graphql-python/graphql-server) repository to keep any breaking change on the base package on sync with all other integrations. In order to contribute, please take a look at [CONTRIBUTING.md](https://github.com/graphql-python/graphql-server/blob/master/CONTRIBUTING.md).
Loading