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

jest-serializer-graphql-schema

v5.0.0

Published

Jest serializer for GraphQLSchema objects

Downloads

8,215

Readme

jest-serializer-graphql-schema

GitHub Sponsors Discord chat room Follow Follow

A serializer for doing snapshot testing of GraphQL schemas using the Jest testing framework.

This serializer only works on instances of the GraphQLSchema class exported from graphql-js. It does not work on AST objects.

Crowd-funded open-source software

To help us develop this software sustainably, we ask all individuals and businesses that use it to help support its ongoing maintenance and development via sponsorship.

Click here to find out more about sponsors and sponsorship.

And please give some love to our featured sponsors 🤩:

* Sponsors the entire Graphile suite

Install

First, add this package as a devDependency:

# With npm
npm install --save-dev jest-serializer-graphql-schema

# With yarn
yarn add --dev jest-serializer-graphql-schema

Next, update your package.json file to let Jest know about the serializer:

"jest": {
  "snapshotSerializers": ["jest-serializer-graphql-schema"]
}

Simple Example

This test introspects the Pokemon GraphQL API to verify that the schema is consistent.

import fetch from "node-fetch";
import {
  getIntrospectionQuery,
  IntrospectionQuery,
  buildClientSchema,
} from "graphql";

const getSchema = async (url: string) => {
  const response = await fetch(url, {
    method: "POST",
    body: JSON.stringify({ query: getIntrospectionQuery() }),
    headers: { "Content-Type": "application/json" },
  });
  const result = await (response.json() as Promise<{
    data: IntrospectionQuery;
  }>);
  return buildClientSchema(result.data);
};

test("Pokemon GraphQL API has a consistent schema", async () => {
  const schema = await getSchema("https://graphql-pokemon.now.sh");
  expect(schema).toMatchSnapshot();
});

This test will produce the following snapshot:

// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`Pokemon GraphQL API has a consistent schema 1`] = `
"""Represents a Pokémon's attack types"""
type Attack {
  """The name of this Pokémon attack"""
  name: String

  """The type of this Pokémon attack"""
  type: String

  """The damage of this Pokémon attack"""
  damage: Int
}

"""Represents a Pokémon"""
type Pokemon {
  """The ID of an object"""
  id: ID!

  """The identifier of this Pokémon"""
  number: String

  """The name of this Pokémon"""
  name: String

  """The minimum and maximum weight of this Pokémon"""
  weight: PokemonDimension

  """The minimum and maximum weight of this Pokémon"""
  height: PokemonDimension

  """The classification of this Pokémon"""
  classification: String

  """The type(s) of this Pokémon"""
  types: [String]

  """The type(s) of Pokémons that this Pokémon is resistant to"""
  resistant: [String]

  """The attacks of this Pokémon"""
  attacks: PokemonAttack

  """The type(s) of Pokémons that this Pokémon weak to"""
  weaknesses: [String]
  fleeRate: Float

  """The maximum CP of this Pokémon"""
  maxCP: Int

  """The evolutions of this Pokémon"""
  evolutions: [Pokemon]

  """The evolution requirements of this Pokémon"""
  evolutionRequirements: PokemonEvolutionRequirement

  """The maximum HP of this Pokémon"""
  maxHP: Int
  image: String
}

"""Represents a Pokémon's attack types"""
type PokemonAttack {
  """The fast attacks of this Pokémon"""
  fast: [Attack]

  """The special attacks of this Pokémon"""
  special: [Attack]
}

"""Represents a Pokémon's dimensions"""
type PokemonDimension {
  """The minimum value of this dimension"""
  minimum: String

  """The maximum value of this dimension"""
  maximum: String
}

"""Represents a Pokémon's requirement to evolve"""
type PokemonEvolutionRequirement {
  """The amount of candy to evolve"""
  amount: Int

  """The name of the candy to evolve"""
  name: String
}

"""Query any Pokémon by number or name"""
type Query {
  query: Query
  pokemons(first: Int!): [Pokemon]
  pokemon(id: String, name: String): Pokemon
}

`;

Sorting Schemas

Note that by default, schemas are not sorted before serialization. This means that if the content of the schema is reordered, your snapshot test will fail. If you don't care about the order of the content of your schema, sort your schema before calling .toMatchSnapshot(), like this:

import { lexicographicSortSchema } from "graphql";

test("Pokemon GraphQL API has a consistent schema", async () => {
  const schema = await getSchema("https://graphql-pokemon.now.sh");
  expect(lexicographicSortSchema(schema)).toMatchSnapshot();
});