[英]Extending a GraphQL Filter Definition
I have extended my graphql schema to add a totals resolver, but I can't seem to extend the filter to filter on this field.我已经扩展了我的 graphql 架构以添加总计解析器,但我似乎无法扩展过滤器以过滤此字段。 I can't figure out what can be wrong as it seems very simple, so maybe it's not supported?
我不知道有什么问题,因为它看起来很简单,所以可能不支持? I am using Postgraphile with the makeExtendSchemaPlugin, but I believe the question is basic graphql syntax.
我正在使用带有 makeExtendSchemaPlugin 的 Postgraphile,但我相信问题是基本的 graphql 语法。
return {
typeDefs: gql`
extend type Note {
lines: Int
}
extend type NoteFilter {
lines: IntFilter
}
`,
resolvers: {
Note: {
resolve: async(parent, args, ctx, info) => {
// logic here
return parent['@lines'].data.length;
}
}
}
}
This seems so simple.这看起来很简单。 The count resolver works, and gives me how many lines are in the note, yet I am not able to filter on it.
计数解析器工作,并告诉我笔记中有多少行,但我无法对其进行过滤。 I don't want to put the filter logic in the lines property itself.
我不想将过滤器逻辑放在 lines 属性本身中。 If I define a new query and give it a NoteFilter, the filter exists but doesn't include my extended property (lines).
如果我定义一个新查询并给它一个 NoteFilter,过滤器存在但不包括我的扩展属性(行)。 Anyone know what I'm doing wrong?
有人知道我在做什么错吗? This is the end goal I would like for a query:
这是我想要查询的最终目标:
gql`
{
allNotes(filter: {
lines: {
greaterThan: 10
}
}) {
id
lines
line {
content
}
}
}
`
If you are extending an input object type, the correct syntax is:如果要扩展输入 object 类型,正确的语法是:
extend input NoteFilter {
lines: IntFilter
}
In SDL, input object types are denoted as input
, not type
.在 SDL 中,输入 object 类型表示为
input
,而不是type
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.