Circular import solution
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 5/5
- Tiempo estimado
- Más de una semana
- Aptitud para principiantes
- 35/100
Línea de trabajo
Empieza revisando graphene/types/schema.py alrededor de construct_fields_for_type y los métodos get_type/import_string de utils; después, reproduce el ejemplo de importación circular de la discusión enlazada. Se considera terminado cuando se determine si pasar el schema resuelve el ejemplo sin romper la resolución de tipos existente y se documente la decisión resultante.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
I would like to contribute a solution to the circular import problem. As far as I can see, currently this problem has some workaround through the Dynamic type:
https://github.com/graphql-python/graphene/issues/522#issuecomment-626075061
From my point of view strategy described in this link is pretty much elegant, since it uses type argument from Scheme constructor, which has relevant description:
types (List[GraphQLType], optional): List of any types to include in schema that
may not be introspected through root types.
But instead of creating new types and making syntax even more complicated and non-readable, I would like to propose a solution with schema pushing down to the import_string method from utils.
Apparently, it was not difficult task:
I made fast and simple changes in interfaces, in order to do this:
Changed type method interface of Field class:
def type(self, schema):
return get_type(self._type, schema)
Then reducer invocation here :
def construct_fields_for_type(self, map, type, is_input_type=False):
fields = OrderedDict()
for name, field in type._meta.fields.items():
if isinstance(field, Dynamic):
field = get_field_as(field.get_type(self.schema), _as=Field)
if not field:
continue
map = self.reducer(map, field.type(self.schema))
field_type = self.get_field_type(map, field.type(self.schema))
Small changes for get_type method:
def get_type(_type, schema=None):
if isinstance(_type, string_types):
return import_string(_type, schema=schema)
def import_string(type_name, dotted_attributes=None, schema=None):
if schema:
try:
scheme_type = next(type_ for type_ in schema.types if type_._meta.name == type_name)
return scheme_type
except StopIteration:
pass
....
At the end of a day I was able to run code from link without problems.
from graphene import ObjectType, List
class FooBarBaz(ObjectType):
foo_bars = List('FooBar', required= True)
It is a small fix, I made them with respect to my first impression of graphene structure.
Please, give me feedback, if this solution is okay for you, I will make a pull request.
If not, please, describe why and how can I then avoid circular import
- Lenguaje dominante
- Python
- Estrellas
- 8.2k
- Forks
- 822
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: 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 ·
-
✨ enhancement
Dificultad 4/5 3-5 días Aptitud para principiantes 42/100
graphql-python/graphene#1600 ·
-
Inaccurate Float-to-Decimal Conversion in `parse_value` of `Decimal` `Scalar`Posiblemente ocupada @mak626 la tomó hace 607 días. Abierto🐛 bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 55/100
graphql-python/graphene#1593 ·
Todos los issues de graphql-python/graphene
Issues similares
-
bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100
awslabs/visual-asset-management-system#414 ·
Los mantenedores suelen responder en 1 día
-
bug v1 v2
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
modelcontextprotocol/python-sdk#3670 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
aicell-lab/bioengine#232 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 74/100
modelscope/evalscope#1836 ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 72/100