GraphQL-Env
GraphQL-Env provides a GraphQL environment with pluggable query optimizers (backends) for Python GraphQL servers.
Installation
For instaling GraphQL-Env, just run this command in your shell
pip install graphql-env
Examples
Here is one example for you to get started:
from graphql_env import GraphQLEnv
# schema = graphene.Schema(...)
graphql_env = GraphQLEnv(
schema=schema,
)
my_query = graphql_env.document_from_string('{ hello }')
result = my_query.execute()
Usage with Quiver Cloud
Quiver is a JIT compiler for GraphQL queries. It reduces the CPU effort to make the query to the maximum, similar performance as if you write the data retrieval by hand (0 overhead from GraphQL).
Here is an example usage for Quiver:
from graphql_env import GraphQLEnv
from graphql_env.backend.quiver_cloud import GraphQLQuiverCloudBackend
# schema = graphene.Schema(...)
graphql_env = GraphQLEnv(
schema=schema,
backend=GraphQLQuiverCloudBackend(
'http://******@api.graphql-quiver.com'
)
)
my_query = graphql_env.document_from_string('{ hello }')
result = my_query.execute()
Note: Quiver Cloud is using requests
under the hood. Systems like Google App Engine
need a monkeypatch to have it working properly
Contributing
After cloning this repo, ensure dependencies are installed by running:
pip install -e ".[test]"
After developing, the full test suite can be evaluated by running:
py.test graphql_env --cov=graphql_env --benchmark-skip # Use -v -s for verbose mode
You can also run the benchmarks with:
py.test graphql_env --benchmark-only
Documentation
The documentation is generated using the excellent Sphinx and a custom theme.
The documentation dependencies are installed by running:
cd docs
pip install -r requirements.txt
Then to produce a HTML version of the documentation:
make html