Support lazy type references everywhere
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 4/5
- Tiempo estimado
- 3-5 días
- Aptitud para principiantes
- 42/100
- Tipo de issue
- Nueva funcionalidad
- Claridad
- Bastante claro
- Estado de actividad
- Estancado
- Stack tecnológico
- python
- Área
- backend-api-design
Línea de trabajo
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.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- Python
- Estrellas
- 8.2k
- Forks
- 818
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Aún no hemos revisado los archivos de configuración de este proyecto. Empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de graphql-python/graphene
-
Tutorial mistakesAbierto🐛 bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
graphql-python/graphene#1389 · 5 comentarios · 2 reacciones ·
-
Support OneOf input object typesAbierto
Dificultad 4/5 3-5 días Aptitud para principiantes 68/100
graphql-python/graphene#1606 ·
-
Python 3.14 supportAbierto✨ enhancement
Dificultad 2/5 1-3 horas Aptitud para principiantes 38/100
graphql-python/graphene#1601 · 2 comentarios ·
-
🐛 bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 55/100
graphql-python/graphene#1593 ·
-
🐛 bug
Dificultad 4/5 3-5 días Aptitud para principiantes 25/100
graphql-python/graphene#1592 ·
Todos los issues de graphql-python/graphene
Issues similares
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
solana-foundation/pay-kit#341 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
nasa/python_cmr#123 ·
-
Dificultad 1/5 Menos de una hora Aptitud para principiantes 92/100
EleutherAI/lm-evaluation-harness#4243 ·
Los mantenedores suelen responder en 1 día
-
area: dashboard bug perceived difficulty: 3
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
Nitjsefnie-Harness-Commons/daedalus#1179 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 88/100
cusp-ai-oss/tojax#17 ·