sinned
sinned

Reputation: 738

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.

Upvotes: 4

Views: 3767

Answers (1)

Uziel Valdez
Uziel Valdez

Reputation: 2280

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

Upvotes: 1

Related Questions