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 🙏

© 2024 – Pkg Stats / Ryan Hefner

graphql-mocky

v0.2.0

Published

Mock GraphQL APIs with ease!

Downloads

7

Readme

Mock GraphQL APIs with ease!

oclif Version Downloads/week License

Usage

Ways of running

From all of these methods, the GraphQL server (and Graphiql, if enabled) will be available at /graphql (e.g. http://localhost:3000/graphql).

Docker

A simple docker file is provided (to be published). You can then add in your config and schema (if required), either as a bind mount volume or as another layer.

e.g.

FROM alex/graphql-mocky
COPY .graphql-mockyrc schema.graphql ./

NB: the image is not published yet! So you'll have to build yourself from the provided root Dockerfile.

By default, the application listens to port 3000, so map that to a local port etc.

Package

Install (globally or locally) or run the graphql-mocky NPM package:

$ npm install -g graphql-mocky
$ yarn global add graphql-mocky
$ graphql-mocky
running command...
# Or
$ npx graphql-mocky

Programmatically

Install the graphql-mocky package and import graphql-mocky/server. This API is subject to change though.

Arguments

CLI arguments override the config file.

port

schema

graphiql

Config

A schema must be provided. This can be either provided as config or a CLI argument:

graphql-mocky --schema ./schema.graphql

Cosmiconfig is used for reading a config file, which allows the mocking to be customised. The following places will be searched:

  • package.json (graphql-mocky key)
  • .graphql-mockyrc (YAML or JSON)
  • .graphql-mockyrc.[json|yaml|yml|js|cjs]
  • graphql-mocky.config.[json|yaml|yml|js|cjs]
  • graphql-mocky.[json|yaml|yml]

The schema for all is the same:

schema

The path to a schema. Currently only relative paths are supported (this is next on the list).

port

The port to bind the HTTP server to. Defaults to 3000.

graphiql

Enable/disable the Graphiql UI. Defaults to true.

mocks

Customise the mocking. By default, the GraphQL primitives (strings, numbers, booleans) are randomly assigned using casual.

Keys correspond to either GraphQL primitives (String, Int, Float, Boolean or ID), custom scalars or types from the schema.

mocks:
  String: Hello world
  Query:
    books: mockList(10)
  Book:
    name: casual.title
    sales: casual.integer(1000, 50000)

Values can be specified in several ways:

  • Literals If a literal value is used, it is returned directly
  • casual If a string starting with casual. is used, the corresponding casual function is called.
  • Mock list Use mockList(10) or mockList(1, 5) to control the number of items in a list (otherwise random)
  • Functions If using a .js format for config, you can specify a function which will be called automatically

path

The URL path to run at. Defaults to /graphql.

healthcheck

Adds a healthcheck endpoint to the server. This will respond to HTTP GET requests. Disabled by default.

healthcheck.path

URL path for the healthcheck endpoint.

healthecheck.result

What to send back to the healthcheck endpoint.