Hacktoberfest 2026:维护者为十月标记出来的 issue,仍然开放、适合新手。 浏览 Hacktoberfest issue

FragmentSpread' object has no attribute 'selection_set' with custom Middleware

未关闭
#1,354 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

评估

难度
3/5
预计耗时
1-2 天
新手友好度
42/100
Issue 类型
缺陷
描述清晰度
基本清楚
活跃度
停滞
技术栈
graphql, python
领域
api, backend

调研方向

该失败发生在报告中所示的 custom DepthAnalysisBackend.document_from_string 遍历过程中;首先检查 document.document_ast 中的 AST 节点,包括 FragmentSpread 和片段定义。确认所提供的片段查询能够在不出现属性错误的情况下完成,并且深度检查仍按预期运行。

由索引模型根据 Issue 内容生成。

描述

🐛 bug

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

贡献指南

这个仓库没有索引到贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

graphql-python/graphene 的其他 Issue

查看 graphql-python/graphene 的全部 Issue

相似的 Issue

更多 Python Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。