Collection of utilities, middleware, decorators for graphql-core>=3.0
Project description
graphql-utilities
Collection of utils, middleware, decorators for graphql-core>=3.0 (formerly known as graphql-core-next)
What's included?
- depth analysis:
graphql-utilities
provides a configurable customExecutionContext
that can be configured to perform depth analysis. @run_only_once
decorator for middleware: each field resolver involves running all middleware. For middleware of certain purpose like authenticating users shouldn't run multiple times.
Installation
pip install graphql-utilities
Alternatively, if you use pipenv:
pipenv install graphql-utilities
Examples
Operation-level middleware (One-shot middleware)
from graphql_utilities.decorators import run_only_once
class AuthMiddleware:
@run_only_once
def resolve(self, next_, root, info, *args, **kwargs):
# middleware logic
return next_(root, info, *args, **kwargs)
Limiting Query Depth
# import your schema
from graphql import execute, parse # Requires `graphql-core>=3.0`
from graphql_utilities.execution import ExtendedExecutionContext
query = '{ field_1_str field_2_int field_3_obj { field_3_obj_sub_1 { xxx } } }'
execute(schema=schema, document=parse(query),
context_value={"depth_analysis": {
"max_depth": 2 # Maximum depth allowed
}},
execution_context_class=ExtendedExecutionContext # Use the `ExtendedExecutionContext` provided in `graphql-utilities`
)
What's next?
Here is a list of items I am working on: (or will work on):
- Query cost analysis
Motivation
In recent projects, I ran into some problems with graphene
and graphql-core
including missing operation-level middleware (See issue here), etc.
graphql-utilities
is a compilation of utilities and custom execution context for depth analysis, etc targeting graphql-core>=3.0
.
Contributing
Any form of contribution, feature requests, bug reports, pull requests are largely welcome.
Licenses
MIT Licensed. GraphQL logo is licensed under Facebook BSD.
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 graphql-utilities-0.3.0.tar.gz
.
File metadata
- Download URL: graphql-utilities-0.3.0.tar.gz
- Upload date:
- Size: 5.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | ef7270c8d3bf2704c89eafaced69280dccbd76b74680bc7016bf8668c62869ad |
|
MD5 | eb6183335003a9ca7af3d21269061266 |
|
BLAKE2b-256 | 6012e1de8005a4f0e309d7ab392a1b969f401de7fb6c93fa4c7e3e0ea93f659d |
File details
Details for the file graphql_utilities-0.3.0-py3-none-any.whl
.
File metadata
- Download URL: graphql_utilities-0.3.0-py3-none-any.whl
- Upload date:
- Size: 8.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.7.6
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e0dfe955d41a6311dd09c80d06678e72a01dfb668c0a0adc6ee7dc7394963fb0 |
|
MD5 | 44b3aba55694782d0be247bf217a48ea |
|
BLAKE2b-256 | 118e3f46fa31a22e65db67be66a9de56f66aeacc8725eed4402b9a7f10c2c20e |