简体   繁体   中英

How to access authenticated user in graphene-django resolve method?

I have added this to my Query class and it's returning null in response.

me = graphene.Field(UserType)

def resolve_user(root, info):
    logger.info("***** Inside resolve ****")
    return info.context.user

and my UserType is defined like this.

class UserType(DjangoObjectType):
    fields = ["id", "name", "email", "username"]

    class Meta:
        model = User

I'm on Django==3.0 if it helps

I'm authenticated and the cookies are present. It's not even printing the log which is confusing me.

Graphene fields use resolve_<field> pattern to resolve the values. Check more here

me = graphene.Field(UserType)
^^

def resolve_me(root, info):
    logger.info("***** Inside resolve ****")
    return info.context.user

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM