首页 > 解决方案 > Is it possible to show only posts with dates older than yesterday

问题描述

as the topic says.

I was hoping this could be done w graphql. The documentation shows there's a lt and gt operator, but when I try this locally or the graphiql demo, I get an error, saying the operator is not available...

index.js:

export const IndexPageQuery = graphql`
  query {
    allEventsJson
      #here I was hoping to filter all past events
      #(filter: { date:{ gte: { today }}})
      #but gte is not accepted and I'm unsure how to set today's date in 
      #the query (iso8601 date through a JS variable was not accepted)
    {
      edges {
        node {
          id
          title
          date(formatString: "DD-MM-YYYY")
          month: date(formatString: "MMM")
          day: date(formatString: "DD")
          year: date(formatString: "YYYY")
        }
      }
    }
  }
`

I have a repository with a demo here

标签: javascriptreactjsgatsby

解决方案


推荐阅读