我正在使用带有GraphQL的Strapi。我需要查询当前日期之后具有发布日期的文章。 其目的是允许编辑者发布将来的日期,以便他们可以提前计划。 现在我只有这个:
export const ARTICLES_QUERY = gql`
query Articles {
articles(where: { display: true }) {
id
slug
title
publish
display
time_to_read
article_categories {
slug
title
}
user {
username
name
}
cover {
url
}
}
}
`
我认为我需要这样的东西:
export const ARTICLES_QUERY = gql`
query Articles($today: String!) {
articles(where: { display: true, publish >= $today }) {
id
slug
...
该字符串的格式是Strapi输入日期时间的默认格式,结果是"publish": "2020-02-28T02:00:00.000Z"
我知道这不是要走的路,但这说明了我需要完成的事情。
答案 0 :(得分:2)
想通了。
GraphQL允许我们这样设置:
export const ARTICLES_QUERY = gql`
query Articles($today: String!) {
articles(where: { display: true, publish_lt: $today }) {
id
slug
...
在字段名称上使用_lt
或_gt
表示我们要过滤列表中设置日期(_lt)之前(_lt)或(_gt)之后的日期。