我有一个 Node.js GraphQL 服务器。从客户端,我正在尝试使用如下查询获取所有用户条目:
{
user {
name
entries {
title
body
}
}
}
但是,在 Node.js GraphQL 服务器中,我想返回基于条目对象publishDate
和expiryDate
在条目对象中当前有效的用户条目。
例如:
{
"user": "john",
"entries": [
{
"title": "entry1",
"body": "body1",
"publishDate": "2019-02-12",
"expiryDate": "2019-02-13"
},
{
"title": "entry2",
"body": "body2",
"publishDate": "2019-02-13",
"expiryDate": "2019-03-01"
},
{
"title": "entry3",
"body": "body3",
"publishDate": "2020-01-01",
"expiryDate": "2020-01-31"
}
]
}
应该返回这个
{
"user": "john",
"entries": [
{
"title": "entry2",
"body": "body2",
"publishDate": "2019-02-13",
"expiryDate": "2019-03-01"
}
]
}
这entries
是通过delegateToSchema
调用(https://www.apollographql.com/docs/graphql-tools/schema-delegation.html#delegateToSchema)获取的,我没有将publishDate和expiryDate作为查询参数传递的选项。本质上,我需要得到结果,然后在内存中过滤它们。
publishDate
我面临的问题是原始查询没有expiryDate
支持这一点。有没有办法将这些字段添加到 delegateToSchema 调用中,然后在将它们发送回客户端时删除它们?