graphql-engine
graphql-engine copied to clipboard
Add date operators (particularly Extract function)
For now I am filtering all my data in the client but datasets are growing so, I really need something like this: https://www.postgresql.org/docs/11/functions-datetime.html#FUNCTIONS-DATETIME-EXTRACT
It will help me to do all the hard work in server side and not downloading the whole dataset.
@florent1933 For now you can create a view with the extracted component. If we support this at graphql-engine how do you expect the api to be?
@0x777 , thanks for your answer.
My usecase is a query like: get all datas between dateA and dateB (year/month/day granularity).
I don't know enough of graphQl to suggest you an API.
I am not sure if the following is what you needed, but I'll write down what is possible currently. (It is not the extract function from postgres)
You can do the following:
query {
article(
where: {
_and: [
{created_at: {_gt: "2019-01-01"}},
{created_at: {_lt: "2019-04-10"}}
]
}
) {
title
content
created_at
}
}
Assuming there is an article table with title, content and created_at fields.
Is this what you are looking for?
Yeah, that's perfect. That's what I planned to do 🙂
Any news on this?
About how the api could look, something like this comes to mind.
query test {
todos(where: {
created_at: { _extract: "month", _eq: 12 }
}) {
id
created_at
}
}
or maybe something like this is better
query test {
todos(where: {
created_at: [
{ _extract: "month" },
{ _eq: 12 }
]
}) {
id
created_at
}
}
.
+1