Skip to main content

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 custom ExecutionContext 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.

Files for graphql-utilities, version 0.3.0
Filename, size File type Python version Upload date Hashes
Filename, size graphql_utilities-0.3.0-py3-none-any.whl (8.2 kB) File type Wheel Python version py3 Upload date Hashes View
Filename, size graphql-utilities-0.3.0.tar.gz (5.8 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page