Skip to content

Commit e1e3093

Browse files
committed
chore: use graphql-server to re-export sanic
1 parent 89202be commit e1e3093

16 files changed

+750
-951
lines changed

Diff for: .gitignore

+201-8
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,204 @@
1-
*.pyc
2-
.idea
3-
.cache
4-
.tox
1+
2+
# Created by https://www.gitignore.io/api/python,intellij+all,visualstudiocode
3+
# Edit at https://www.gitignore.io/?templates=python,intellij+all,visualstudiocode
4+
5+
### Intellij+all ###
6+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio and WebStorm
7+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
8+
9+
# User-specific stuff
10+
.idea/**/workspace.xml
11+
.idea/**/tasks.xml
12+
.idea/**/usage.statistics.xml
13+
.idea/**/dictionaries
14+
.idea/**/shelf
15+
16+
# Generated files
17+
.idea/**/contentModel.xml
18+
19+
# Sensitive or high-churn files
20+
.idea/**/dataSources/
21+
.idea/**/dataSources.ids
22+
.idea/**/dataSources.local.xml
23+
.idea/**/sqlDataSources.xml
24+
.idea/**/dynamic.xml
25+
.idea/**/uiDesigner.xml
26+
.idea/**/dbnavigator.xml
27+
28+
# Gradle
29+
.idea/**/gradle.xml
30+
.idea/**/libraries
31+
32+
# Gradle and Maven with auto-import
33+
# When using Gradle or Maven with auto-import, you should exclude module files,
34+
# since they will be recreated, and may cause churn. Uncomment if using
35+
# auto-import.
36+
# .idea/modules.xml
37+
# .idea/*.iml
38+
# .idea/modules
39+
# *.iml
40+
# *.ipr
41+
42+
# CMake
43+
cmake-build-*/
44+
45+
# Mongo Explorer plugin
46+
.idea/**/mongoSettings.xml
47+
48+
# File-based project format
49+
*.iws
50+
51+
# IntelliJ
52+
out/
53+
54+
# mpeltonen/sbt-idea plugin
55+
.idea_modules/
56+
57+
# JIRA plugin
58+
atlassian-ide-plugin.xml
59+
60+
# Cursive Clojure plugin
61+
.idea/replstate.xml
62+
63+
# Crashlytics plugin (for Android Studio and IntelliJ)
64+
com_crashlytics_export_strings.xml
65+
crashlytics.properties
66+
crashlytics-build.properties
67+
fabric.properties
68+
69+
# Editor-based Rest Client
70+
.idea/httpRequests
71+
72+
# Android studio 3.1+ serialized cache file
73+
.idea/caches/build_file_checksums.ser
74+
75+
### Intellij+all Patch ###
76+
# Ignores the whole .idea folder and all .iml files
77+
# See https://github.com/joeblau/gitignore.io/issues/186 and https://github.com/joeblau/gitignore.io/issues/360
78+
79+
.idea/
80+
81+
# Reason: https://github.com/joeblau/gitignore.io/issues/186#issuecomment-249601023
82+
83+
*.iml
84+
modules.xml
85+
.idea/misc.xml
86+
*.ipr
87+
88+
# Sonarlint plugin
89+
.idea/sonarlint
90+
91+
### Python ###
92+
# Byte-compiled / optimized / DLL files
93+
__pycache__/
94+
*.py[cod]
95+
*$py.class
96+
97+
# C extensions
98+
*.so
99+
100+
# Distribution / packaging
101+
.Python
102+
build/
103+
develop-eggs/
104+
dist/
105+
downloads/
106+
eggs/
107+
.eggs/
108+
lib/
109+
lib64/
110+
parts/
111+
sdist/
112+
var/
113+
wheels/
114+
pip-wheel-metadata/
115+
share/python-wheels/
116+
*.egg-info/
117+
.installed.cfg
5118
*.egg
6-
*.eggs
7-
*.egg-info
119+
MANIFEST
120+
121+
# PyInstaller
122+
# Usually these files are written by a python script from a template
123+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
124+
*.manifest
125+
*.spec
126+
127+
# Installer logs
128+
pip-log.txt
129+
pip-delete-this-directory.txt
130+
131+
# Unit test / coverage reports
132+
htmlcov/
133+
.tox/
134+
.nox/
135+
.venv/
8136
.coverage
9-
/build/
137+
.coverage.*
138+
.cache
139+
nosetests.xml
140+
coverage.xml
141+
*.cover
142+
.hypothesis/
143+
.pytest_cache/
144+
145+
# Translations
146+
*.mo
147+
*.pot
148+
149+
# Scrapy stuff:
150+
.scrapy
151+
152+
# Sphinx documentation
153+
docs/_build/
154+
155+
# PyBuilder
156+
target/
157+
158+
# pyenv
159+
.python-version
160+
161+
# pipenv
162+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
163+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
164+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
165+
# install all needed dependencies.
166+
#Pipfile.lock
167+
168+
# celery beat schedule file
169+
celerybeat-schedule
170+
171+
# SageMath parsed files
172+
*.sage.py
173+
174+
# Spyder project settings
175+
.spyderproject
176+
.spyproject
177+
178+
# Rope project settings
179+
.ropeproject
180+
181+
# Mr Developer
182+
.mr.developer.cfg
183+
.project
184+
.pydevproject
185+
186+
# mkdocs documentation
187+
/site
188+
189+
# mypy
190+
.mypy_cache/
191+
.dmypy.json
192+
dmypy.json
193+
194+
# Pyre type checker
195+
.pyre/
196+
197+
### VisualStudioCode ###
198+
.vscode
199+
200+
### VisualStudioCode Patch ###
201+
# Ignore all local history of files
202+
.history
10203

11-
/dist/
204+
# End of https://www.gitignore.io/api/python,intellij+all,visualstudiocode

Diff for: .travis.yml

+5-13
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,17 @@
11
language: python
2-
2+
sudo: false
33
python:
44
- 3.6
55
- 3.7
66
- 3.8
7-
8-
matrix:
9-
include:
10-
- python: '3.7'
11-
env: TOXENV=flake8
12-
13-
cache:
14-
directories:
15-
- $HOME/.cache/pip
16-
- $TRAVIS_BUILD_DIR/.tox
7+
cache: pip
178

189
install:
19-
- pip install tox tox-travis coveralls
10+
- pip install tox-travis
2011

2112
script:
2213
- tox
2314

2415
after_success:
25-
- coveralls
16+
- pip install coveralls
17+
- coveralls

Diff for: MANIFEST.in

+8
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,10 @@
1+
include LICENSE
12
include README.md
23

4+
include tox.ini
5+
include Makefile
6+
7+
recursive-include sanic_graphql *.py
8+
recursive-include tests *.py
9+
10+
global-exclude *.py[co] __pycache__

Diff for: Makefile

+5
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+
py.test tests --cov=sanic_graphql -vv

Diff for: README.md

+45-26
Original file line numberDiff line numberDiff line change
@@ -12,41 +12,57 @@ Based on [flask-graphql] by [Syrus Akbary].
1212
Usage
1313
-----
1414

15-
Just use the `GraphQLView` view from `sanic_graphql`
15+
Use the `GraphQLView` view from`sanic_graphql`
1616

1717
```python
1818
from sanic_graphql import GraphQLView
19+
from sanic import Sanic
1920

20-
app.add_route(GraphQLView.as_view(schema=Schema, graphiql=True), '/graphql')
21+
from schema import schema
2122

22-
# Optional, for adding batch query support (used in Apollo-Client)
23-
app.add_route(GraphQLView.as_view(schema=Schema, batch=True), '/graphql/batch')
24-
```
25-
26-
This will add `/graphql` endpoint to your app.
23+
app = Sanic(name="Sanic Graphql App")
2724

28-
### Sharing eventloop with Sanic
25+
app.add_route(
26+
GraphQLView.as_view(schema=schema, graphiql=True),
27+
'/graphql'
28+
)
2929

30-
In order to pass Sanic’s eventloop to GraphQL’s `AsyncioExecutor`, use `before_start` listener:
30+
# Optional, for adding batch query support (used in Apollo-Client)
31+
app.add_route(
32+
GraphQLView.as_view(schema=schema, batch=True),
33+
'/graphql/batch'
34+
)
3135

32-
```python
33-
@app.listener('before_server_start')
34-
def init_graphql(app, loop):
35-
app.add_route(GraphQLView.as_view(schema=Schema, executor=AsyncioExecutor(loop=loop)), '/graphql')
36+
if __name__ == '__main__':
37+
app.run(host='0.0.0.0', port=8000)
3638
```
3739

