Hacktoberfest 2026: những issue maintainer đã đánh dấu cho tháng Mười, đang mở và phù hợp người mới. Xem issue Hacktoberfest

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

Đang mở
#1,354 0 bình luận 0 reaction 0 người được giao Xem trên GitHub

Chưa có ai nhận issue này.

Đánh giá

Độ khó
3/5
Thời gian dự kiến
1-2 ngày
Mức phù hợp với người mới
42/100
Loại issue
Lỗi
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
graphql, python
Lĩnh vực
api, backend

Hướng nghiên cứu

Lỗi xảy ra trong quá trình duyệt custom DepthAnalysisBackend.document_from_string được nêu trong báo cáo; trước tiên hãy kiểm tra các nút AST trong document.document_ast, bao gồm FragmentSpread và định nghĩa fragment. Xác nhận rằng truy vấn fragment được cung cấp hoàn tất mà không gặp lỗi thuộc tính và việc kiểm tra độ sâu vẫn hoạt động như dự kiến.

Do mô hình lập chỉ mục viết ra từ nội dung của issue.

Mô tả

🐛 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

Ngôn ngữ chính
Python
Star
8.2k
Fork
822
Chỉ số merge pull request
Không có pull request nào được merge trong 30 ngày

Chuẩn bị môi trường

Dự án này không cung cấp dev container, Dockerfile hay hướng dẫn đóng góp, nên bạn cần tự thiết lập môi trường: hãy bắt đầu từ README và xem hướng dẫn đóng góp lần đầu của chúng tôi để biết các bước chung.

Bắt đầu từ đâu

  1. Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
  2. 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.
  3. Fork repository và làm thay đổi trên một nhánh.
  4. Mở pull request có tham chiếu số hiệu của issue.

Issue khác của graphql-python/graphene

Tất cả issue của graphql-python/graphene

Issue tương tự

Thêm issue về Python

Nhận issue mới trong hộp thư của bạn

Bản tóm tắt ngắn những issue GitHub phù hợp với người mới.