Graphql-engine: Add date operators (particularly Extract function)

Created on 1 Apr 2019  路  5Comments  路  Source: hasura/graphql-engine

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.

server longterm

Most helpful comment

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

All 5 comments

@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
  }
}
Was this page helpful?
0 / 5 - 0 ratings

Related issues

stereobooster picture stereobooster  路  3Comments

bogdansoare picture bogdansoare  路  3Comments

anisjonischkeit picture anisjonischkeit  路  3Comments

marionschleifer picture marionschleifer  路  3Comments

jjangga0214 picture jjangga0214  路  3Comments