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 🙏

© 2025 – Pkg Stats / Ryan Hefner

fastify-apollo-step

v1.2.1

Published

Set up Apollo Server on Fastify.

Downloads

22

Readme

fastify-apollo-step

Set up Apollo Server with Fastify.

update dependencies to the latest version.

  "dependencies": {
    "@types/node": "^14.14.8",
    "apollo-server-core": "^2.19.0",
    "fastify": "^3.8.0",
    "graphql": "^15.4.0",
    "graphql-playground-html": "^1.6.29",
    "graphql-subscriptions": "^1.1.0",
    "graphql-tools": "^7.0.1"
  }

fastify

Fast and low overhead web framework, for Node.js

apollo

A community building flexible open source tools for GraphQL.

fastify-apollo-step

As Apollo offical page said that Apollo Server can work with many Node.js HTTP frameworks, but no fastify in that list. So let's make one.

fastify-apollo-step is designed as a plugin of fastify, just call register to use it.

fastify-apollo-step also supports graphiql/playground module of Apollo Server.

Usage

npm install --save fastify-apollo-step apollo-server-core graphql fastify graphql-playground-html graphql-tools graphql-subscriptions
  • by fastify, just need apollo-server-core, not apollo-server

Options

fastify-apollo-step can be configurated with the follow option object, inclues itself configurations and Apollo Server configurations.

const options = {
    path: '/ql',
    context: undefined,
    gqlSchema: undefined,
    typeDefs: typeDefs,
    resolvers: resolvers,
    subscriptions: {
      enabled: true,
      path: '/subscriptions',
      onConnect: (connectionParams, webSocket) => {
      },
      onDisconnect: (webSocket, connectionContext) => {
      }
    },
    graphiql: {
      enabled: true,
      path: '/iql'
    },
    routeBeforeHandler: function (request, reply, done) {
      done();
    }
};
  • path: GraphQL module endpoint;
  • gqlSchema: GraphQL schema, optional if typeDefs and resolvers exist;
  • typeDefs: GraphQL type definitions, optional if schema exists;
  • resolvers: GraphQL resolver definitions, optional if schema exists;
  • subscriptions: Options of subscription;
  • graphiql: Options of GraphiQL of Playground;
  • routeBeforeHandler: beforeHandler function of Fastify while calls QL or iQL;

Example

const options = {
  path: '/ql',
  typeDefs: typeDefs,
  resolvers: resolvers,
  ...
};

fastify.register(ApolloFastify, options);

fastify.listen(3000, (err) => {
  if (err) {
      console.error('server starts failed - ', err);
      return;
  }    
  console.log('🚀 Server ready at http://localhost:3000');
});

TypeScript

Do NOT support TypeScript because NOT compatible with latest Fastify.

~~Ready. But I am not good at TypeScript yet.~~

~~To conflict with Fastify Plugin Option, I have to change 'schema' and 'beforeHandler' of FastifyApollo's, Please refer to ./test/ts/subscription.ts.~~

Test

    npm run query
    npm run mutation
    npm run subscription

Notes: Graphsql query must be with 'operationName' now.

query [querybook] {
  books {
    author
    title
  }
}

ScreenShots

  • Query

Query

  • Mutaton

Mutation

  • Subscription

Subscription