Skip to content

Conversation

pilsy
Copy link

@pilsy pilsy commented Aug 11, 2023

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

@benjie
Copy link
Member

benjie commented Jan 5, 2024

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:

and here:

if (Object.prototype.hasOwnProperty.call(args, "filter")) {
const sqlFragment = connectionFilterResolve(
args.filter,

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.

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

Successfully merging this pull request may close these issues.

2 participants