Closed madtibo closed 2 years ago
Thanks for the PR @madtibo !
In the interest of minimizing the scope of this plugin, would you be willing to use a small standalone plugin like this instead?
import type { Plugin } from "graphile-build";
import { Build } from "postgraphile-core";
import { AddConnectionFilterOperator } from "postgraphile-plugin-connection-filter/dist/PgConnectionArgFilterPlugin";
const UnaccentPlugin: Plugin = (builder) => {
builder.hook("build", (_, build) => {
const {
pgSql: sql,
graphql: { GraphQLString },
addConnectionFilterOperator,
escapeLikeWildcards,
} = build as Build & {
addConnectionFilterOperator: AddConnectionFilterOperator;
escapeLikeWildcards: any;
};
addConnectionFilterOperator(
"String",
"includesUnaccentInsensitive",
"Contains the specified string (unaccented case-insensitive).",
() => GraphQLString,
(i, v) => sql.query`UNACCENT(${i}) ILIKE UNACCENT(${v})`,
{
resolveInput: (input) => `%${escapeLikeWildcards(input)}%`,
resolveSqlIdentifier: (i) => i,
}
);
// continue adding other operators here
return _;
});
};
export default UnaccentPlugin;
I really need to properly document addConnectionFilterOperator
in the README. :relaxed: The API isn't ideal, but it's been out there long enough now that I might as well promote it and encourage others to extend this plugin as needed.
In the interest of minimizing the scope of this plugin, would you be willing to use a small standalone plugin like this instead?
It is not nice to force the use of the UNACCENT extension. So this is a very good idea. I will look into it.
In the interest of minimizing the scope of this plugin, would you be willing to use a small standalone plugin like this instead?
@mattbretl I created a new project for this plugin: postgraphile-plugin-unaccented-search-filter.
I am not fluent in Javascript and I am not sure what should be done to make it a valid package. Could you give me a hand?
This PR adds 4 new operators:
includesUnaccentInsensitive
: Contains the specified string (unaccented case-insensitive).notIncludesUnaccentInsensitive
: Does not contain the specified string (unaccented case-insensitive).likeUnaccentInsensitive
: Matches the specified pattern (unaccented case-insensitive).notLikeUnaccentInsensitive
: Does not match the specified pattern (unaccented case-insensitive).@mattbretl do you think it is possible to add these operators?