graphql-python / graphql-python/graphene-mongo

TypeError: How to resolve fields with ListField(GenericReferenceField())?

Aperta
#227 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub
Lingua principale
Python
Stelle
287
Fork
111
Metriche di merge delle PR
Nessuna PR unita negli ultimi 30g

Descrizione

I'm attempting to use `GenericReferenceField` or `GenericLazyReferenceField` fields in combination with `ListField`. However, it seems that the fields cannot be resolved correctly. I have the following model and graphene schema defined:

Model:
```
from mongoengine import ListField, Document, GenericReferenceField

class AndroidApp(Document):
...
generic_field_list = ListField(GenericReferenceField())
...
```

Schema:
```
import graphene
from graphene.relay import Node
from graphene_mongo import MongoengineObjectType
from graphql_jwt.decorators import superuser_required
from model import AndroidApp

class AndroidAppType(MongoengineObjectType):
class Meta:
model = AndroidApp
interfaces = (Node,)

class AndroidAppQuery(graphene.ObjectType):
android_app_list = graphene.List(AndroidAppType,
object_id_list=graphene.List(graphene.String),
name="android_app_list")

def resolve_android_app_list(self, info, object_id_list):
return AndroidApp.objects(pk__in=object_id_list)
```
Whenever I add the `ListField(GenericReferenceField())` the following stack trace occurs which says that the field cannot be resolved. A ListField in combination with `LazyReferenceField` works with the same model but not with the `GenericLazyReferenceField` or `GenericReferenceField` classes.

Stacktrace:
```
File "/usr/local/lib/python3.9/site-packages/graphene/types/schema.py", line 440, in __init__
self.graphql_schema = GraphQLSchema(
File "/usr/local/lib/python3.9/site-packages/graphql/type/schema.py", line 224, in __init__
collect_referenced_types(query)
File "/usr/local/lib/python3.9/site-packages/graphql/type/schema.py", line 433, in collect_referenced_types
collect_referenced_types(field.type)
File "/usr/local/lib/python3.9/site-packages/graphql/type/schema.py", line 433, in collect_referenced_types
collect_referenced_types(field.type)
File "/usr/local/lib/python3.9/site-packages/graphql/type/schema.py", line 432, in collect_referenced_types
for field in named_type.fields.values():
File "/usr/local/lib/python3.9/functools.py", line 993, in __get__
val = self.func(instance)
File "/usr/local/lib/python3.9/site-packages/graphql/type/definition.py", line 811, in fields
raise cls(f"{self.name} fields cannot be resolved. {error}") from error

TypeError: AndroidAppType fields cannot be resolved. Expected Graphene type, but received: .
```

What is the intended way of using `GenericReferenceField` with `ListField`? I guess according to #70 it should be supported to use the `GenericReferenceField`.

Guida per i contributori

Nessuna guida per i contributori indicizzata per questo repository

Direzione di ricerca

Inizia riproducendo lo schema AndroidAppType con ListField(GenericReferenceField()) e confrontalo con il caso funzionante di LazyReferenceField. Leggi il percorso di conversione dei campi di MongoengineObjectType e la gestione di GenericReferenceField. Il lavoro è completato quando lo schema viene costruito correttamente e l’elenco di riferimenti generici può essere esposto senza l’errore di risoluzione di NoneType.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Valutazione

Stack tecnologico
mongodb, python
Ambito
api, backend
Tipo di issue
Bug
Difficoltà
4/5
Tempo stimato
3-5 giorni
Stato di attività
Ferma
Chiarezza
Abbastanza chiara
Idoneità per principianti
35/100

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.