Skip to content

Instantly share code, notes, and snippets.

@benjie
Created August 13, 2020 18:38
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save benjie/4ca989e0420b7ff217f89159ccf4f2c8 to your computer and use it in GitHub Desktop.
Save benjie/4ca989e0420b7ff217f89159ccf4f2c8 to your computer and use it in GitHub Desktop.
Deprecate all fields that reference a named output type in Graphile Engine
import type { Plugin } from "graphile-build";
const makeDeprecateTypePlugin = (typeName: string, deprecationReason: string): Plugin => builder => {
builder.hook('GraphQLObjectType:fields:field', (field, { graphql }) => {
if (graphql.getNamedType(field.type).name !== typeName) {
return field;
}
return {
...field,
deprecationReason,
}
});
}
// Usage:
// appendPlugins: [makeDeprecateTypePlugin('TypeToDeprecate', 'Use OtherType instead')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment