我有一个烧瓶应用程序,它使用烧瓶安全性进行身份验证。我想使用带有石墨烯的 graphql来获取数据,但是我无法访问我一直用来解析请求的current_user代理。graphene 仅提供了一个可以理解的自定义可插入视图,但它无法在应用程序的上下文中访问 current_user,因此 current_user 恢复为 AnonymousUser。
这是一些示例代码
from flask import Flask, render_template, redirect, request
from flask_security import Security, SQLAlchemySessionUserDatastore, login_required, current_user, login_user
from flask_graphql import GraphQLView
import graphene
from graphene_sqlalchemy import SQLAlchemyConnectionField
from .models import UserModel, RoleModel, Todo, TodoModel
from .pipeline import session
app = Flask(__name__, template_folder="../templates", static_folder="../static")
app.config.from_object('core.pipeline.configs.DevConfig')
user_datastore = SQLAlchemySessionUserDatastore(session, UserModel, RoleModel)
security = Security(app, user_datastore)
@app.route('/')
@login_required
def index(path):
user = current_user
return render_template('index.html')