AEM Cloud: Headless query to graphQL with date filter (not less that current day) | Community
Skip to main content
Level 2
May 23, 2024
Solved

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

  • May 23, 2024
  • 2 replies
  • 1431 views

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

This post is no longer active and is closed to new replies. Need help? Start a new post to ask your question.
Best answer by joel_at_verb

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 }, ] }

 

 

 

 

2 replies

Level 2
May 26, 2024

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.

h_kataria
Community Advisor
Community Advisor
June 19, 2024

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

joel_at_verbAuthorAccepted solution
Level 2
June 19, 2024

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 }, ] }