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

@vantreeseba/graphql-mocks-codegen

v3.0.0

Published

GraphQL Code Generator plugin that emits a SchemaTypeMap for typing @vantreeseba/graphql-mocks pools.

Downloads

385

Readme

@vantreeseba/graphql-mocks-codegen

A GraphQL Code Generator plugin that emits a SchemaTypeMap — a { TypeName: GeneratedType } map of every object type in your schema — so you can hand it to @vantreeseba/graphql-mocks's buildMocks<TTypes> and get typed mock pools back without a cast.

Install

npm install -D @vantreeseba/graphql-mocks-codegen
# peer deps you already have for codegen
npm install -D @graphql-codegen/cli @graphql-codegen/typescript
# the runtime the type map is used with
npm install @vantreeseba/graphql-mocks

Usage

Point the plugin at the same generated types file your typescript plugin (or the client preset) emits — by default it imports from ./graphql.

// codegen.ts
import type { CodegenConfig } from '@graphql-codegen/cli';

const config: CodegenConfig = {
  schema: './schema.graphql',
  generates: {
    // your existing typed output
    './src/__generated__/graphql.ts': {
      plugins: ['typescript'],
    },
    // the type map, emitted alongside it
    './src/__generated__/schema-type-map.ts': {
      plugins: ['@vantreeseba/graphql-mocks-codegen'],
    },
  },
};

export default config;

Then type your mock pools straight off the generated map:

import { buildMocks } from '@vantreeseba/graphql-mocks';
import type { SchemaTypeMap } from './__generated__/schema-type-map';

const mocks = buildMocks<SchemaTypeMap>(schema);

mocks.User;                          // User[] — typed, no cast
mocks.find('Todo', (t) => t.done);   // Todo | undefined — predicate item typed

Generated output

For a schema with User and Todo object types, the plugin emits:

import type * as Types from './graphql';

export type SchemaTypeMap = {
  Todo: Types.Todo;
  User: Types.User;
};

The map KEY is the raw GraphQL type name (what the mock pools are keyed by at runtime); the VALUE references the generated TS type via codegen's own naming convention, so it stays correct even if you change namingConvention. Root operation types (Query/Mutation/Subscription) and introspection types are excluded; entries are sorted for deterministic output.

Configuration

All options are optional strings:

| Option | Default | Description | |---|---|---| | typeMapName | SchemaTypeMap | Name of the generated type-map type. | | typesImportPath | ./graphql | Module the generated TS types are imported from. | | typesNamespace | Types | Namespace alias the generated types are imported under. |

'./src/__generated__/schema-type-map.ts': {
  plugins: ['@vantreeseba/graphql-mocks-codegen'],
  config: { typeMapName: 'MockTypes', typesImportPath: '../gen/types' },
},