Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sql-server/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
按日期时间筛选GraphQL项目_Graphql_Strapi - Fatal编程技术网

按日期时间筛选GraphQL项目

按日期时间筛选GraphQL项目,graphql,strapi,Graphql,Strapi,我正在使用Strapi和GraphQL。我需要查询发布日期晚于当前日期的文章。 这背后的意图是允许编辑在未来的日期发布,以便他们可以提前计划。 现在我只有这个: export const ARTICLES_QUERY = gql` query Articles { articles(where: { display: true }) { id slug title publish display time_to_

我正在使用Strapi和GraphQL。我需要查询发布日期晚于当前日期的文章。 这背后的意图是允许编辑在未来的日期发布,以便他们可以提前计划。 现在我只有这个:

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默认的日期-时间输入格式,结果是“发布”:“2020-02-28T02:00:00.000Z”

我知道这不是我要走的路,但它说明了我需要完成的事情。

找到了答案

GraphQL允许我们这样设置:

export const ARTICLES_QUERY = gql`
  query Articles($today: String!) {
    articles(where: { display: true, publish_lt: $today }) {
      id
      slug
...
在字段名上使用
\u lt
\u gt
表示我们要在列表中筛选设置日期之前(\u lt)或之后(\u gt)的日期