Tartiflette Middleware
Framework to facilitate the creation of middleware for Tartiflette with resolver context variable assignment using python context managers.
Allows for processing of request/response headers, dependent on the http server you're using.
Installation
pip install tartiflette-middleware
Usage
This requires:
- Creation of your middleware.
- Configuration of your middleware in your application.
- Update your resolvers to access your data.
1 - Creation of your middleware
Create a context manager to run on each request.
Example:
from tartiflette_middleware import BaseMiddleware
class MyMiddleware(BaseMiddleware):
# required short arbitrary unique middleware label
label = 'MyMware'
def __init__(self, my_middleware_params):
BaseMiddleware.__init__(self)
# do things necessary for repeated use across all of the requests, e.g.
# configure factories
async def __aenter__(self):
# provide the data or method to be used in all queries for a single
# request.
your_method_or_data = ...
# store the data/method to be reused for this request
await self.store_request_data(your_method_or_data)
async def __aexit__(self, exc_type, exc_val, exc_tb):
# optional: for if you need to do something when the request is
# completed
data = await self.get_request_data()
data.close_or_whatever()
There are more examples in the examples directory including one with access to AIOHTTP request headers.
You can set the response http status using something like:
async def __aenter__(self):
self.status = 401
2 - Configuration of your middleware in your app
Currently only AIOHTTP is supported but the library is extensible if others would like to submit a pull request to support other servers that Tartiflette supports.
Limited AIOHTTP setup example, imports and configuration kept to middleware specific details:
from tartiflette_middleware import Middleware, server
import MyMiddleware # your Middleware as defined earlier
my_middleware = Middleware(
context_manager=MyMiddleware(
my_middleware_params={},
),
server_middleware=server.aiohttp
)
app = web.Application(middlewares=[
my_middleware.middleware
])
ctx = {
'my_session_service': my_middleware.service,
}
web.run_app(
register_graphql_handlers(
# your configuration
executor_context=ctx,
)
)
3 - Access data in your resolvers' context
Works in queries, mutations, and subscriptions.
@Resolver('Query.whatever')
async def resolve_query_user_login(parent, args, ctx, info):
my_data = await ctx['my_session_service']()
Metadata
Release files for tartiflette-middleware 1.1
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 |
|---|---|---|---|---|
| tartiflette-middleware-1.1.tar.gz | 4.8 kB | Without provenance | Details for tartiflette-middleware-1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| tartiflette_middleware-1.1-py3-none-any.whl | Python 3 | none | any | Details for tartiflette_middleware-1.1-py3-none-any.whl |
Total release size: 10.9 kB
Release files / tartiflette-middleware-1.1.tar.gz
| Download URL | tartiflette-middleware-1.1.tar.gz |
|---|---|
| Size | 4.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3fdd8278c4309023b6f0e0b34312a126eac22f81548e6757cf3c6f39337b52db
|
|
BLAKE2b-256 checksum How to use checksums |
0098e3669679f088b4f578aeb2db585bb8b94e24c59f947bafd0abeabcaf3bc2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.2
|
Release files / tartiflette_middleware-1.1-py3-none-any.whl
| Download URL | tartiflette_middleware-1.1-py3-none-any.whl |
|---|---|
| Size | 6.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
aa4f1ce5e8e01a386bd2f1f204d7c3ba9aa3f4df1e91364cf021c9b4495d315b
|
|
BLAKE2b-256 checksum How to use checksums |
f176b808251f2aa9a52fcc3b9d0724b8291561c7cc7c2d2fc2e98eecb20491b6
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.15.0 pkginfo/1.5.0.1 requests/2.21.0 setuptools/49.2.1 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.5.2
|
Security for tartiflette-middleware 1.1
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.