GraphQL 查询使用嵌套对象字段进行过滤
我刚刚开始学习.net core中的graphql和HotChocolate.Data。 我使用属性 [UseFiltering] 如何使用嵌套对象字段来过滤表中的行并过滤嵌套对象?
query GetData(
$search: String
) {
documents(
where: {
name: { contains: $search }
}
) {
total: totalCount
items {
id
name
requirements(
where: {
name: { contains: $search }
}
)
{
id
name
}
}
}
}
按文档过滤工作正常,但如果我尝试按要求连接过滤,则会出现错误 生成期间出错:字段“Document.requirements”上的未知参数“where”。
I just started to learn graphql and HotChocolate.Data in .net core.
I usind attribute [UseFiltering]
How do I use nested objects` fields to filter rows from a table and also filter the nested objects as well?
query GetData(
$search: String
) {
documents(
where: {
name: { contains: $search }
}
) {
total: totalCount
items {
id
name
requirements(
where: {
name: { contains: $search }
}
)
{
id
name
}
}
}
}
Filtering by documents works fine, but if I try to connect the filtering by requirements I get errors
Error during generation: Unknown argument "where" on field "Document.requirements".
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
为此,您需要告诉 HotChocolate 您要在该字段上进行过滤。 正如克里斯在评论中所说,您可以使用使用
[UseFiltering]
注释来执行此操作或者,您可以使用代码优先方法:
在
Item
类型中,您应该将UseFiltering()
添加到Requirements
字段:In order to do this you need to tell HotChocolate that you want to filter on that field. As Chris says in his comment, you can use annotation to do this with
[UseFiltering]
Alternatively, you can use a code-first approach:
In your
Item
type, you should addUseFiltering()
to theRequirements
field: