FragmentSpread' object has no attribute 'selection_set' with custom Middleware
还没有人认领这个 Issue。
评估
调研方向
该失败发生在报告中所示的 custom DepthAnalysisBackend.document_from_string 遍历过程中;首先检查 document.document_ast 中的 AST 节点,包括 FragmentSpread 和片段定义。确认所提供的片段查询能够在不出现属性错误的情况下完成,并且深度检查仍按预期运行。
由索引模型根据 Issue 内容生成。
描述
Hello, I am using custom middleware to mesure complexity of graphql query, but it throws an error FragmentSpread' object has no attribute 'selection_set' with custom Middleware when using fragments.
Query example
query{
getProfile(id:1){
...test
}
}
fragment test on ProfileType{
id
}
The middleware
from graphql.backend.core import GraphQLCoreBackend
def measure_depth(selection_set, level=1):
current_depth = level
for field in selection_set.selections:
if field.selection_set:
new_depth = measure_depth(field.selection_set, level=level + 1)
if new_depth > current_depth:
current_depth = new_depth
if new_depth > 3:
raise Exception('Query is too nested')
return current_depth
class DepthAnalysisBackend(GraphQLCoreBackend):
def document_from_string(self, schema, document_string):
document = super().document_from_string(schema, document_string)
ast = document.document_ast
for definition in ast.definitions:
if len(definition.selection_set.selections) > 1:
raise Exception("Query is too complex")
measure_depth(definition.selection_set)
return document
How to fix this, and what Fragments use instead of selection_set
- 主要语言
- Python
- 星标
- 8.2k
- 派生
- 818
- PR 合并指标
- 30 天内没有已合并 PR
贡献指南
这个仓库没有索引到贡献指南
从这里开始
- 先读完整个 Issue,再读项目的贡献指南。
- 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
- Fork 仓库,在一个分支上完成修改。
- 提交 Pull Request,并在描述里引用这个 Issue 编号。
graphql-python/graphene 的其他 Issue
-
🐛 bug
难度 2/5 1-3 小时 新手友好度 72/100
graphql-python/graphene#1389 · 5 条评论 · 2 个 reaction ·
-
难度 4/5 3-5 天 新手友好度 68/100
graphql-python/graphene#1606 ·
-
✨ enhancement
难度 2/5 1-3 小时 新手友好度 38/100
graphql-python/graphene#1601 · 2 条评论 ·
-
✨ enhancement
难度 4/5 3-5 天 新手友好度 42/100
graphql-python/graphene#1600 ·
-
🐛 bug
难度 2/5 1-3 小时 新手友好度 55/100
graphql-python/graphene#1593 ·
查看 graphql-python/graphene 的全部 Issue
相似的 Issue
-
难度 1/5 1 小时以内 新手友好度 75/100
-
hcocena 未关闭policies-accepted pre-review precheck-passed
难度 1/5 1 小时以内 新手友好度 88/100
Bioconductor/BiocContributions#214 · 5 条评论 ·
-
难度 1/5 1 小时以内 新手友好度 92/100
TencentCloud/Octop#1169 · 1 条评论 ·
-
难度 2/5 1-3 小时 新手友好度 70/100
521xueweihan/HelloGitHub#3778 ·
-
The version checker's trailing attribute region has no control for a less-than inside a quoted value 未关闭area: dashboard area: tests bug perceived difficulty: 2 python
难度 2/5 1-3 小时 新手友好度 84/100
Nitjsefnie-Harness-Commons/daedalus#1105 · 1 条评论 ·