Search code examples
pythondjangographqlgraphene-python

Create graphene-django interface from models


I'm using graphene-django and i want to create four Interfaces, each representing models in Django, i'll start with only one model:

class TestInterface(graphene.Interface):
    items = graphene.Field(models.Test)

But i keep getting this error:

AttributeError: type object 'Test' has no attribute 'name'

Any ideas?


Solution

  • The argument to graphene.Field should be a class that inherits from DjangoObjectType and not a Django model, e.g.

    class TestType(DjangoObjectType):
    
        class Meta:
            model = Test