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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@nwire/apollo

v0.12.1

Published

Nwire — Apollo Server (v4) interop adapter. actionResolver(action) plugs a Nwire ActionDefinition into a GraphQL schema as a field resolver; nwireApolloContext({ runtime }) adds runtime.dispatch + envelope to Apollo's per-request context; mountNwireOnApol

Readme

@nwire/apollo

Apollo Server (v4) interop — plug Nwire actions into a GraphQL schema as field resolvers; reuse a hand-authored schema you already maintain.

What it is

A thin adapter (~60 LOC of real code). actionResolver(action) wraps a Nwire ActionDefinition so it serves as a GraphQL field resolver. nwireApolloContext({ runtime }) injects the runtime + a fresh envelope onto every request. mountNwireOnApollo(...) bundles the context factory with Nwire-aware error formatting so defineError errors surface with stable extensions.code.

Same migration story Express got: keep the schema and gateway you already have, stop hand-writing resolver bodies that just call services.

A native GraphQL transport (schema generated from actions/queries automatically, subscriptions on top of @nwire/bus) is a separate roadmap item. This package is for teams already running Apollo with a hand-authored schema. Cross-link: @nwire/express.

Install

pnpm add @nwire/apollo @apollo/server graphql

@apollo/server (^4) and graphql (^16) are peer deps — bring whatever versions your Apollo setup already uses. Apollo v3 is EOL and unsupported.

Quickstart

import { z } from "zod";
import { ApolloServer } from "@apollo/server";
import { startStandaloneServer } from "@apollo/server/standalone";
import gql from "graphql-tag";
import { defineAction, Runtime } from "@nwire/forge";
import { actionResolver, mountNwireOnApollo } from "@nwire/apollo";

const submitAnswer = defineAction({
  name: "submissions.submit-answer",
  schema: z.object({ questionId: z.string(), answer: z.string() }),
  handler: async (input, ctx) => ({
    id: "sub-1",
    ...input,
    student: ctx.envelope.userId,
  }),
});

const runtime = new Runtime();
runtime.registerHandler(submitAnswer.handler!);

const typeDefs = gql`
  input SubmitAnswerInput {
    questionId: String!
    answer: String!
  }
  type Submission {
    id: ID!
    questionId: String!
    answer: String!
    student: String
  }
  type Mutation {
    submitAnswer(input: SubmitAnswerInput!): Submission!
  }
  type Query {
    _: Boolean
  }
`;

const apollo = new ApolloServer({
  typeDefs,
  resolvers: {
    Mutation: { submitAnswer: actionResolver(submitAnswer) },
  },
  ...mountNwireOnApollo({ runtime }),
});

await startStandaloneServer(apollo, { listen: { port: 4000 } });

actionResolver reads args.input by default (matches GraphQL convention for mutation inputs); customise via extractInput for query-style flat args. Dispatched actions return their handler value verbatim to the GraphQL response — emit events, no events, return a plain object, whatever the handler does.

API

  • actionResolver(action, options?)ActionDefinition → GraphQL field resolver. Options: extractInput, extractEnvelope, resolveRuntime.
  • nwireApolloContext({ runtime, extractEnvelope?, extractUser? }) — Apollo context factory that injects runtime + envelope per request.
  • mountNwireOnApollo({ runtime, ... }) — convenience bundle: returns { context, formatError } you spread into ApolloServer constructor + startStandaloneServer options.
  • formatNwireError(formattedError, rawError) — standalone formatError callback. Use directly if you compose your own error formatter.

Errors

When a handler throws a defineError-style value (e.g. QuestionLocked), GraphQL clients receive:

{
  "errors": [
    {
      "message": "Question is locked for further submissions.",
      "extensions": { "code": "QUESTION_LOCKED", "status": 423 }
    }
  ]
}

Same stable code the REST transport emits — clients can branch on extensions.code and ignore wire format.

See also