标签: graphene-django

如何在 graphene-django GraphQLTestCase 中使用 django-grahql-jwt 进行身份验证?

我正在尝试根据 graphene django 文档测试我的突变。该突变与@login_required装饰器一起使用,但存在一个问题,因为任何登录测试方法都不起作用。我尝试过self.client.loginself.client.force_login. 我什至做了一个 tokenAuth 突变,并在那里硬编码了一些凭据,但它也不起作用;用户仍然是匿名的。

def test_create_member_mutation(self):
    response = self.query(
        '''
        mutation createMember($firstName: String) {
            createMember(firstName: $firstName) {
                member {
                    id
                }
            }
        }
        ''',
        op_name='createMember',
        variables={'firstName': 'Foo'}
    )

    self.assertResponseNoErrors(response)
Run Code Online (Sandbox Code Playgroud)

python django graphql graphene-django django-graphql-jwt

2
推荐指数
1
解决办法
1836
查看次数

Django GraphQL 返回 null

我有一个 Django GraphQL 应用程序 ( graphene_django ) 与 djongo ( mongoDB ) 一起运行 ) )。

当我尝试列出所有 twitter 查询时(使用 GraphiQL)时,它返回空数据:

我的查询:

query {
  allTwitterQueries {
    id,
    keyword
  }
}
Run Code Online (Sandbox Code Playgroud)

回报:

{
  "data": {
    "allTwitterQueries": null
  }
}
Run Code Online (Sandbox Code Playgroud)

这是我的 Django 文件:

无标题/schema.py

query {
  allTwitterQueries {
    id,
    keyword
  }
}
Run Code Online (Sandbox Code Playgroud)

无标题/api/models.py

{
  "data": {
    "allTwitterQueries": null
  }
}
Run Code Online (Sandbox Code Playgroud)

无标题/api/schema.py

import untitled.api.schema
import graphene

from graphene_django.debug import DjangoDebug


class Query(
    untitled.api.schema.Query,
    graphene.ObjectType,
):
    debug = graphene.Field(DjangoDebug, name="_debug")


schema = graphene.Schema(query=Query)
Run Code Online (Sandbox Code Playgroud)

我的 …

python django graphql graphene-django

1
推荐指数
1
解决办法
1124
查看次数

如何使用石墨烯突变信息访问 django 请求

我收到此错误“WSGIRequest”对象没有属性“请求”

PS:片段被截断了。错误来自 info.context.request

  class Arguments:
    input = ForgotPasswordInput()

  ok = graphene.Boolean()
  message = graphene.String()

  @staticmethod
  def mutate(root, info, input=None):
    try:
      user = User.objects.get(email=input.get('email'))
      current_site = get_current_site(info.context.request)```

Run Code Online (Sandbox Code Playgroud)

django graphene-django

1
推荐指数
1
解决办法
1192
查看次数

断言错误:您需要在 UserProfile.Meta 中传递有效的 Django 模型,收到“无”

我正在使用 AbstractBaseUser 自定义用户模型将 Django 模型添加到 graphql api。管理员工作正常,但我在尝试访问 graphql api 时收到错误消息,“您需要在 UserProfile.Meta 中传递有效的 Django 模型,收到“无””

我已经尝试将 AUTH_USER_MODEL = 'noxer_app.MyUser' 添加到设置中,但它不起作用

在models.py中:

from django.db import models
from django.contrib.auth.models import (
    BaseUserManager, AbstractBaseUser
)


class MyUserManager(BaseUserManager):
    def create_user(self, email, first_name, last_name, company, company_reg_no, address, phone, image, password=None):

        if not email:
            raise ValueError('Users must have an email address')

        user = self.model(
            email=self.normalize_email(email),
            first_name=first_name,
            last_name=last_name,
            company=company,
            company_reg_no=company_reg_no,
            address=address,
            phone=phone,
            image=image,
        )

        user.set_password(password)
        user.save(using=self._db)
        return user

    def create_superuser(self, email, first_name, last_name, company, company_reg_no, address, phone, image, …
Run Code Online (Sandbox Code Playgroud)

django graphene-django

0
推荐指数
1
解决办法
897
查看次数