Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Trigram support? #175

Open
theogravity opened this issue Feb 13, 2022 · 2 comments
Open

Trigram support? #175

theogravity opened this issue Feb 13, 2022 · 2 comments

Comments

@theogravity
Copy link

theogravity commented Feb 13, 2022

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}`,
      },
@theogravity
Copy link
Author

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

@mattbretl
Copy link
Member

(Sorry for the delayed response!)

Glad you were able to find a solution! ☺️

In case anyone else comes across this, you can probably achieve something similar on filter with the addConnectionFilterOperator method exported from this plugin. See #173 (comment) and https://github.com/graphile-contrib/postgraphile-plugin-connection-filter-postgis for examples.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants