Hacktoberfest 2026:メンテナが10月に向けて印を付けた、オープンで初心者向けの issue。 Hacktoberfest の issue を見る

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

オープン
#1,354 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

評価

難易度
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. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

graphql-python/graphene のほかの issue

graphql-python/graphene の issue をすべて見る

似ている issue

Python の issue をもっと見る

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。