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.

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.1.0.tar.gz (4.7 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.1.0-py3-none-any.whl (7.5 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: graphql-utilities-0.1.0.tar.gz
  • Upload date:
  • Size: 4.7 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.0 CPython/3.7.5

File hashes

Hashes for graphql-utilities-0.1.0.tar.gz
Algorithm Hash digest
SHA256 58e6a7980a07513f03f9ecae7dc40faf1939878019b6dd398e6ad0b19d697c9a
MD5 330974e1f450e8e93c29deb6e4e9cd7b
BLAKE2b-256 f32dc26d0e056046106531d35b6266e8d057578d5e56111734a5ca5997757a7e

See more details on using hashes here.

File details

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

File metadata

  • Download URL: graphql_utilities-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.5 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.0 CPython/3.7.5

File hashes

Hashes for graphql_utilities-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 c8354a06e88cb4aed207ceb6d7f5a3dc5b77f86b68282f8464e162dafb1d69cc
MD5 65628f8dae5036222b68b0b8676ed22e
BLAKE2b-256 a3ca00329cd10c515d2f80a4f7cfbdeb560a542ab9631e6ecc27d39b53465dbc

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