【发布时间】:2019-06-10 14:59:43
【问题描述】:
我正在尝试使用 Django 和 Graphene 执行 GraphQL 查询。要使用 id 查询单个对象,我执行了以下操作:
{
samples(id:"U2FtcGxlU2V0VHlwZToxMjYw") {
edges {
nodes {
name
}
}
}
}
而且效果很好。当我尝试使用多个 id 进行查询时会出现问题,如下所示:
{
samples(id_In:"U2FtcGxlU2V0VHlwZToxMjYw, U2FtcGxlU2V0VHlwZToxMjYx") {
edges {
nodes {
name
}
}
}
}
在后一种情况下,我收到以下错误:
argument should be a bytes-like object or ASCII string, not 'list'
这是django-graphene中如何定义类型和查询的草图
class SampleType(DjangoObjectType):
class Meta:
model = Sample
filter_fields = {
'id': ['exact', 'in'],
}
interfaces = (graphene.relay.Node,)
class Query(object):
samples = DjangoFilterConnectionField(SampleType)
def resolve_sample_sets(self, info, **kwargs):
return Sample.objects.all()
【问题讨论】:
-
首先,您需要使用列表字段扩展
SampleType——类似于ids = graphene.List(graphene.ID()) -
@MarkChackerian 你能详细说明一下并提供解决方案吗?我遇到了同样的问题,看不到添加 ids 字段如何改变任何东西。似乎 graphene-django 在输入字段中有一些输入验证问题?
标签: django-filter graphene-python graphql-python