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

@newmo/graphql-codegen-fake-server-client

v0.25.0

Published

GraphQL Codegen plugin for generating a fake server client

Readme

@newmo/graphql-codegen-fake-server-client

GraphQL Code Generator plugin that generates fake client for @newmo/graphql-fake-server .

Installation

npm add --save-dev @newmo/graphql-codegen-fake-server-client
# This plugin depends on @graphql-codegen/client-preset
npm install @graphql-codegen/cli @graphql-codegen/client-preset --save-dev

GraphQL Code Generator configuration:

import type { CodegenConfig } from "@graphql-codegen/cli";

const config: CodegenConfig = {
  overwrite: true,
  schema: "./api/graphql/api.graphqls",
  documents: "./api/graphql/query.graphql",
  generates: {
    "./generated/": {
      preset: "client",
    },
    "./generated/fake-client.ts": {
      plugins: ["@newmo/graphql-codegen-fake-server-client"],
      config: {
        // Required: path to the generated client's graphql file
        typesFile: "./graphql",
      },
    },
  },
};

export default config;

You can use ./generated/fake-client.ts to register the fake to the fake server.

Basic Usage

import { it, expect } from "vitest";
import { createFakeClient } from "./generated/fake-client";

const fakeClient = createFakeClient({
  fakeServerEndpoint: "http://localhost:4000",
});
it("register fake response for query", async () => {
  const sequenceId = crypto.randomUUID();
  // register fake response for GetBooks query
  const resRegister = await fakeClient.registerGetBooksQueryResponse(
    sequenceId,
    {
      books: [
        {
          id: "new id",
          title: "new title",
        },
      ],
    }
  );
  expect(resRegister).toMatchInlineSnapshot(`"{"ok":true}"`);
  // request to server
  const client = new GraphQLClient(`${fakeServerUrl}/graphql`, {
    headers: {
      "sequence-id": sequenceId,
    },
  });
  // Got fake response
  const response = await client.request(GetBooksDocument);
  expect(response).toMatchInlineSnapshot(`
          {
            "books": [
              {
                "id": "new id",
                "title": "new title",
              },
            ],
          }
        `);
  // Get actual request and response for testing
  const calledResults = await fakeClient.calledGetBooksDocumentQuery(
    sequenceId
  );
  console.log(calledResults[0].request);
  console.log(calledResults[0].response);
});

Conditional Fake Responses

You can register conditional fake responses that return different results based on variables. The variables are now fully type-safe based on your GraphQL operations:

import { it, expect } from "vitest";
import { createFakeClient } from "./generated/fake-client";

const fakeClient = createFakeClient({
  fakeServerEndpoint: "http://localhost:4000",
});

it("register conditional fake responses", async () => {
  const sequenceId = crypto.randomUUID();

  // Type-safe variables condition!
  // TypeScript will enforce the correct variables shape for this operation
  await fakeClient.registerListDestinationCandidatesQueryResponse(
    sequenceId,
    {
      destinationCandidates: [{ id: "3", name: "Tokyo Station" }],
    },
    {
      requestCondition: {
        type: "variables",
        value: { text: "tokyo" }, // ✅ Type-safe! Must match ListDestinationCandidatesQueryVariables
      },
    }
  );

  // Another type-safe variables condition example
  await fakeClient.registerCreateUrlRideHistoryMutationResponse(
    sequenceId,
    {
      createURLRideHistory: { id: "4", name: "Shibuya" },
    },
    {
      requestCondition: {
        type: "variables",
        value: { desinationName: "Shibuya" }, // ✅ Type-safe for this mutation!
      },
    }
  );
});

Type Safety Benefits

  • Variables validation: TypeScript will ensure variables in conditions match the exact shape expected by your GraphQL operation
  • Autocomplete: Your IDE will provide autocomplete for available variable fields
  • Compile-time errors: Typos or wrong variable types will be caught at compile time
  • Refactoring safety: If you change your GraphQL schema, TypeScript will help you update the affected conditions

Options

  • typesFile (required): Path to the generated client's graphql file.
  • fakeServerEndpoint (optional): Fake server endpoint. Default is http://127.0.0.1:4000/fake.
  • namingConvention (optional): Naming convention for the generated types. Default is change-case#pascalCase.
  • typesPrefix (optional): Prefix for the generated types.
  • typesSuffix (optional): Suffix for the generated types.

License

MIT