PedroBern / django-graphql-auth

Django registration and authentication with GraphQL.

Home Page:https://django-graphql-auth.readthedocs.io/en/latest/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Different id user query when I use info.context.user.id schema.py

patrykKlimczak opened this issue · comments

Description

I have the different id user query when I use info.context.user.id schema.py.

Steps to Reproduce

  1. Create extend django user model
  2. Create schema
class Query(graphene.ObjectType):
    user = graphene.Field(UserType, token=graphene.String(required=True))

    @login_required
    def resolve_user(self, info, **kwargs):
        print(info.context.user.id, 'my user schema id')
        return info.context.user

  1. Create the example model (ex. Post)
  2. Create schema
class Query(graphene.ObjectType):
    post_partner = graphene.List(PostType)

    def resolve_post_partner(self, info):
        print(info.context.user.id, 'my user partner id')
        return Post.objects.order_by('-updated_at').filter(partner_id=info.context.user.id)
  1. Get query on graphQL. In the same time I have two query with id one is user model, second is example model. First I have correct ID, but the Post model I have None Id
    image
  1. When I log in app I use this mutation FRONTEND SIDE:

export const TOKEN_AUTH = gql`
  mutation tokenAuth($username:String!, $password: String!) {
    tokenAuth(username: $username, password: $password) {
      token,
      success,
      errors,
      unarchiving,
      user {
        id,
        username
      }
    }
  }
`;

async tokenAuth() {
      await this.$apollo.mutate({
        mutation: TOKEN_AUTH,
        variables: {
          username: this.username,
          password: this.account.password,
        }
      }).then(response => {
        if (response.data.tokenAuth.success) {
          const token = response.data.tokenAuth.token;
          this.$store.dispatch('user/setToken', token);
          this.verifyToken(token)
        } else {
          console.log(response.data.tokenAuth.errors.nonFieldErrors[0].message)
        }
      })
    },

Expected behavior

The same info.context.user.id in two query base the same info.

Actual behavior

Different, None or anonymous, but when I log i admin panel django I have the second query info.user.id -> id user who login i admin panel django

Requirements

aniso8601==7.0.0
Django==2.2.7
django-debug-toolbar==2.1
django-filter==2.2.0
django-webpack-loader==0.6.0
graphene==2.1.8
graphene-django==2.6.0
graphql-core==2.2.1
graphql-relay==2.0.0
promise==2.2.1
pytz==2019.3
Rx==1.6.1
singledispatch==3.4.0.3
six==1.13.0
sqlparse==0.3.0
redis==3.3.11
Pillow==6.2.1
djangorestframework==3.10.3
django-extensions==2.2.5
psycopg2==2.8.5
psycopg2-binary==2.7.6
six==1.13.0
sqlparse==0.3.0
celery==4.3.0
amqp==2.5.2
django-cors-headers==2.1.0
django-graphql-jwt==0.3.0
graphene-file-upload==1.2.2
django-graphql-auth==0.3.10
django-environ==0.4.5