Skip to content

Commit e045b57

Browse files
committed
chore: use graphql-server to re-export webob
1 parent 5f7ccc2 commit e045b57

23 files changed

+1020
-1301
lines changed

.gitignore

+201-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +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-
*.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/
7136
.coverage
8-
/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
9203

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

.travis.yml

+13-17
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,21 @@
11
language: python
22
sudo: false
3-
matrix:
4-
include:
5-
- python: pypy
6-
env: TOX_ENV=pypy
7-
- python: '2.7'
8-
env: TOX_ENV=py27
9-
- python: '3.5'
10-
env: TOX_ENV=py35
11-
- python: '3.6'
12-
env: TOX_ENV=py36,import-order,flake8
13-
cache:
14-
directories:
15-
- $HOME/.cache/pip
16-
- $TRAVIS_BUILD_DIR/.tox
3+
python:
4+
- 3.6
5+
- 3.7
6+
- 3.8
7+
cache: pip
8+
179
install:
18-
- pip install tox coveralls
10+
- pip install tox-travis
11+
1912
script:
20-
- tox -e $TOX_ENV -- --cov=webob_graphql
13+
- tox
14+
2115
after_success:
22-
- coveralls
16+
- pip install coveralls
17+
- coveralls
18+
2319
deploy:
2420
provider: pypi
2521
user: syrusakbary

MANIFEST.in

+9-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
1+
include LICENSE
12
include README.md
2-
recursive-include webob_graphql/static *
3-
recursive-include webob_graphql/templates *
3+
4+
include tox.ini
5+
include Makefile
6+
7+
recursive-include webob_graphql *.py
8+
recursive-include tests *.py
9+
10+
global-exclude *.py[co] __pycache__

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=webob_graphql -vv

README.md

+34-30
Original file line numberDiff line numberDiff line change
@@ -4,49 +4,53 @@
44

55
Adds GraphQL support to your WebOb (Pyramid, Pylons, ...) application.
66

7-
## Installation
8-
9-
For instaling WebOb-GraphQL, just run this command in your shell
10-
11-
```bash
12-
pip install "webob-graphql>=1.0.dev"
13-
```
14-
15-
167
## Usage
178

18-
Just use the `serve_graphql_request` function from `webob_graphql`
19-
9+
Use the `GraphQLView` view from `webob_graphql`
2010

2111
### Pyramid
2212

2313
```python
14+
from wsgiref.simple_server import make_server
2415
from pyramid.view import view_config
2516

2617
from webob_graphql import serve_graphql_request
2718

19+
from schema import schema
2820

29-
@view_config(
30-
route_name='graphql',
31-
# The serve_graphql_request method will detect what's the best renderer
32-
# to use, so it will do the json render automatically.
33-
# In summary, don't use the renderer='json' here :)
34-
)
3521
def graphql_view(request):
36-
context = {'session': request.session}
37-
return serve_graphql_request(request, schema, context_value=context)
38-
39-
# Optional, for adding batch query support (used in Apollo-Client)
40-
return serve_graphql_request(request, schema, batch_enabled=True, context_value=context)
22+
return GraphQLView(request=request, schema=schema, graphiql=True).dispatch_request(request)
23+
24+
if __name__ == '__main__':
25+
with Configurator() as config:
26+
config.add_route('graphql', '/graphql')
27+
config.add_view(graphql_view, route_name='graphql')
28+
app = config.make_wsgi_app()
29+
server = make_server('0.0.0.0', 6543, app)
30+
server.serve_forever()
4131
```
32+
This will add `/graphql` endpoint to your app and enable the GraphiQL IDE.
33+
34+
### Supported options for GraphQLView
4235

43-
### Supported options
4436
* `schema`: The `GraphQLSchema` object that you want the view to execute when it gets a valid request.
45-
* `context_value`: A value to pass as the `context` to the `graphql()` function.
46-
* `root_value`: The `root_value` you want to provide to `executor.execute`.
47-
* `format_error`: If you want to use a custom error formatter.
37+
* `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`.
38+
* `root_value`: The `root_value` you want to provide to graphql `execute`.
4839
* `pretty`: Whether or not you want the response to be pretty printed JSON.
49-
* `executor`: The `Executor` that you want to use to execute queries.
50-
* `graphiql_enabled`: If `True` (default), may present [GraphiQL](https://github.com/graphql/graphiql) when loaded directly from a browser (a useful tool for debugging and exploration).
51-
* `render_graphiql`: A custom function for rendering GraphiQL (this function should have the arguments `result` and `params`).
52-
* `batch_enabled`: Enable batch support (for using in [Apollo-Client](http://dev.apollodata.com/core/network.html#query-batching) or [ReactRelayNetworkLayer](https://github.com/nodkz/react-relay-network-layer))
40+
* `graphiql`: If `True`, may present [GraphiQL](https://github.com/graphql/graphiql) when loaded directly from a browser (a useful tool for debugging and exploration).
41+
* `graphiql_version`: The graphiql version to load. Defaults to **"1.0.3"**.
42+
* `graphiql_template`: Inject a Jinja template string to customize GraphiQL.
43+
* `graphiql_html_title`: The graphiql title to display. Defaults to **"GraphiQL"**.
44+
* `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))
45+
* `middleware`: A list of graphql [middlewares](http://docs.graphene-python.org/en/latest/execution/middleware/).
46+
* `encode`: the encoder to use for responses (sensibly defaults to `graphql_server.json_encode`).
47+
* `format_error`: the error formatter to use for responses (sensibly defaults to `graphql_server.default_format_error`.
48+
* `enable_async`: whether `async` mode will be enabled.
49+
* `subscriptions`: The GraphiQL socket endpoint for using subscriptions in graphql-ws.
50+
* `headers`: An optional GraphQL string to use as the initial displayed request headers, if not provided, the stored headers will be used.
51+
* `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.
52+
* `header_editor_enabled`: An optional boolean which enables the header editor when true. Defaults to **false**.
53+
* `should_persist_headers`: An optional boolean which enables to persist headers to storage when true. Defaults to **false**.
54+
55+
## Contributing
56+
Since v3, `webob-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).

0 commit comments

Comments
 (0)