apollo-deprecated-highlight
TypeScript icon, indicating that this package has built-in type declarations

1.1.15 • Public • Published

apollo deprecated highlight

circleci codecov Known Vulnerabilities

Highlight the apollo graphql deprecated fields.

We know that even you mark a field in apollo-server as @deprecated the client-side won't be able to know it until execute introspection queries. This package is for showing the deprecations in the response so that the engineers can know which fields are deprecated when they are developing.

NOTE: This package is only for apollo 4. If you are using apollo 3 please use apollo3-deprecated-highlight

How to use

import { ApolloDeprecatedHighlight } from 'apollo-deprecated-highlight';

// add ApolloDeprecatedHighlight() as plugin
const server = new ApolloServer({
    typeDefs,
    resolvers,
    plugins: [ApolloDeprecatedHighlight()],
    ...
});

Then it will add deprecations to extensions of graphql respons. The response format will be

{
    "data": {...},
    "extensions": {
        "deprecations": [
            <deprecation1>,
            <deprecation2>,
            ...
        ]
    }
}

Example

Here is the example project

We mark title, author and make as deprecated fields in the schema

type Book {
    title: String @deprecated(reason:"title is deprecated. Dont't use it")
    author: String @deprecated(reason:"author is deprecated. Dont't use it")
}

type Car {
    make: String @deprecated(reason:"make is deprecated. Dont't use it")
    model: String
}

You will see the deprecations in the response response example

Here is the response

"data": {...}
"extensions": {
    "deprecations": [
      {
        "field": "title",
        "reason": "title is deprecated. Dont't use it"
      },
      {
        "field": "author",
        "reason": "author is deprecated. Dont't use it"
      },
      {
        "field": "make",
        "reason": "make is deprecated. Dont't use it"
      }
    ]
  }

Friendly browser warnings

It's better use this package with apollo-deprecated-highlight-client. You can get friendly browser warnings in console like this client example

Readme

Keywords

Package Sidebar

Install

npm i apollo-deprecated-highlight

Weekly Downloads

21

Version

1.1.15

License

ISC

Unpacked Size

49.9 kB

Total Files

10

Last publish

Collaborators

  • alexxiyang