graphql-python / graphql-python/graphene
Subclass built-in scalars without creating new GraphQL type
- 主要言語
- Python
- スター
- 8.2k
- フォーク
- 818
- PR マージ指標
- 30日以内にマージされた PR はありません
説明
**Is your feature request related to a problem? Please describe.**
I'd like to be able to customise serialization logic for some scalars, e.g. a `NormalizedDecimal` that inherits from `Decimal` but calls `.normalize()` on the value during serialization. Unfortunately, this results in the GraphQL schema containing a new `NormalizedDecimal` scalar that clients don't know how to deserialize.
**Describe the solution you'd like**
I'd like the type to still be that of the superclass in the schema, e.g. `Decimal` in the above example.
**Describe alternatives you've considered**
I've tried overriding `Scalar.get_type()` to return the type of the superclass, but then the subclass doesn't function as intended, e.g. the custom serialization logic doesn't get invoked. I've also tried setting `Meta.name` to that of the superclass, but that also results in the custom serialization logic not being invoked.
コントリビューションガイド
このリポジトリのコントリビューションガイドは索引されていません
調査の方向性
まず、Issue の NormalizedDecimal の例を使って、Scalar.get_type() の挙動と Meta.name がスキーマ生成に与える影響を追跡します。Scalar のサブクラスがカスタムのシリアライズロジックを保持しながら、スキーマではスーパークラスの Scalar 型を公開できれば完了です。両方の挙動に対する焦点を絞ったテストを追加してください。
索引モデルが issue の本文から書いたものです。
評価
- 技術スタック
- graphql, python
- 領域
- api, backend-api-design
- issue の種類
- 機能追加
- 難易度
- 4/5
- 見積もり時間
- 3〜5日
- 活発さ
- 停滞
- 明瞭さ
- おおむね明確
- 初心者へのやさしさ
- 35/100