Coder Social home page Coder Social logo

melvinkcx / graphql-utilities Goto Github PK

View Code? Open in Web Editor NEW
19.0 3.0 1.0 56 KB

Oneshot middleware, query cost analysis, depth limiting, etc for graphql-core>=3.0 (formerly, graphql-core-next)

Home Page: https://graphql-utilities.readthedocs.io/

License: MIT License

Python 100.00%

graphql-utilities's Issues

Feature: do not count specific fields when calculating depth

Some schema may be created like normal or relay:

normal:

{
  allUsers { id username }
}

relay:

{
  allUsers { edges { node { id username } } }
}

I think, need skip edges and node in depth analysis.

The configuration can be implemented for example like this:

{
    "depth_analysis": {
        "max_depth": 2,  # Maximum depth allowed
        "skip": [EdgeClass, NodeClass],  # Do not count
     }
}

Graphene>=3.0 Integration

With graphene==3.0b1 being released, we can start looking into the integration with it.

For graphql-utilities to work with graphene>=3.0, we need to solve these issues:

  • How to define cost in graphene, since schemas are defined using classes
  • How to pass custom context value and ExecutionContext class for execution in graphene

Graphene usage with GraphQL-utitlities

Hey I saw your issue on Graphene as I was looking around for how to have request level middleware and evidently i'm not the only person who has had this issue ๐Ÿ˜„ graphql-python/graphene#1117

Seems like your library solves that plus some other useful features but from the looks of

install_requires=['graphql-core>=3.0'],
it requires greater than graphql-core > 3 and latest stable version of Graphene requires graphql-core < 3

https://github.com/graphql-python/graphene/blob/3d0e460be166cbb7c3701a9d91030eb15c73e382/setup.py#L88

Just wondering if they were designed to work together or is this more of a replacement? Thanks and great work ๐Ÿ‘

Integration with Graphene Django

Is it possible to integrate graphql-utilities with graphene-django?
The last version of graphene-django is 2.9.1 which depends on graphql-core<3.0.

Multiple Middlewares with run_only_once decorator will only execute the first one

I think there is a bug in the decorator:

if isinstance(info.context, dict) and not info.context.get("__middleware_ran", False):

If you have multiple middlewares decorated with run_only_once only the first one will be executed because the check is written in the shared context.

Untested but something like this should work (check is bound to functionpointer):

from functools import wraps

def run_only_once(resolve_func):
    @wraps(resolve_func)
    def wrapper(instance, next, root, info, *args, **kwargs):
        if not getattr(resolve_func, "__once", False):
            setattr(resolve_func, '__once', True)
            return resolve_func(instance, next, root, info, *args, **kwargs)
        return next(root, info, *args, **kwargs)
    return wrapper

Btw. move the from functools import wraps out of the function scope, otherwise this will be a dynamic import and will reimport wraps on every call

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.