graphql-directive-deprecated
v3.0.0
Published
A GraphQL schema directive for deprecating fields
Downloads
105
Maintainers
Readme
When writing a GraphQL schema with the Schema Definition Language, some flexibility, such as
adding a deprecationReason
to a field is lost. This package implements a custom directive
to make it possible to deprecate a field or enum. This is intended for use in Apollo Server that builds the schema with graphql-tools. See the Apollo graphql-tools docs for more information on schema directives.
Usage
npm install graphql-directive-deprecated
Example
import { makeExecutableSchema } from 'graphql-tools';
import { DeprecatedDirective } from 'graphql-directive-deprecated';
const typeDefs = `
directive @deprecated(
reason: String = "No longer supported"
) on FIELD_DEFINITION | ENUM_VALUE
type ExampleType {
newField: String
oldField: String @deprecated(reason: "Use newField.")
}
`;
const schema = makeExecutableSchema({
typeDefs,
schemaDirectives: {
deprecated: DeprecatedDirective
}
});