Closed Brookke closed 8 months ago
Hey @mattbretl I've opened this PR, to address #203. Normally I would would wait for sign off on the proposal before hand. But, given I had already written the code when testing this locally, I thought I would open a PR with the change since it was fairly small. Would love to get a review when you get a moment :)
This can also be achieved via a plugin:
In V4:
import { makeAddInflectorsPlugin } from "graphile-utils";
export const PrefixFilterPlugin = makeAddInflectorsPlugin(
(inflectors, build, options) => {
const {
filterType: oldFilterType,
filterFieldType: oldFilterFieldType,
filterFieldListType: oldFilterFieldListType,
} = inflectors;
const { connectionFilterTypePrefix = "" } = options;
return {
filterType(typeName) {
return connectionFilterTypePrefix + oldFilterType.call(this, typeName);
},
filterFieldType(typeName) {
return (
connectionFilterTypePrefix + oldFilterFieldType.call(this, typeName)
);
},
filterFieldListType(typeName) {
return (
connectionFilterTypePrefix +
oldFilterFieldListType.call(this, typeName)
);
},
};
},
true,
);
And of course, It's Better In V5™️:
function prefix(prev, preset, typeName) {
const { schema: { connectionFilterTypePrefix = "" } } = preset;
return connectionFilterTypePrefix + prev(typeName);
}
export const PrefixFilterPlugin = {
name: "PrefixFilterPlugin",
inflection: {
replace: {
filterType: prefix,
filterFieldType: prefix,
filterFieldListType: prefix,
},
},
};
This can also be achieved via a plugin:
In V4:
import { makeAddInflectorsPlugin } from "graphile-utils"; export const PrefixFilterPlugin = makeAddInflectorsPlugin( (inflectors, build, options) => { const { filterType: oldFilterType, filterFieldType: oldFilterFieldType, filterFieldListType: oldFilterFieldListType, } = inflectors; const { connectionFilterTypePrefix = "" } = options; return { filterType(typeName) { return connectionFilterTypePrefix + oldFilterType.call(this, typeName); }, filterFieldType(typeName) { return ( connectionFilterTypePrefix + oldFilterFieldType.call(this, typeName) ); }, filterFieldListType(typeName) { return ( connectionFilterTypePrefix + oldFilterFieldListType.call(this, typeName) ); }, }; }, true, );
And of course, It's Better In V5™️:
function prefix(prev, preset, typeName) { const { schema: { connectionFilterTypePrefix = "" } } = preset; return connectionFilterTypePrefix + prev(typeName); } export const PrefixFilterPlugin = { name: "PrefixFilterPlugin", inflection: { replace: { filterType: prefix, filterFieldType: prefix, filterFieldListType: prefix, }, }, };
Thanks for this @benjie this will unlock us. I will leave this PR open for now as I think that the ergonomics of this PR are nicer, but understand if it gets closed in favour of suggesting people write a custom plugin
Since there has been little interest in this and the workaround is straightforward I'm going to go ahead and close this. Thanks for submitting it though, @Brookke!
Solves #203