Last active
February 23, 2021 16:22
-
-
Save hos/a5d20ce53397c18037a572266458762b to your computer and use it in GitHub Desktop.
Postgraphile plugin to remove all mutation containing ByNodeId
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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