3.0.0 • Published 3 years ago

fast-graphql-mock v3.0.0

Weekly downloads
22
License
MIT
Repository
github
Last release
3 years ago

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.

3.0.0

3 years ago

2.1.5

3 years ago

2.1.4

3 years ago

2.1.3

3 years ago

2.1.2

4 years ago

2.1.1

4 years ago

2.1.0

4 years ago

2.0.7

4 years ago

2.0.6

4 years ago

2.0.5

4 years ago

2.0.4

4 years ago

2.0.3

5 years ago

2.0.2

5 years ago

2.0.1

5 years ago

2.0.0

5 years ago

1.2.6-alpha

5 years ago

1.2.5-alpha

5 years ago

1.2.4-alpha

5 years ago

1.2.3-alpha

5 years ago

1.2.2-alpha

5 years ago

1.2.1-alpha

5 years ago

1.2.0-alpha

5 years ago

1.1.0

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago