到目前为止,我一直在关注这个博客tutorial...well,我正在生成token...using GraphQl的默认模板
input->
mutation{
tokenAuth(username:"riyad", password:"1234"){
token
}
}
output->
{
"data": {
"tokenAuth": {
"token": "eyJ0eXAiOiJKV1QiLCJhbGciOiJIUzI1NiJ9.eyJ1c2VybmFtZSI6InJpeWFkIiwiZXhwIjoxNTkzNTI0Nzk5LCJvcmlnX2lhdCI6MTU5MzUyNDQ5OX0.DjploWeEwLpRBZX0wz5_NSqz22qDHbgNI26uXs6fuXE"
}
}
}但是当我使用失眠进行抓取时,我没有得到我创建的用户authorize....rather它引发异常...


我的架构文件->
class UserType(DjangoObjectType):
class Meta:
model = get_user_model()
class Query(graphene.ObjectType):
me = graphene.Field(UserType)
users = graphene.List(UserType)
def resolve_users(self, info, **kwargs):
return get_user_model().objects.all()
def resolve_me(self, info):
user = info.context.user
if user.is_anonymous:
raise Exception('Not logged in!')
return user我额外添加的settings.file
GRAPHENE = {
'SCHEMA': 'hackernews.schema.schema'
}
'''python(path=“…/graphql-python/hackernews/hackernews/settings.py”) GRAPHENE = { ‘SCHEMA’: ‘mysite.myschema.schema’, ‘MIDDLEWARE’: [ ‘graphql_jwt.middleware.JSONWebTokenMiddleware’, ], } '''
AUTHENTICATION_BACKENDS = [
'graphql_jwt.backends.JSONWebTokenBackend',
'django.contrib.auth.backends.ModelBackend',
]我的主应用程序->
import graphene
import links.schema
import users.schema
import graphql_jwt
class Query(users.schema.Query, links.schema.Query, graphene.ObjectType):
pass
class Mutation(users.schema.Mutation, links.schema.Mutation, graphene.ObjectType):
token_auth = graphql_jwt.ObtainJSONWebToken.Field()
verify_token = graphql_jwt.Verify.Field()
refresh_token = graphql_jwt.Refresh.Field()
schema = graphene.Schema(query=Query, mutation=Mutation)发布于 2020-07-01 02:01:05
我通过搬家解决了它
'MIDDLEWARE': [ 'graphql_jwt.middleware.JSONWebTokenMiddleware', ], 它位于settings.py文件中的石墨烯变量中,也位于同一文件中的中间件变量中。
参考--> https://github.com/howtographql/howtographql/issues/983
https://stackoverflow.com/questions/62659151
复制相似问题