我的解析器
{ adminMsg:
[
{active: “y”, text1: “blah1" } ,
{active: “n”, text1: “blah2" }
] };
我的查询:
{
adminWarn {
adminMsg {
active, text1
}
}
}
我只想要带有条件的数组元素:active ='y'
我在GQL Dokumentation中找不到在我的查询中写这个条件的方法。 GQL中有解决方案吗?
答案 0 :(得分:1)
使用resolve args可以解决问题:
const adminWarnList = new GraphQLObjectType({
name: 'adminWarnReportList',
fields: () => ({
adminMsg: {
type: new GraphQLList(adminWarnFields),
},
}),
});
const adminWarn = {
type: adminWarnList,
args: {
active: { type: GraphQLString },
},
resolve: (parent, args, context) => {
...
let reportdata = context.loadData();
if (args.active == 'y') {
let filteredItems = reportdata.filter(function(item) {
return item.active != null && item.active != 'y';
});
reportdata = filteredItems;
}
return { adminMsg: reportdata };
},
};