Giter VIP home page Giter VIP logo

Comments (5)

mjtamlyn avatar mjtamlyn commented on August 19, 2024 1

I've written something along these lines for my own project. It just works on a connection at the moment. It uses the info to work out which fields (if any) are being requested on the underlying node, and then checks the corresponding node type for a optimize_foo classmethod. If that exists, it passes the queryset through that method, before passing the queryset to the connection_from_foo function. They have a similar signature to a resolver. You have to be careful in resolver methods that both optimized and non-optimized cases are covered in some cases.

class PostNode(DjangoNode):
    [...]

    @classmethod
    def optimize_owner(cls, queryset):
        return queryset.select_related('owner')

    @classmethod
    @with_context
    def optimize_loved(cls, queryset, context):
        # Sets user_loves attribute on post
        return queryset.prefetch_user_loves(context.user)

    @with_context
    def resolve_loved(self, args, context, info):
        try:
            return self.user_loves
        except AttributeError:
            return self.love_set.filter(user=context.user).exists()

    @classmethod
    def optimize_field_with_arguments(cls, queryset, args):
        return queryset.process_args(args)

from graphene.

bigblind avatar bigblind commented on August 19, 2024

I think you can get this info from the query AST, but there should be a more convenient way to get this.

from graphene.

syrusakbary avatar syrusakbary commented on August 19, 2024

Related issue needed to resolve before this task: #57

from graphene.

jkimbo avatar jkimbo commented on August 19, 2024

@syrusakbary I think this issue can be closed? If it's still an issue then it should be raised on the graphene-django repo

from graphene.

syrusakbary avatar syrusakbary commented on August 19, 2024

Yup, we can close the issue here and reopen in graphene-django if necessary

from graphene.

Related Issues (20)

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.