alit8
alit8

Reputation: 41

graphene_django DjangoFilterConnectionField - The type * doesn't have a connection

I have a problem with graphene_django. When I create a DjangoObjectType and pass this to DjangoFilterConnectionField in my Query, I get an AssertionError that The type {my DjangoObjectType class} doesn't have a connection.

Here is part of my code:

class TradeType(DjangoObjectType):
    class Meta:
        model = Trade
        filter_fields = {
            'id': ['exact', 'range', 'in', 'gte', 'lt'],
            'updated': ['gte', 'lt'],
            'created': ['gte', 'lt']
        }
        interface = (graphene.relay.Node,)

class Query(graphene.ObjectType):
    trades = DjangoFilterConnectionField(TradeType)

I did all of this based on this page.

Exception in thread django-main-thread:

Traceback (most recent call last):

File "/usr/local/lib/python3.8/threading.py", line 932, in
_bootstrap_inner

self.run()

File "/usr/local/lib/python3.8/threading.py", line 870, in run

self._target(*self._args, **self._kwargs)

File "/usr/local/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper

fn(*args, **kwargs)

File "/usr/local/lib/python3.8/site-packages/channels/management/commands/runserver.py", line 69, in inner_run

self.check(display_num_errors=True)

File "/usr/local/lib/python3.8/site-packages/django/core/management/base.py", line 419, in check

all_issues = checks.run_checks(

File "/usr/local/lib/python3.8/site-packages/django/core/checks/registry.py", line 76, in run_checks

new_errors = check(app_configs=app_configs, databases=databases)

File "/usr/local/lib/python3.8/site-packages/django/core/checks/urls.py", line 13, in check_url_config

return check_resolver(resolver)

File "/usr/local/lib/python3.8/site-packages/django/core/checks/urls.py", line 23, in check_resolver

return check_method()

File "/usr/local/lib/python3.8/site-packages/django/urls/resolvers.py", line 412, in check

for pattern in self.url_patterns:

File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__

res = instance.__dict__[self.name] = self.func(instance)

File "/usr/local/lib/python3.8/site-packages/django/urls/resolvers.py", line 598, in url_patterns

patterns = getattr(self.urlconf_module, "urlpatterns", self.urlconf_module)

File "/usr/local/lib/python3.8/site-packages/django/utils/functional.py", line 48, in __get__

res = instance.__dict__[self.name] = self.func(instance)

File "/usr/local/lib/python3.8/site-packages/django/urls/resolvers.py", line 591, in urlconf_module

return import_module(self.urlconf_name)

File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module

return _bootstrap._gcd_import(name[level:], package, level)

File "<frozen importlib._bootstrap>", line 1014, in _gcd_import

File "<frozen importlib._bootstrap>", line 991, in _find_and_load

File "<frozen importlib._bootstrap>", line 975, in
_find_and_load_unlocked

File "<frozen importlib._bootstrap>", line 671, in _load_unlocked

File "<frozen importlib._bootstrap_external>", line 783, in exec_module

File "<frozen importlib._bootstrap>", line 219, in
_call_with_frames_removed

File "/app/tabdeal/urls.py", line 45, in <module>

path('utils/', include('utils.urls')),

File "/usr/local/lib/python3.8/site-packages/django/urls/conf.py", line 34, in include

urlconf_module = import_module(urlconf_module)

File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module

return _bootstrap._gcd_import(name[level:], package, level)

File "<frozen importlib._bootstrap>", line 1014, in _gcd_import

File "<frozen importlib._bootstrap>", line 991, in _find_and_load

File "<frozen importlib._bootstrap>", line 975, in
_find_and_load_unlocked

File "<frozen importlib._bootstrap>", line 671, in _load_unlocked

File "<frozen importlib._bootstrap_external>", line 783, in exec_module

File "<frozen importlib._bootstrap>", line 219, in
_call_with_frames_removed

File "/app/utils/urls.py", line 6, in <module>

from utils.schema import schema

File "/app/utils/schema.py", line 200, in <module>

schema = graphene.Schema(query=Query)

File "/usr/local/lib/python3.8/site-packages/graphene/types/schema.py", line 78, in __init__

self.build_typemap()

File "/usr/local/lib/python3.8/site-packages/graphene/types/schema.py", line 167, in build_typemap

self._type_map = TypeMap(

File "/usr/local/lib/python3.8/site-packages/graphene/types/typemap.py", line 80, in __init__

super(TypeMap, self).__init__(types)

File "/usr/local/lib/python3.8/site-packages/graphql/type/typemap.py", line 31, in __init__

self.update(reduce(self.reducer, types, OrderedDict())) # type: ignore

File "/usr/local/lib/python3.8/site-packages/graphene/types/typemap.py", line 88, in reducer

return self.graphene_reducer(map, type)

File "/usr/local/lib/python3.8/site-packages/graphene/types/typemap.py", line 117, in graphene_reducer

return GraphQLTypeMap.reducer(map, internal_type)

File "/usr/local/lib/python3.8/site-packages/graphql/type/typemap.py", line 109, in reducer

field_map = type_.fields

File "/usr/local/lib/python3.8/site-packages/graphql/pyutils/cached_property.py", line 22, in __get__

value = obj.__dict__[self.func.__name__] = self.func(obj)

File "/usr/local/lib/python3.8/site-packages/graphql/type/definition.py", line 198, in fields

return define_field_map(self, self._fields)

File "/usr/local/lib/python3.8/site-packages/graphql/type/definition.py", line 212, in define_field_map

field_map = field_map()

File "/usr/local/lib/python3.8/site-packages/graphene/types/typemap.py", line 275, in construct_fields_for_type

map = self.reducer(map, field.type)

File "/usr/local/lib/python3.8/site-packages/graphene_django/fields.py", line 98, in type

assert _type._meta.connection, "The type {} doesn't have a connection".format(

AssertionError: The type TradeType doesn't have a connection

graphene==2.1.9, graphene_django==2.15, django-filter==2.4

Upvotes: 0

Views: 1117

Answers (1)

Jerven Clark
Jerven Clark

Reputation: 1219

I think the issue is it can't find what interface to use because you mistype interfaces in the Meta class as interface.

class TradeType(DjangoObjectType):
    class Meta:
        ...
        interfaces = (graphene.relay.Node,)

Upvotes: 1

Related Questions