Graphene-django: In mutation, info.context.user returns AnonymousUser

Created on 14 Dec 2017  路  4Comments  路  Source: graphql-python/graphene-django

When making queries, the info.context.user returns a correct user.
However, then making the mutation, the same call to the info.context.user return AnonymousUser

Any suggestions what is going on?

Most helpful comment

Could you please provide further information as to where the configuration issue was?
I'm currently running into the exact same issue.

All 4 comments

As far as I can tell, we do not handle Mutations and Queries differently when it comes to their context. It should be calling get_context regardless.

Do you have more context you can share, or the minimum code it takes to reproduce the problem?

Hey,

It was my bad configuration of apollo-client and JWT middleware for authentication.

Thanks for great job guys!

L

Could you please provide further information as to where the configuration issue was?
I'm currently running into the exact same issue.

I see that this question still seems to be popular given the number of likes from the previous comment.

To anyone experiencing a similar issue:

graphql.error.located_error.GraphQLLocatedError: 'NoneType' object has no attribute 'context'

it may be caused by the ordering of the parameters.

Graphene always stores the mutation context, and hence the user transitively, in the second non-default parameter it receives.

Using,

def mutate(root, info, **kwargs)

The user is retrieved by calling info.context.user.

Using,

def mutate(info, root, **kwargs)

You would retrieve the user using root.context.user.

Always ensure that your parameter ordering is consistent throughout your function definitions.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

ZuluPro picture ZuluPro  路  3Comments

dan-klasson picture dan-klasson  路  4Comments

flame0 picture flame0  路  4Comments

BrianChapman picture BrianChapman  路  3Comments

StefanoSega picture StefanoSega  路  4Comments