Giter VIP home page Giter VIP logo

Comments (7)

jhgg avatar jhgg commented on August 19, 2024

Regarding graphene, I think that the execution context should be added to get_node. As a good practice, the execution context should be available in all resolvers for this very reason.

Regarding graphql-core, in addition to root_value, I provide a request_context inside of ExecutionContext which can be set to any value you want to use. In graphql-django-view, I use it to store the current request object from Django. But given your use-case, perhaps it would make more sense to pass it a dict containing your session and auth objects.

You should be able to do this using graphene.core.Schema.execute() by passing request_context as a kwarg to that function.

I.e. somewhere:

schema.execute(query, request_context={
   'session': Session(),
   'auth': get_auth()
})

In a standard resolver, you would then access session by doing info.request_context['session']

def resolve_ship(self, args, info):
    session = info.request_context['session']
    ship_id = args.get('id')
    ship = session.query(Ship).filter_by(id=ship_id).one()
    return Ship(ship)

from graphene.

inklesspen avatar inklesspen commented on August 19, 2024

I can prepare a PR to make get_node work like other resolver functions (with the possibility of decorating it with resolve_only_args for the previous style of behavior).

That is:

class Foo(Node):
    @classmethod
    def get_node(cls, args, info):
        # do the right thing
        pass

or

class Foo(Node):
    @classmethod
    @resolve_only_args
    def get_node(cls, id):
        # do the right thing
        pass

Would such a PR be accepted?

from graphene.

jhgg avatar jhgg commented on August 19, 2024

This is going to be a breaking change... but I think should be made. 0.5.0 here we come lol.

from graphene.

syrusakbary avatar syrusakbary commented on August 19, 2024

@inklesspen Yep, is a breaking change but will be accepted.
However a node could only be retrieved by the id arg (there are no other args in the base javascript implementation/ relay specification)
So, the syntax could be something like this:

    @classmethod
    def get_node(cls, id, info):
        pass

from graphene.

inklesspen avatar inklesspen commented on August 19, 2024

ok, so it wouldn't support resolve_only_args then.

I will try to prepare a PR in the next day or so.

from graphene.

inklesspen avatar inklesspen commented on August 19, 2024

Just a reminder the PR is ready.

from graphene.

syrusakbary avatar syrusakbary commented on August 19, 2024

Merged!

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.