testcoder101
testcoder101

Reputation: 33

How to graphql after a certain date in contentful?

I'm using Contentful's GraphQL API. What I want to do is to query all the events that haven't past yet.

I tried using lt, but that doesn't seem to be working. I also found out that the date is a string, so what options do I have?

eventCollection(where: {eventEndDate: {lt: "2022-10-27T00:00:00.000-06:00"}}){
    items {
      slug
      eventEndDate
    }
  }

A normal query (without the where condition) gives you:

"eventCollection": {
      "items": [
        {
          "slug": "black-friday",
          "eventEndDate": "2022-11-27T12:00:00.000-07:00"
        }
      ]
    }

Upvotes: 0

Views: 1248

Answers (1)

stefan judis
stefan judis

Reputation: 3879

You should have an eventEndDate_gte filter available. On every field, there will be type dependent filter available. It's best to use GraphiQL or the GraphQL Playground to discover available filter options.

The following filter works fine for my space.

query {
  tilPostCollection(where: {date_gte: "2022-09-05T00:00:00.000+02:00"}) {
    items {
      title
      date
    }
  }
}

Upvotes: 0

Related Questions