I used both "DjangoListField()" and "graphene.List()" with the Resolver to list all objects.
"DjangoListField()" in schema.py:
import graphene
from graphene_django import DjangoObjectType
from graphene_django import DjangoListField
from .models import Category
class CategoryType(DjangoObjectType):
class Meta:
model = Category
fields = ("id","name")
class Query(graphene.ObjectType):
all_categories = DjangoListField(CategoryType) # DjangoListField()
def resolve_all_categories(root, info): # Resolver to list all objects
return Category.objects.all()
schema = graphene.Schema(query=Query)
"graphene.List()" in schema.py:
import graphene
from graphene_django import DjangoObjectType
from .models import Category
class CategoryType(DjangoObjectType):
class Meta:
model = Category
fields = ("id","name")
class Query(graphene.ObjectType):
all_categories = graphene.List(CategoryType) # graphene.List()
def resolve_all_categories(root, info): # Resolver to list all objects
return Category.objects.all()
schema = graphene.Schema(query=Query)
Then, I queried "allCategories" for both code in schema.py above one by one:
query {
allCategories {
id
name
}
}
But the result is the same to list all objects:
{
"data": {
"allCategories": [
{
"id": "1",
"name": "category1"
},
{
"id": "2",
"name": "category2"
}
]
}
}
What is the difference between "DjangoListField()" and "graphene.List()"?