aiohttp-graphql
Adds GraphQL support to your aiohttp application.
Based on flask-graphql by Syrus Akbary and sanic-graphql by Sergey Porivaev.
Usage
Just use the GraphQLView view from aiohttp_graphql
from aiohttp_graphql import GraphQLView
GraphQLView.attach(app, schema=Schema, graphiql=True)
# Optional, for adding batch query support (used in Apollo-Client)
GraphQLView.attach(app, schema=Schema, batch=True)
This will add a /graphql endpoint to your app (customizable by passing route_path='/mypath' to GraphQLView.attach).
Note: GraphQLView.attach is just a convenience function, and the same functionality can be achieved with
gql_view = GraphQLView(schema=Schema, **kwargs)
app.router.add_route('*', gql_view, name='graphql')
It's worth noting that the the "view function" of GraphQLView is contained in GraphQLView.__call__. So, when you create an instance, that instance is callable with the request object as the sole positional argument. To illustrate:
gql_view = GraphQLView(schema=Schema, **kwargs)
gql_view(request) # <-- the instance is callable and expects a `aiohttp.web.Request` object.
Supported options
schema: TheGraphQLSchemaobject that you want the view to execute when it gets a valid request.executor: TheExecutorthat you want to use to execute queries. If anAsyncioExecutorinstance is provided, performs queries asynchronously within executor’s loop.root_value: Theroot_valueyou want to provide toexecutor.execute.context: A value to pass as thecontextto thegraphql()function. By default is set todictwith request object at keyrequest.pretty: Whether or not you want the response to be pretty printed JSON.graphiql: IfTrue, may present GraphiQL when loaded directly from a browser (a useful tool for debugging and exploration).graphiql_version: The version of the providedgraphiqlpackage.graphiql_template: Inject a Jinja template string to customize GraphiQL.middleware: Custom middleware for graphql-python.batch: Set the GraphQL view as batch (for using in Apollo-Client or [ReactRelayNetworkLayer])jinja_env: Sets jinja environment to be used to process GraphiQL template. If Jinja’s async mode is enabled (byenable_async=True), usesTemplate.render_asyncinstead ofTemplate.render. If environment is not set, fallbacks to simple regex-based renderer.max_age: sets the response headerAccess-Control-Max-Agefor preflight requestsencoder: the encoder to use for responses (sensibly defaults tographql_server.json_encode)error_formatter: the error formatter to use for responses (sensibly defaults tographql_server.default_format_error)enable_async: whetherasyncmode will be enabled.subscriptions: The GraphiQL socket endpoint for using subscriptions in graphql-ws.
Testing
Testing is done with pytest.
git clone https://github.com/graphql-python/aiohttp-graphql
cd aiohttp-graphql
# Create a virtualenv
python3.6 -m venv env && source env/bin/activate # for example
pip install -e .[test]
pytest
The tests, while modeled after sanic-graphql's tests, have been entirely refactored to take advantage of pytest-asyncio, conform with PEP-8, and increase readability with pytest fixtures. For usage tests, please check them out.
License
Copyright for portions of project aiohttp-graphql are held by Syrus Akbary as part of project flask-graphql and sanic-graphql as part of project Sergey Porivaev. All other claims to this project aiohttp-graphql are held by Devin Fee.
This project is licensed under the MIT License.
Metadata
Release files for aiohttp-graphql 1.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| aiohttp-graphql-1.1.0.tar.gz | 19.2 kB | Without provenance | Details for aiohttp-graphql-1.1.0.tar.gz |
Release files / aiohttp-graphql-1.1.0.tar.gz
| Download URL | aiohttp-graphql-1.1.0.tar.gz |
|---|---|
| Size | 19.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
29035589ca0929f5dc19b09461db0a2563db0166a6efcf22e23498a44e45040e
|
|
BLAKE2b-256 checksum How to use checksums |
fce7953018ff0af70c515efff12175240ca1d4f9a47d2681eeba656a37e3db02
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.38.0 CPython/3.8.2
|
Security for aiohttp-graphql 1.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.