[MIDDLEWARE] middleware executed many times
还没有人认领这个 Issue。
评估
- 难度
- 4/5
- 预计耗时
- 3-5 天
- 新手友好度
- 25/100
调研方向
从 issue 中所示的 GraphQLView.as_view 配置和 DummyMiddleware.resolve 开始,然后使用 hello 查询、列表查询和 logout mutation 重现该行为。比较中间件的调用次数,并在确定由哪个组件负责之前,确定预期的单次执行行为。
由索引模型根据 Issue 内容生成。
描述
Hi there, I'm using flask-graphql in a project and got into a question/issue I don't have many clues. I'm using middlewares; this is the minimum example:
from flask import Flask, request
from flask_graphql import GraphQLView
from graphene import Field, ObjectType, Schema, String, relay
class Hello(ObjectType):
message = String()
class Query(ObjectType):
hello = Field(Hello)
def resolve_hello(self, info):
return Hello(message="Hi there")
class DummyMiddleware(object):
def resolve(self, next, root, info, **kwargs):
print("DummyMiddleware")
return next(root, info, **kwargs)
dummy_middleware = DummyMiddleware()
schema = Schema(query=Query)
app = Flask(__name__)
app.add_url_rule('/graphql', view_func=GraphQLView.as_view('graphql',
schema=schema,
graphiql=True,
middleware=[dummy_middleware]))
if __name__ == "__main__":
app.run(host='0.0.0.0', threaded=True)
(The problem happens no matter the version; the problem also happens when launching the wsgi app with gunicorn).
If I query "hello()", the "DummyMiddleware" will appear twice. If I query a list of elements, the middleware is executed lots of time, twice per element it seems.
For a query this is just a problem of performance, but in a Logout() mutation what happens is:
- 1st time - the authenticated request is valid, so "logout()" deletes the token
- 2nd time - the authenticated request is not valid (because the token has been deleted), so it returns an error
Is there anything wrong in my approach to middlewares? I'm not sure which part is responsible (flask, graphql, my configuration...). Any hint would be appreciated.
- 主要语言
- Python
- 星标
- 1.3k
- 派生
- 139
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
graphql-python/flask-graphql 的其他 Issue
-
难度 4/5 3-5 天 新手友好度 25/100
graphql-python/flask-graphql#92 · 2 条评论 ·
-
难度 4/5 3-5 天 新手友好度 25/100
-
难度 2/5 1-3 小时 新手友好度 35/100
graphql-python/flask-graphql#85 · 2 条评论 · 1 个 reaction ·
-
CSRF Exemption? 未关闭
难度 3/5 1-2 天 新手友好度 25/100
graphql-python/flask-graphql#84 · 1 条评论 ·
-
难度 4/5 3-5 天 新手友好度 35/100
graphql-python/flask-graphql#80 · 9 条评论 · 2 个 reaction ·
查看 graphql-python/flask-graphql 的全部 Issue
相似的 Issue
-
难度 2/5 1-3 小时 新手友好度 75/100
anthropics/skills#1811 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
speaches-ai/speaches#678 ·
-
bug
难度 2/5 1-3 小时 新手友好度 75/100
datalayer/mcp-compose#42 ·
-
难度 2/5 1-3 小时 新手友好度 75/100
conda-forge/spacy-feedstock#177 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
UKGovernmentBEIS/inspect_evals#2523 ·