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

gatsby-source-mock

v1.2.1

Published

Gatsby source plugin to mock GraphQL data with Faker.js

Readme

gatsby-source-mock

This plugin allows you to mock GraphQL data in Gatsby sites using Faker.js or custom callback functions. This is especially useful for mocking datasets that are still under development and can be hooked in later.

This plugin is based on the official gatsby-source-faker plugin.

Install

npm install --save gatsby-source-mock

or

yarn add gatsby-source-mock

How to use

Define the schema in gatsby-config.js. See a full list of options here.

module.exports = {
  plugins: [
    {
      resolve: `gatsby-source-mock`,
      options: {
        schema: {
          name: `{{name.firstName}} {{name.lastName}}`,
          company: `{{company.companyName}}`,
          balance: (faker) => faker.finance.amount() / 2,
          features: {
            accountType: (faker) =>
              faker.random.arrayElement(['Free', 'Premium']),
            creditCard: {
              isValid: (faker) => faker.datatype.boolean(),
              number: `{{finance.creditCardNumber}}`,
            },
            account: {
              iban: `{{finance.iban}}`,
              bic: `{{finance.bic}}`,
            },
          },
        },
        count: 10,
        type: `BankAccount`,
        seed: 123456,
        locale: `de`,
      },
    },
  ],
};

Faker.fake()

All strings will be parsed with Faker.fake(), so you may use a mustache string format to use Faker.js methods:

{
  options: {
    schema: {
      fullName: '{{name.firstName}} {{name.lastName}}',
      ...
    },
  }
}

Callback

You may pass a callback function which will receive an instance of Faker. This can be useful for more complex situations:

{
  options: {
    schema: {
      emoji: (faker) => {
        return faker.random.arrayElement(
          ['🤖', '✌️', '🎮', '✊', '🙃']
        );
      },
      ...
    },
  }
}

The callback function will also receive the index of the current run as a second argument:

{
  options: {
    schema: {
      counter: (faker, index) => {
        return `Number ${index + 1}`;
      },
      ...
    },
  }
}

Defining data types

You can explicitely define data types by providing schema keys as <name>:<type>:

{
  options: {
    schema: {
      'title:String!': '{{lorem.sentence}}',
      'publishedAt:Date!': faker => faker.date.past(),
      'likes:Number': faker => faker.datatype.number(),
      subline: '{{lorem.sentence}}',
    },
  }
}

This would result in a schema definition like this:

id: ID!
title: String!
publishedAt(
  difference: String
  formatString: String
  fromNow: Boolean
  locale: String
): Date
likes: Number
subline: String

Passing a dataset

You may define a dataset explicitely by passing an array to schema. You can still use Faker.js interpolation and callback functions:

module.exports = {
  plugins: [
    {
      resolve: `gatsby-source-mock`,
      options: {
        schema: [
          {
            name: `Fred {{name.lastName}}`,
            about: (faker) => faker.lorem.paragraphs(3),
          },
          {
            name: `Hermine {{name.lastName}}`,
            about: (faker) => faker.lorem.paragraph(),
          },
          {
            name: `{{name.firstName}} Bowie`,
            about: (faker) => faker.lorem.paragraphs(2),
          },
        ],
        type: `User`,
      },
    },
  ],
};

You can also define a dataset and the count parameter to generate multiple nodes of the given dataset.

This example will create three nodes named Harry and two nodes named Hermine each with a random last name:

module.exports = {
  plugins: [
    {
      resolve: `gatsby-source-mock`,
      options: {
        schema: [
          {
            name: `Harry {{name.lastName}}`,
          },
          {
            name: `Hermine {{name.lastName}}`,
          },
        ],
        type: `Hogwarts`,
        count: 5,
      },
    },
  ],
};

Options

| Option | Description | | --------- | --------------------------------------------------------------------------------------------------------------------------- | | schema  | The object describing the schema | | count  | The number of fake items being generated, defaults to 10 | | type  | Name of the graphql query node | | seed  | You may specify a randomness seed to get consistent results | | locale  | You may specify a locale for fakes, defaults to en |

Query mock data

The GraphQL query will match the specified schema, for the example above it could look like this:

query {
  allBankAccount(limit: 2) {
    edges {
      node {
        id
        balance
        id
        name
        company
        features {
          account {
            bic
            iban
          }
          creditCard {
            number
            isValid
          }
        }
      }
    }
  }
}

The result for this example may look something like this:

{
  "data": {
    "allBankAccount": {
      "edges": [
        {
          "node": {
            "balance": 448.62,
            "id": "155df202-6533-5eea-a2b7-fbb4e796bdab",
            "name": "Filip Laurén",
            "company": "Thyssen, Grasse and Restorff",
            "features": {
              "account": {
                "bic": "SGHEAFZ1",
                "iban": "BG79YWJV02007108V69521"
              },
              "creditCard": {
                "number": "6384-3821-1503-3495",
                "isValid": false
              }
            }
          }
        },
        {
          "node": {
            "balance": 112.395,
            "id": "3c523dc7-4771-557b-aa0b-f0b5124dd78b",
            "name": "Rike Weller",
            "company": "Breitenstein OHG",
            "features": {
              "account": {
                "bic": "CVCUAZT1",
                "iban": "MK64263157663695906"
              },
              "creditCard": {
                "number": "5434-1536-6521-4284",
                "isValid": false
              }
            }
          }
        }
      ]
    }
  },
  "extensions": {}
}