Applying type cast with a filter
SlashKirill opened this issue · 2 comments
Hi Matt,
thanks for the great plugin. I was wondering if it's possible to add type cast option into the filter. In our project, we think to store different types of values as text/varchar in the single table and if some advanced filtering would be required, we would need to use type casting for queries to work. For example:
select * from object_properties where value < 0
would generate the error, because value is of varchar type. But if we apply casting, it will work fine (apparently assuming that values stored in the table can be converted to real):
select * from object_properties where value::real <0
So GraphQL query with plugin-connection-filter would not work for us out of the box. What we need is the ability to specify "cast" option within the filter explicitly to compose proper SQL queries.
Just wanted to get your opinion on this feature.
Hey @SlashKirill, I'm not sure if this is still relevant given how much time has passed, but if so.. I'd suggest writing a small plugin that uses the addConnectionFilterOperator method on the build
object. One example of this approach would be the PostGIS filter plugin: https://github.com/graphile-contrib/postgraphile-plugin-connection-filter-postgis/blob/master/src/PgConnectionArgFilterPostgisOperatorsPlugin.js, though yours would end up much simpler than that. If you're still struggling with this, let me know and I'll put together a more concise example.
Closing this as stale, but please reach out if this is still an issue! 🙏