【发布时间】:2021-02-28 06:05:04
【问题描述】:
我正在尝试使用 graphene-django 进行简单查询,但我无法获取数据库,它给了我 null。
我认为代码没问题,出了什么问题,我为此工作了几个小时。
你知道它是什么吗?
提前致谢
import graphene
from graphene_django.types import DjangoObjectType, ObjectType
from myProject.models import Times
class TimesType(DjangoObjectType):
class Meta:
model=Times
fields="__all__"
class Query(ObjectType):
today_times = graphene.Field(TimesType, id=graphene.ID())
all_times = graphene.List(TimesType)
def resolve_todaytimes(self, info, id=None):
return Times.objects.get(pk=id)
def resolve_alltimes(root, info, **kwargs):
return Times.objects.all()
schema = graphene.Schema(query=Query, mutation=Mutation)
query {todayTimes(id:"1029"){id}}
{
"data": {
"todayTimes": null
}
}
【问题讨论】: