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.

Source Distribution

graphql-utilities-0.2.0.tar.gz (5.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

graphql_utilities-0.2.0-py3-none-any.whl (8.1 kB view details)

Uploaded Python 3

File details

Details for the file graphql-utilities-0.2.0.tar.gz.

File metadata

  • Download URL: graphql-utilities-0.2.0.tar.gz
  • Upload date:
  • Size: 5.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for graphql-utilities-0.2.0.tar.gz
Algorithm Hash digest
SHA256 d552689a661618efd1a39cfe6bb7e83b789eb7dc09ef64074b177f587204c2ae
MD5 af63ed587ddb8e0e53a9e703eb43194c
BLAKE2b-256 aea8be0f0fe21b0b888115bee0df497fcafea76c2aa89fe96177b81dc9b9fd32

See more details on using hashes here.

File details

Details for the file graphql_utilities-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: graphql_utilities-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.1.1 pkginfo/1.5.0.1 requests/2.22.0 setuptools/45.1.0 requests-toolbelt/0.9.1 tqdm/4.42.1 CPython/3.7.6

File hashes

Hashes for graphql_utilities-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 230632e7785b1ec48251a5b5c16240b4ba308cc95362c19c15937c96ff20502a
MD5 251414931ae0b519dc1beb2903cb9948
BLAKE2b-256 6c657eef77470a065fda9e1c53352630079c347ca87c1ed8e5a78dc372c92ea7

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page