Created
August 13, 2020 18:38
-
-
Save benjie/4ca989e0420b7ff217f89159ccf4f2c8 to your computer and use it in GitHub Desktop.
Deprecate all fields that reference a named output type in Graphile Engine
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 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