graphql-python / graphql-python/graphene
Subclass built-in scalars without creating new GraphQL type
- Lingua principale
- Python
- Stelle
- 8.2k
- Fork
- 818
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Descrizione
**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.
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Direzione di ricerca
Start by tracing the Scalar.get_type() behavior and how Meta.name affects schema generation, using the NormalizedDecimal example from the issue. Done means a scalar subclass can retain its custom serialization logic while the schema exposes the superclass scalar type; add focused tests for both behaviors.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Valutazione
- Stack tecnologico
- graphql, python
- Ambito
- api, backend-api-design
- Tipo di issue
- Funzionalità
- Difficoltà
- 4/5
- Tempo stimato
- 3-5 giorni
- Stato di attività
- Ferma
- Chiarezza
- Abbastanza chiara
- Idoneità per principianti
- 35/100