postgraphile-plugin-connection-filter
postgraphile-plugin-connection-filter copied to clipboard
Trigram support?
Would it be difficult to support for the operators here?
https://www.postgresql.org/docs/14/pgtrgm.html
Would it be as simple as adding in something like:
similarityGreaterThan: {
description: "Value has a similarity that is greater than the current similarity threshold set by pg_trgm.similarity_threshold.",
resolve: (i, v) => sql.query`${i} % ${v}`,
},
If anyone wants to know how to do this, you can actually create your own plugin easily using makeAddPgTableConditionPlugin
from 'graphile-utils':
https://www.graphile.org/postgraphile/make-add-pg-table-condition-plugin/
import { makeAddPgTableConditionPlugin } from 'graphile-utils'
const cardNameSearch = makeAddPgTableConditionPlugin(
'public',
'cards',
'cardNameSearch',
(build) => {
const { GraphQLList, GraphQLString } = build.graphql
return {
description:
'Value has a similarity that is greater than the current similarity threshold set by pg_trgm.similarity_threshold.',
type: new GraphQLList(GraphQLString),
}
},
(value, helpers, build) => {
const { sql, sqlTableAlias } = helpers
return sql.fragment`${sqlTableAlias}.name %> (${sql.value(value)}::text)`
},
)
export default cardNameSearch
(Sorry for the delayed response!)
Glad you were able to find a solution! :relaxed:
In case anyone else comes across this, you can probably achieve something similar on filter
with the addConnectionFilterOperator
method exported from this plugin. See https://github.com/graphile-contrib/postgraphile-plugin-connection-filter/pull/173#issuecomment-1000945085 and https://github.com/graphile-contrib/postgraphile-plugin-connection-filter-postgis for examples.