Skip to content

brandondoran/graphql-directive-deprecated

Repository files navigation

Build Status Coverage Status dependencies Status devDependencies Status peerDependencies Status semantic-release Dependabot Status

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
  }
});

About

A GraphQL directive for deprecating fields in a schema

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •