按日期时间过滤 GraphQL 文章

Joã*_*elo 3 graphql strapi

我将 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
      }
    }
  }
`
Run Code Online (Sandbox Code Playgroud)

我想我需要这样的东西:

export const ARTICLES_QUERY = gql`
  query Articles($today: String!) {
    articles(where: { display: true, publish >= $today }) {
      id
      slug
...
Run Code Online (Sandbox Code Playgroud)

该字符串的格式是 Strapi 对于日期时间输入的默认格式,结果为"publish": "2020-02-28T02:00:00.000Z"

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

Joã*_*elo 5

弄清楚了。

GraphQL 允许我们这样设置:

export const ARTICLES_QUERY = gql`
  query Articles($today: String!) {
    articles(where: { display: true, publish_lt: $today }) {
      id
      slug
...
Run Code Online (Sandbox Code Playgroud)

在字段名称上使用_lt_gt表示我们要过滤列表以查找设置日期之前 (_lt) 或之后 (_gt) 的日期。