Adds GraphQL support to your Sanic application
Project description
Sanic-GraphQL
Adds GraphQL support to your Sanic application.
Based on flask-graphql by Syrus Akbary.
Usage
Just use the GraphQLView view from sanic_graphql
from sanic_graphql import GraphQLView
app.add_route(GraphQLView.as_view(schema=Schema, graphiql=True), '/graphql')
# Optional, for adding batch query support (used in Apollo-Client)
app.add_route(GraphQLView.as_view(schema=Schema, batch=True), '/graphql/batch')
This will add /graphql endpoint to your app.
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. By default is set to dict with request object at key request.
root_value: The root_value you want to provide to executor.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. If an AsyncioExecutor instance is provided, performs queries asynchronously within executor’s loop.
graphiql: If True, may present GraphiQL when loaded directly from a browser (a useful tool for debugging and exploration).
graphiql_template: Inject a Jinja template string to customize GraphiQL.
jinja_env: Sets jinja environment to be used to process GraphiQL template. If Jinja’s async mode is enabled (by enable_async=True), uses Template.render_async instead of Template.render. If environment is not set, fallbacks to simple regex-based renderer.
batch: Set the GraphQL view as batch (for using in Apollo-Client or ReactRelayNetworkLayer)
You can also subclass GraphQLView and overwrite get_root_value(self, request) to have a dynamic root value per request.
class UserRootValue(GraphQLView):
def get_root_value(self, request):
return request.user
License
Copyright for portions of project sanic-graphql are held by Syrus Akbary as part of project flask-graphql. All other copyright for project sanic-graphql are held by Sergey Porivaev.
This project is licensed under MIT License.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file Sanic-GraphQL-1.2.0.tar.gz
.
File metadata
- Download URL: Sanic-GraphQL-1.2.0.tar.gz
- Upload date:
- Size: 7.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 08bb4ee95bc8ac12dbd351294a5c1b4f401b192a9f338c1b61840220f73fb7e6 |
|
MD5 | cb0ee5176665e7edcbab1d141cad8d20 |
|
BLAKE2b-256 | f2e9f04e17c0cecbe52349a9a6582e5749233bb71392354b3c4e1a64024f8445 |
File details
Details for the file Sanic_GraphQL-1.2.0-py3-none-any.whl
.
File metadata
- Download URL: Sanic_GraphQL-1.2.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/46.0.0 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.5
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8b6a5dc281ef47631563289c5f88585203b32419907ae03abdedac9246b8c028 |
|
MD5 | 7475e810a4f2a6ad62777b2728669c0a |
|
BLAKE2b-256 | 15bcda1ac4b94bd4c723210ad1602afdd5bc98e313d786638f74447ef8926eae |