question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Discussion - Pass context to resolve methods

See original GitHub issue

The context story seems very confused in the newest version. My understanding from the graphql-js 0.5.0 release notes is that all resolving functions should now have the signature ([self,] args, context, info), as opposed to ([self,] args, info).

At the moment, if I update a resolve_NAME method to take context, then it throws argument errors.

Also, mutations don’t take context and therefore they cannot access context data. It think a patch similar to this one on graphql-relay-js is necessary for the relay mutations at least, but probably for all of them.

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Comments:19 (15 by maintainers)

github_iconTop GitHub Comments

5reactions
vinigfercommented, Nov 3, 2017

In case anyone is also having troubles on how to access the context, after an endless effort/search I found on this link:

http://docs.graphene-python.org/projects/django/en/latest/authorization/

that I can access context like this:

if not info.context.user.is_authenticated():

Hope this helps anyone

3reactions
FrankSaladcommented, Oct 20, 2017

According to the docs: http://docs.graphene-python.org/en/latest/types/objecttypes/

By default resolvers take the arguments args, context and info.

Followed by

    def resolve_reverse(self, info, word):
        return word[::-1]

As you can see, the example resolver method only has the self, info and word params. There was no usage of args or context at all, and no mention of what I should actually find passed in info. I’m still digging around to try to understand what I should expect in these params. This is confusing and unpythonic. The expectation around function params is that if they’re positional, their actual names don’t matter. I had to find this issue to understand what you guys were even trying to do here. If your intent was to create a function that ignores some of its arguments, adding **kwargs to the end to do so explicitly is the right way.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Pass context to a method that is declared in the base class
Is there a way to pass the context from one method to another without having to use the entity name of EntityName so...
Read more >
Passing a context object to the constructor or to the method
Sometimes you want both - passing a global or root context into the constructor and an optional sub-context to the query/parse method.
Read more >
Section 4. Techniques for Leading Group Discussions
Decide on an action; Provide mutual support; Solve a problem; Resolve a conflict; Plan your work or an event. Possible leadership styles of...
Read more >
Context | Android Developers
Context. Public methods. bindIsolatedService; bindService; bindService ... Remove all permissions to access a particular content provider Uri that were ...
Read more >
How to use React Context effectively - Kent C. Dodds
If it's just using the default value that's been provided, then it can't really do much good. 99% of the time that you're...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found