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

Support lazy type references everywhere

Đang mở
#1,600 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ó
4/5
Thời gian dự kiến
3-5 ngày
Mức phù hợp với người mới
42/100
Loại issue
Tính năng
Độ rõ ràng
Khá rõ ràng
Mức độ hoạt động
Đình trệ
Công nghệ
python
Lĩnh vực
backend-api-design

Hướng nghiên cứu

Review graphene/relay/connection.py around the node type checks and name handling, and graphene/types/objecttype.py around fields construction. Use PR #1599 as the Union precedent. Done means lazy string or callable references work consistently for Connection node types, Union members, and ObjectType or Interface interfaces.

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

Mô tả

✨ enhancement

Is your feature request related to a problem? Please describe.

Currently, Graphene supports lazy type references (a string or a callable) in fields, input fields, and arguments. But there are other places where types are coupled that don't support it. From what I can tell, it's these cases:

  • Node types of a relay.Connection
  • Member types of a Union
  • Interfaces of an ObjectType or another Interface

Lazy references are useful for modelling schemas with circular dependencies across multiple Python modules without creating circular imports. But they're also useful for non-static schemas, which you might have when some relationships depend on configuration such as feature flags that aren't available at import time. For example, it's possible to do this:

class SomeType(ObjectType):
   field = Field(lambda: OneType if CONFIG.get_feature_flag() else AnotherType)

but we can't have this:

class SomeUnion(Union):
    class Meta:
        types = (lambda: OneType if CONFIG.get_feature_flag() else AnotherType, ...) 

Overall, it's a bit unintuitive that lazy references are allowed in some places but not others.

Describe the solution you'd like
Support lazy type references consistently across all type declarations, including in the three cases described above.

Describe alternatives you've considered
For circular imports, it's usually possible to break dependencies elsewhere in the chain where lazy references are already supported. Though there may be some more contrived cases that only involve the relationships described above, where this wouldn't be possible.

For dynamic schema parts, you could define all schema components at runtime rather than statically, but in practice I think the static approach is cleaner in most cases and makes it easier to distribute schema components across multiple modules.

Additional context
I don't expect the changes to be huge, they should be non-breaking, and I'm happy to contribute them if people find this useful.

  • I've already prepared a PR for adding support to Union types: #1599
  • Supporting node types for Connection should be easier. The node construction already supports lazy references, we'd just need to remove the hard-coded instance check and handle cases where the name isn't available here.
  • Interfaces are probably the biggest change since that will require the entire fields construction here to be moved to a property to be resolved lazily. Even then, it's conceptually very similar to the Union change above.
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.