Skip to content

Instantly share code, notes, and snippets.

@hos
Last active February 23, 2021 16:22
Show Gist options
  • Save hos/a5d20ce53397c18037a572266458762b to your computer and use it in GitHub Desktop.
Save hos/a5d20ce53397c18037a572266458762b to your computer and use it in GitHub Desktop.
Postgraphile plugin to remove all mutation containing ByNodeId
import { omitBy } from "lodash";
import { Plugin } from "postgraphile";
export const RemoveByNodeIdPlugin: Plugin = (builder) => {
builder.hook("GraphQLObjectType:fields", (fields, _) => {
return omitBy(fields, (_, key) => key.endsWith?.("ByNodeId"));
});
};
export default RemoveByNodeIdPlugin;
import { Plugin } from "postgraphile";
export const RemoveByNodeIdPlugin: Plugin = (builder) => {
builder.hook("GraphQLObjectType:fields", (fields, _, { Self }) => {
if (Self.name !== "Mutation") {
return fields;
}
return Object.keys(fields).reduce((all, key) => {
if (!key.includes("ByNodeId")) {
return { ...all, [key]: fields[key] };
}
return all;
}, {});
});
};
export default RemoveByNodeIdPlugin;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment