Support lazy type references everywhere
まだ誰も着手していません。
評価
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 初心者へのやさしさ
- 42/100
- issue の種類
- 機能追加
- 明瞭さ
- おおむね明確
- 活発さ
- 停滞
- 技術スタック
- python
調査の方向性
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.
索引モデルが issue の本文から書いたものです。
説明
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
ObjectTypeor anotherInterface
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
Connectionshould 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
Unionchange above.
- 主要言語
- Python
- スター
- 8.2k
- フォーク
- 818
- PR マージ指標
- 30日以内にマージされた PR はありません
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
graphql-python/graphene のほかの issue
-
Tutorial mistakes オープン🐛 bug
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
graphql-python/graphene#1389 · コメント 5 件 · リアクション 2 件 ·
-
難易度 4/5 3〜5日 初心者へのやさしさ 68/100
graphql-python/graphene#1606 ·
-
Python 3.14 support オープン✨ enhancement
難易度 2/5 1〜3時間 初心者へのやさしさ 38/100
graphql-python/graphene#1601 · コメント 2 件 ·
-
🐛 bug
難易度 2/5 1〜3時間 初心者へのやさしさ 55/100
graphql-python/graphene#1593 ·
-
🐛 bug
難易度 4/5 3〜5日 初心者へのやさしさ 25/100
graphql-python/graphene#1592 ·
graphql-python/graphene の issue をすべて見る
似ている issue
-
area: harness bug status: needs-triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
Human-Agent-Society/reef#625 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 70/100
-
難易度 1/5 1時間未満 初心者へのやさしさ 80/100
learningequality/kolibri#15351 · コメント 2 件 ·
-
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
-
Name consistency オープン
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
eellak/triplestore#65 · コメント 1 件 ·