38-
### Supported options
40+
This will add `/graphql` endpoint to your app and enable the GraphiQL IDE.
41+
42+
### Supported options for GraphQLView
3943

40-
- `schema`: The `GraphQLSchema` object that you want the view to execute when it gets a valid request.
41-
- `context`: A value to pass as the `context` to the `graphql()` function. By default is set to `dict` with request object at key `request`.
42-
- `root_value`: The `root_value` you want to provide to `executor.execute`.
43-
- `pretty`: Whether or not you want the response to be pretty printed JSON.
44-
- `executor`: The `Executor` that you want to use to execute queries. If an `AsyncioExecutor` instance is provided, performs queries asynchronously within executor’s loop.
45-
- `graphiql`: If `True`, may present [GraphiQL] when loaded directly from a browser (a useful tool for debugging and exploration).
46-
- `graphiql_template`: Inject a Jinja template string to customize GraphiQL.
47-
- `jinja_env`: Sets jinja environment to be used to process GraphiQL template. If Jinja’s async mode is enabled (by `enable_async=True`), uses
44+
* `schema`: The `GraphQLSchema` object that you want the view to execute when it gets a valid request.
45+
* `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`.
46+
* `root_value`: The `root_value` you want to provide to graphql `execute`.
47+
* `pretty`: Whether or not you want the response to be pretty printed JSON.
48+
* `graphiql`: If `True`, may present [GraphiQL](https://github.com/graphql/graphiql) when loaded directly from a browser (a useful tool for debugging and exploration).
49+
* `graphiql_version`: The graphiql version to load. Defaults to **"1.0.3"**.
50+
* `graphiql_template`: Inject a Jinja template string to customize GraphiQL.
51+
* `graphiql_html_title`: The graphiql title to display. Defaults to **"GraphiQL"**.
52+
* `jinja_env`: Sets jinja environment to be used to process GraphiQL template. If Jinja’s async mode is enabled (by `enable_async=True`), uses
4853
`Template.render_async` instead of `Template.render`. If environment is not set, fallbacks to simple regex-based renderer.
49-
- `batch`: Set the GraphQL view as batch (for using in [Apollo-Client] or [ReactRelayNetworkLayer])
54+
* `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))
55+
* `middleware`: A list of graphql [middlewares](http://docs.graphene-python.org/en/latest/execution/middleware/).
56+
* `max_age`: Sets the response header Access-Control-Max-Age for preflight requests.
57+
* `encode`: the encoder to use for responses (sensibly defaults to `graphql_server.json_encode`).
58+
* `format_error`: the error formatter to use for responses (sensibly defaults to `graphql_server.default_format_error`.
59+
* `enable_async`: whether `async` mode will be enabled.
60+
* `subscriptions`: The GraphiQL socket endpoint for using subscriptions in graphql-ws.
61+
* `headers`: An optional GraphQL string to use as the initial displayed request headers, if not provided, the stored headers will be used.
62+
* `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.
63+
* `header_editor_enabled`: An optional boolean which enables the header editor when true. Defaults to **false**.
64+
* `should_persist_headers`: An optional boolean which enables to persist headers to storage when true. Defaults to **false**.
65+
5066

5167
You can also subclass `GraphQLView` and overwrite `get_root_value(self, request)` to have a dynamic root value per request.
5268

@@ -56,8 +72,12 @@ class UserRootValue(GraphQLView):
5672
return request.user
5773
```
5874

59-
License
60-
-------
75+
76+
## Contributing
77+
Since v3, `sanic-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).
78+
79+
80+
## License
6181

6282
Copyright for portions of project [sanic-graphql] are held by [Syrus Akbary] as part of project [flask-graphql]. All other copyright
6383
for project [sanic-graphql] are held by [Sergey Porivaev].
@@ -73,4 +93,3 @@ This project is licensed under MIT License.
7393
[ReactRelayNetworkLayer]: https://github.com/nodkz/react-relay-network-layer
7494
[Sergey Porivaev]: https://github.com/grazor
7595
[sanic-graphql]: https://github.com/grazor/sanic-graphql
76-

0 commit comments

Comments
 (0)