graphql-python / graphql-python/graphene

Subclass built-in scalars without creating new GraphQL type

Abierto
#1,553 0 comentarios 0 reacciones 0 asignados Ver en GitHub
✨ enhancement
Lenguaje dominante
Python
Estrellas
8.2k
Forks
818
Métricas de merge de PR
Sin PR fusionados en 30 d

Descripción

**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.

Guía de contribución

No hay ninguna guía de contribución indexada para este repositorio

Línea de trabajo

Comienza rastreando el comportamiento de Scalar.get_type() y cómo Meta.name afecta a la generación del esquema, usando el ejemplo NormalizedDecimal del issue. La tarea estará terminada cuando una subclase de Scalar pueda conservar su lógica de serialización personalizada mientras el esquema expone el tipo Scalar de la superclase; añade pruebas específicas para ambos comportamientos.

Escrito por el modelo de indexación a partir del texto del issue.

Evaluación

Stack tecnológico
graphql, python
Área
api, backend-api-design
Tipo de issue
Nueva funcionalidad
Dificultad
4/5
Tiempo estimado
3-5 días
Estado de actividad
Estancado
Claridad
Bastante claro
Aptitud para principiantes
35/100

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.