Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
7homasSutter opened this issue Dec 5, 2023 · 0 comments

Comments

@7homasSutter
Copy link

7homasSutter commented Dec 5, 2023

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: <class 'NoneType'>.

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant