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

mb-graphql

v0.1.11

Published

mountebank test doubles for GraphQL

Downloads

36

Readme

Node.js Build Docker Pulls npm npm

Welcome, friend

GraphQL Playground

mb-graphql is a mountebank plugin that makes creating test doubles for GraphQL APIs a lot simpler... and fun: there's no code to write.

Wraps Apollo Server to allow easy declaration of a mock GraphQL server via mountebank stubs (see below).

Features

Getting started

Option 1: Run with Docker (the easiest option)

docker run -p 2525:2525 [-p IMPOSTER_PORT:IMPOSTER_PORT] -d bashj79/mountebank-graphql

NOTE: mountebank itself runs on port 2525.

Check out Docker Hub for further details.

Option 2: Install and Run

Prerequisite:

npm install -g mb-graphql

Start mountebank with the following protocols.json file (master on GitHub):

{
  "graphql": {
    "createCommand": "mb-graphql"
  }
}
mb start --protofile protocols.json

Example

imposter.json

{
  "port": 4000,
  "protocol": "graphql",
  "schema": "type Thing { alpha: Int beta: String } type Query { myQuery(myFirstArg: Int, mySecondArg: Int): Thing }",
  "stubs": [
    {
      "predicates": [
        {
          "equals": {
            "query": "myQuery",
            "args": {
              "myFirstArg": 123
            }
          }
        }
      ],
      "responses": [
        {
          "is": {
            "data": {
              "beta": "abcdef"
            }
          }
        }
      ]
    }
  ]
}

Create the imposter via mountebank (assuming it's running on localhost:2525):

curl -i -X POST -H 'Content-Type: application/json' http://localhost:2525/imposters --data @imposter.json

You can now access the GraphQL playground for the imposter at http://localhost:4000:

GraphQL Playground

Request

query {
    myQuery(myFirstArg: 123, mySecondArg: 456) {
        alpha
        beta
    }
}

Response

{
  "data": {
    "myQuery": {
      "alpha": 42,
      "beta": "abcdef"
    }
  }
}

Note: The value for myQuery.alpha has been randomly generated as it was omitted from the stub's response.

For further examples please check out the features folder.

Imposter Creation Parameters

For further information about mountebank imposters, stubs and related concepts please refer to the mountbank mental model.

| Parameter | Description | Required? | Default | |-------------------------|--------------------------------------------------------------------------------------------------------------------------|--------------------------------|----------------------------------------------------------------------------------------------| | protocol | Must be set to graphql | Yes | N/A |
| port | The port to run the imposter on. | No | A randomly assigned port. mountebank will return the actual value in the POST response. |
| name | Included in the logs, useful when multiple imposters are set up. | No | An empty string. | | schema | A string presenting a valid GraphQL schema definition. | No, if schemaEndpoint is set | N/A |
| schemaEndpoint | URL of a GraphQL schema file or the endpoint of an existing GraphQL API which exposes the GraphQL introspection query. | No, if schema is set | N/A |
| schemaEndpointHeaders | An object representing headers to passed to the schema endpoint defined in schemaEndpoint e.g. Authorization header. | No | An empty object. | | stubs | The list of stubs responsible for matching a GraphQL request and returning a response. See further details below. | No | An empty array. | | defaultResponse | The default response for any top-level query/mutation performed against the schema. | No | Default behaviour for the imposter is to return random data according to the defined schema. |

GraphQL Request Predicates

| Field | Description | Type | |------------|--------------------------------------------------------|--------| | query | The name of the GraphQL query e.g. myQuery. | String | | mutation | The name of the GraphQL mutation e.g. myMutation. | String | | args | The arguments passed to the GraphQL query/mutation. | Object | | headers | The HTTP headers passed to the GraphQL query/mutation. | Object |

Please see the mountebank predicate documentation for further details of mountebank's stub predicates and their usage.