[MIDDLEWARE] middleware executed many times
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức phù hợp với người mới
- 25/100
Hướng nghiên cứu
Bắt đầu từ cấu hình GraphQLView.as_view và DummyMiddleware.resolve được nêu trong issue, sau đó tái hiện hành vi với truy vấn hello, một truy vấn danh sách và mutation logout. So sánh số lần middleware được gọi và xác định hành vi dự kiến là chỉ thực thi một lần trước khi xác định thành phần nào chịu trách nhiệm.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
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.
- Ngôn ngữ chính
- Python
- Star
- 1.3k
- Fork
- 139
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Hướng dẫn đóng góp
Chưa lập chỉ mục được hướng dẫn đóng góp cho kho mã nguồn này
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của graphql-python/flask-graphql
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
graphql-python/flask-graphql#92 · 2 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 25/100
-
which graphiql version is using? Đang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
graphql-python/flask-graphql#85 · 2 bình luận · 1 reaction ·
-
CSRF Exemption? Đang mở
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 25/100
graphql-python/flask-graphql#84 · 1 bình luận ·
-
Độ khó 4/5 3-5 ngày Mức phù hợp với người mới 35/100
graphql-python/flask-graphql#80 · 9 bình luận · 2 reaction ·
Tất cả issue của graphql-python/flask-graphql
Issue tương tự
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
anthropics/skills#1811 · 1 bình luận ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
speaches-ai/speaches#678 ·
-
bug
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
datalayer/mcp-compose#42 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 75/100
conda-forge/spacy-feedstock#177 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 70/100
UKGovernmentBEIS/inspect_evals#2523 ·