无法查询 GraphQL 中的外键字段
Cannot query foreign key field in GraphQL
我正在为 GraphQL 使用 graphene-django 框架。
除了外键
我可以检索的所有字段
# models.py
from django.db import models
from django.contrib.auth.models import User
from users.models import UserProfile
class Video(models.Model):
title = models.TextField()
description = models.TextField()
author = models.ForeignKey(User, on_delete=models.CASCADE)
# schema.py
class VideoType(DjangoObjectType):
class Meta:
model = Video
我的查询是这样的
query {
home_videos {
title
description
author
}
}
以下是 GraphQLView 中的错误消息。
Cannot query field author on type VideoType
我添加了 UserType 并更改了模型 foreignKey 类型
class UserType(DjangoObjectType):
class Meta:
model = UserProfile
author = models.ForeignKey(UserProfile, on_delete=models.CASCADE)
我正在为 GraphQL 使用 graphene-django 框架。 除了外键
我可以检索的所有字段# models.py
from django.db import models
from django.contrib.auth.models import User
from users.models import UserProfile
class Video(models.Model):
title = models.TextField()
description = models.TextField()
author = models.ForeignKey(User, on_delete=models.CASCADE)
# schema.py
class VideoType(DjangoObjectType):
class Meta:
model = Video
我的查询是这样的
query {
home_videos {
title
description
author
}
}
以下是 GraphQLView 中的错误消息。
Cannot query field author on type VideoType
我添加了 UserType 并更改了模型 foreignKey 类型
class UserType(DjangoObjectType):
class Meta:
model = UserProfile
author = models.ForeignKey(UserProfile, on_delete=models.CASCADE)