Circular import solution
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 5/5
- Tempo stimato
- Più di una settimana
- Idoneità per principianti
- 35/100
Direzione di ricerca
Inizia esaminando graphene/types/schema.py nella sezione relativa a construct_fields_for_type e i metodi get_type/import_string di utils, quindi riproduci l’esempio di importazione circolare della discussione collegata. Il lavoro è completato quando si determina se passare lo schema risolve l’esempio senza compromettere la risoluzione dei tipi esistente e si documenta la decisione risultante.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
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
- Lingua principale
- Python
- Stelle
- 8.2k
- Fork
- 818
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Guida per i contributori
Nessuna guida per i contributori indicizzata per questo repository
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di graphql-python/graphene
-
Tutorial mistakes Aperta🐛 bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 72/100
graphql-python/graphene#1389 · 5 commenti · 2 reazioni ·
-
Difficoltà 4/5 3-5 giorni Idoneità per principianti 68/100
graphql-python/graphene#1606 ·
-
Python 3.14 support Aperta✨ enhancement
Difficoltà 2/5 1-3 ore Idoneità per principianti 38/100
graphql-python/graphene#1601 · 2 commenti ·
-
✨ enhancement
Difficoltà 4/5 3-5 giorni Idoneità per principianti 42/100
graphql-python/graphene#1600 ·
-
🐛 bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 55/100
graphql-python/graphene#1593 ·
Tutte le issue di graphql-python/graphene
Issue simili
-
bug
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
stephrobert/dsoxlab#238 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
sublimehq/package_control#1780 ·
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 65/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 70/100
nwg-piotr/nwg-displays#145 ·