This package has been deprecated

Author message:

Package no longer supported. Contact Support at https://www.npmjs.com/support for more info.

fast-graphql-mock
TypeScript icon, indicating that this package has built-in type declarations

3.0.0 • Public • Published

fast-graphql-mock

fast-graphql-mock is a tiny library for mocking GraphQL server using only schema file. Under the hood it uses ApolloServer and graphql-import library.

Installation

Locally

Using yarn:

yarn add fast-graphql-mock

or npm:

npm install fast-graphql-mock

Globally

yarn:

yarn global add fast-graphql-mock

npm:

npm install -g fast-graphql-mock

Usage

As CLI

To mock a schema just run the application with node.

fast-graphql-mock

By default it looks for schema file with name of schema.graphql in current location. To change this behavior use -f or --file flag.

fast-graphql-mock -f othername.graphql

Default port is set to 4000. If you want to change it just use p or --port flag.

fast-graphql-mock -p 3000

As separate library

fast-graphql-mock exports following functions along with TypeScript definitions:

mockSchema- makes schema file executable and adds mock functions to it

createMockServer- returns ApolloServer instance from given mockedSchema and adds resolvers mocked using faker.js library

startMockServer- starts given ApolloServer instance on given port

Example

The simplest example of usage of this library:

import {
  mockSchema,
  createMockServer,
  startMockServer,
} from "fast-graphql-mock";

const schema = mockSchema("schema.graphql");
const server = createMockServer(schema);
startMockServer(server, 3000);

Adding custom mocks (fakers)

You are able to pass custom mocks to the server

// [...]
const customFakers = {
  PhoneNumber: (): string => '123456789',
};
const server = createMockServer(schema, customFakers);
// [...]

Why

Code inside this library is really short (what can't be said about it's dependencies), however I wanted to make something what can make my workflow faster by avoiding need to create mock every time I am working on app using GraphQL.

Package Sidebar

Install

npm i fast-graphql-mock

Weekly Downloads

13

Version

3.0.0

License

MIT

Unpacked Size

12.1 kB

Total Files

13

Last publish

Collaborators

  • kuskoman