npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2021 – Pkg Stats / Ryan Hefner

apollo-server-tools

v3.0.5

Published

Helper for apollo-server

Downloads

364

Readme

apollo-server-tools

Build Status Test Coverage Dependabot Status Dependencies NPM Downloads Semantic-Release Gardener

Helper for apollo-server

Install

Install with npm:

$ npm install --save apollo-server-tools

Example

const path = require('path');
const { syncDocs, CommentVersionPlugin } = require('apollo-server-tools');
const { ApolloServer } = require('apollo-server');
const request = require('request-promise');

const typeDefs = `
    type Query {
        # [deprecated] 1.0.0 Deprecated, add reason and what to do...
        messages: [Message!]!
    }
    # [deprecated] 2.0.0 Also Deprecated, notice the date
    type Message {
        id: String
        # [deprecated] 3.0.0 Yep, Deprecated, we can deprecate everything now
        content: String
        # [required] 3.0.0
        payload: String
    }
`;
const resolvers = {
  Query: {
    messages: () => [
      { id: 1, content: 'Data', payload: null }
    ]
  }
};

const server = new ApolloServer({
  typeDefs,
  resolvers,
  plugins: [CommentVersionPlugin({
    apiVersionHeader: 'x-api-version',
    forceSunset: false,
    sunsetDurationInDays: 7 * 52,
    versions: {
      '0.0.1': '2018-01-01',
      '1.0.0': '2019-01-01',
      '2.0.0': '2019-02-02',
      '3.0.0': '2019-03-03'
    }
  })],
  introspection: false // clients should obtain this from the generated file (see below)
});

// --- deprecation header are returned when deprecated functionality is accessed

server.listen().then(async (serverInfo) => {
  const r = await request({
    method: 'POST',
    uri: `${serverInfo.url}graphql`,
    json: true,
    body: { query: 'query Messages { messages { id, content } }' },
    headers: {
      'x-api-version': '0.0.1'
    },
    resolveWithFullResponse: true
  });
  // As per example https://tools.ietf.org/html/draft-dalal-deprecation-header-00#section-5
  console.log('Deprecation Header:', r.headers.deprecation);
  console.log('Sunset Header:', r.headers.sunset);
  console.log('Response Body:', JSON.stringify(r.body));
  serverInfo.server.close();
});

// --- how you could sync graph api documentation to file

syncDocs(path.join(__dirname, 'graph-docs.json'), server.schema);

Functions

parseInfo({ ast, fragments = {}, vars = {} })

Parse info object to easily access relevant information.

getDeprecationMeta({ versions, sunsetDurationInDays, schema, ast, fragments = {}, vars = {} })

Parse out relevant deprecation information for all accessed functionality.

Expects custom deprecation syntax, see below.

The versions parameter is expected to be an object mapping versions to their respective introduction Date.

Can e.g. be used to return a Sunset header.

getDeprecationDetails({ schema, ast, fragments = {}, vars = {} })

Fetch deprecated entities that are accessed by the query. Expects custom deprecation syntax, see below.

CommentVersionPlugin({ sunsetDurationInDays: Integer, forceSunset: Boolean, versions: Object })

Graphql Plugin that injects appropriate headers into responses.

If forceSunset is set to true and sunset functionality is accessed, an error is thrown.

Versions is expected to be an object mapping versions to their creation date string as "YYYY-MM-DD".

Can make optional arguments required from a certain version by using e.g [required] 1.0.0 as a comment.

syncDocs(filepath, schema, stripDeprecated = true)

Write introspection result into file. Order is stable. Returns true iff the content has changed. Deprecated entities are removed if option is set. Expects custom deprecation syntax, see below.

generateDocs(schema, stripDeprecated = true)

Generate and return introspection result. Deprecated entities are removed if option is set. Expects custom deprecation syntax, see below.

Deprecation Syntax

Deprecation functionality is very limited in graphql. This tool allows overloading of comments, which means that everything in the schema can be deprecated.

The deprecation comment is expected to be in the form [deprecated] YYYY-MM-DD description, where the date indicates the date of deprecation.