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

vitest-graphql-coverage

v0.1.1

Published

Istanbul-compatible coverage maps for .graphql schema files in Vitest

Readme

vitest-graphql-coverage

Test coverage for your GraphQL schema backend (includes field resolvers, args, and input fields)

CI codecov npm

How it works

  • Statements — each field and argument definition in your schema is a statement. The count is how many times that field/argument was resolved during your tests.
  • Branches — each ! (non-null marker) in your schema is a branch with two arms: null and non-null (returned for fields, passed for args and input fields). This tells you whether your tests exercise both paths.

Installation

npm install --save-dev vitest-graphql-coverage

Peer dependencies: vitest ^3.0.0, graphql ^16.0.0.

Setup

1. Register your schema

Call registerSchemaForCoverage once when your server/schema is initialised — typically in the same file that builds or exports your schema.

import { buildSchema } from 'graphql';
import { readFileSync } from 'node:fs';
import { registerSchemaForCoverage } from 'vitest-graphql-coverage/register';

const schemaPath = new URL('./schema.graphql', import.meta.url).pathname;
const schema = buildSchema(readFileSync(schemaPath, 'utf8'));

registerSchemaForCoverage(schema, schemaPath);

export { schema };

registerSchemaForCoverage is a no-op outside of Vitest (i.e. in production), so it is safe to call unconditionally.

2. Add the reporter to your Vitest config

// vitest.config.ts
import { defineConfig } from 'vitest/config';
import GraphQLCoverageReporter from 'vitest-graphql-coverage/reporter';

export default defineConfig({
  test: {
    reporters: [new GraphQLCoverageReporter()],
    coverage: {
      provider: 'v8', // or 'istanbul'
      reporter: ['html', 'lcov', 'text'],
    },
  },
});

Run your tests with coverage enabled:

npx vitest run --coverage

Your .graphql files will now appear alongside your .ts files in the coverage report.

Coverage semantics

| Schema construct | Statement | Branch | |---|---|---| | field: Type | resolved count | — | | field: Type! | resolved count | null vs non-null return | | field(arg: Type): … | times arg was provided | — | | field(arg: Type!): … | times arg was provided | null vs non-null value | | input Foo { field: Type } | times field was present in input | — | | input Foo { field: Type! } | times field was present in input | (always non-null arm) |

API

registerSchemaForCoverage(schema, schemaFilePath)

Instruments all resolvers on the given GraphQLSchema to record hit counts, and registers schemaFilePath so the reporter knows which .graphql file to map results back to. Call this once per schema at startup.

GraphQLCoverageReporter

A Vitest Reporter class. Add an instance to the reporters array in your Vitest config. It integrates with @vitest/coverage-v8 and @vitest/coverage-istanbul by injecting FileCoverage entries into the Istanbul CoverageMap produced by the coverage provider.

Compatibility

| | Supported | |---|---| | Vitest | ^3.0.0 | | pool: 'threads' (default) | yes | | pool: 'forks' | yes | | @vitest/coverage-v8 | yes | | @vitest/coverage-istanbul | yes | | GraphQL | ^16.0.0 | | Node.js | 22, 24 |

License

MIT