graphqlpostgraphqlpostgraphile

Filtering results in GraphQL using PostGraphile


I'm trying to wrap my head around GraphQL and I though using PostGraphile to easily and quickly map my PostgreSQL database and expose it using GraphQL. However, I've been stuck a long time on some things that in simple SQL would be a matter of minutes to do -

First, I'm trying to get all records from my database after a defined date, couldn't do this so far, and I end up getting all records which is highly inefficient.

Second, I'd like to get all records which a nullable field in them isn't null (meaning, only if it has something in it, it will show up in the GraphQL results)

If anyone could shed some light on how to do this, or point me to a good tutorial that explains in a simple way how to write custom filtering functions that would be great.


Solution

  • PostGraphile has a small but growing list of community plugins; for your needs you probably want postgraphile-plugin-connection-filter which adds a number of filters to PostGraphile connections that you'd expect (less than, greater than, in a list, not in a list, and/or/not, like, contains, etc). It's also possible to implement your own plugins, or to achieve this goal via custom queries.