Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GraphQL query filter by current timestamp

I'm wondering what would be a nice solution to filter GraphQL queries by the current timestamp, e.g:

query {
  appointments(createdAt: today) { }
}

or

query {
  appointments(createdAt_gte: now) { }
}

Is it recommended to create my own resolver functions here? How would they look like, when e.g. graph.cool is used as a backend?

I don't want to rely on the correct time of the client but use the server time instead.

like image 994
sinned Avatar asked Sep 08 '26 08:09

sinned


1 Answers

If you don't want to rely on the client side for the date, you can send a paramater on your query i.e.

query {
  appointments(latestsOnly: true) { }
}

and resolve that paramater to the current date in the backend

like image 69
Uziel Valdez Avatar answered Sep 10 '26 00:09

Uziel Valdez