2

I want to fetch data of last one hour.

I have doubt how to add > && < in postgraphile?

if I add current_timestamp in double quotation still getting error.

Here is postgraphile screen.

enter image description here'hour in postgraphile

Radhe9254
  • 198
  • 1
  • 11

1 Answers1

4

You can read about filtering in the PostGraphile docs. To achieve what you've specified you could use the postgraphile-plugin-connection-filter plugin, and issue a query such as this:

query SessionsSince($timestamp: DateTime!) {
  allSessions(filter: {
    createdAt: { greaterThan: $timestamp }
    deviceid: { equalTo: "123" }
  }) {
    ...
  }
}

However, please keep in mind that a GraphQL API is not intended to expose all the functionality of your database to your users. Rather than exposing this raw interface, I'd personally use a custom query which would expose a much neater API; something like:

create function recent_sessions(deviceid text) returns setof sessions as $$
  select *
  from sessions
  where sessions.deviceid = recent_sessions.deviceid
  and created_at > NOW() - interval '1 hour';
$$ language sql stable;

You'd then query it like this:

{
  recentSessions(deviceid: "123") {
    nodes {
      deviceid
    }
  }
}
Benjie
  • 7,701
  • 5
  • 29
  • 44
  • 2020 update; an alternative approach is to add a custom condition via https://www.graphile.org/postgraphile/make-add-pg-table-condition-plugin/ – Benjie Aug 19 '20 at 15:31