graphql_env

The package for setting up a GraphQL Environment with custom backends


Keywords
graphql_env
License
MIT
Install
pip install graphql_env==0.1.0

Documentation

GraphQL-Env Build Status PyPI version Coverage Status

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