Expand my Community achievements bar.

July 31st AEM Gems Webinar: Elevate your AEM development to master the integration of private GitHub repositories within AEM Cloud Manager.
SOLVED

AEM Cloud: Headless query to graphQL with date filter (not less that current day)

Avatar

Level 2

Hi,

Can I create a query in graphql, persisted, where I can ask for a date greater than if equal to today?

 

We have CFs that have dates that sometimes go older than today, and we want to filter them out in a graphQL query.

 

Is this possible?

 

Thanks

Joel

1 Accepted Solution

Avatar

Correct answer by
Level 2

Meant to reply. Yes took some digging. Got this to work

 

lastDate: {
      _logOp: OR
      _expressions: [{
        _operator: AT_OR_AFTER
        value: $today
      },
        {
        _operator: AT
        value: null
      },
      ]
    }

 

 

 

 

View solution in original post

3 Replies

Avatar

Level 2

I see docs on graphql that talk about using resolvers to provide better queries.

https://graphql.org/learn/execution/

 

I don't think graphql is the best for our purposes. I am considering a totally different DB that provides SQL, Non-relational, or  querying the JCR directly from Java.

 

Problem is we want part of the query to be specified from auth/dialog. JCR query may be the way to go.

 

So in auth they would specify (for ex) Event name, startDate, which would be stored in content fragments, and we want to query Events starting after today.

 

Suggestions welcome.

Avatar

Level 7

I think you should be able to use the date filter. Are there any challenges which you are facing ? 
Assuming you have a content fragment that has a field eventDate of type Calendar, you should be able to create a query to filter on that. Something like :

query eventByDate($eventStartDate: Date) {
  eventList(
    filter: {eventDate: {_expressions: [{value: $eventStartDate, _operator: AFTER}]}}
  ) {
    items {     
      eventDate
    }
  }
}

And while calling this, just pass today's date

{"eventStartDate": "2023-06-19"}

Hope this helps

Avatar

Correct answer by
Level 2

Meant to reply. Yes took some digging. Got this to work

 

lastDate: {
      _logOp: OR
      _expressions: [{
        _operator: AT_OR_AFTER
        value: $today
      },
        {
        _operator: AT
        value: null
      },
      ]
    }