postgraphile-plugin-connection-filter icon indicating copy to clipboard operation
postgraphile-plugin-connection-filter copied to clipboard

Custom filter name via connectionFilterName

Open pilsy opened this issue 1 year ago • 1 comments

Where i work we wanted the ability to name the filter "where", so while we migrate from Hasura our queries will not change -- this PR adds this feature via connectionFilterName option

pilsy avatar Aug 11 '23 10:08 pilsy

This need is better served by a small inflection plugin:

import { makeAddInflectorsPlugin } from "graphile-utils";

export const FilterToWherePlugin = makeAddInflectorsPlugin(() => ({
  filterType(typeName: string) {
    return `${typeName}Where`;
  },
  filterFieldType(typeName: string) {
    return `${typeName}Where`;
  },
  filterFieldListType(typeName: string) {
    return `${typeName}ListWhere`;
  },
  filterArgumentName() {
    return "where";
  }
});

The only change needed for this would be adding the new filterArgumentName inflector and then doing:

const filterArgumentName = inflection.filterArgumentName();

and using that variable in the place of filter here:

https://github.com/graphile-contrib/postgraphile-plugin-connection-filter/blob/fcd5e920c50604063c5db9bc28c557bd69bcfdcc/src/PgConnectionArgFilterPlugin.ts#L127

and here:

https://github.com/graphile-contrib/postgraphile-plugin-connection-filter/blob/fcd5e920c50604063c5db9bc28c557bd69bcfdcc/src/PgConnectionArgFilterPlugin.ts#L107-L109

Many of the changes made in this PR are undesirable; for example changing the smart tag from @omit filter to @omit <someVariable> is likely to cause a lot of pain for other plugins. If you want to simplify this PR down to only the few lines mentioned above then I'd definitely consider it.

benjie avatar Jan 05 '24 16:01 benjie