4.1.0 • Published 11 months ago

@pothos/plugin-mocks v4.1.0

Weekly downloads
-
License
ISC
Repository
github
Last release
11 months ago

Mocks Plugin for Pothos

A simple plugin for adding resolver mocks to a GraphQL schema.

Usage

Install

yarn add @pothos/plugin-mocks

Setup

import MocksPlugin from '@pothos/plugin-mocks';
const builder = new SchemaBuilder({
  plugins: [MocksPlugin],
});

Adding mocks

You can mock any field by adding a mock in the options passed to builder.toSchema under mocks.{typeName}.{fieldName}.

builder.queryType({
  fields: (t) => ({
    someField: t.string({
      resolve: () => {
        throw new Error('Not implemented');
      },
    }),
  }),
});

builder.toSchema({
  mocks: {
    Query: {
      someField: (parent, args, context, info) => 'Mock result!',
    },
  },
});

Mocks will replace the resolve functions any time a mocked field is executed. A schema can be built multiple times with different mocks.

Adding mocks for subscribe functions

To add a mock for a subscriber you can nest the mocks for subscribe and resolve in an object:

builder.subscriptionType({
  fields: (t) => ({
    someField: t.string({
      resolve: () => {
        throw new Error('Not implemented');
      },
      subscribe: () => {
        throw new Error('Not implemented');
      },
    }),
  }),
});

builder.toSchema({
  mocks: {
    Subscription: {
      someField: {
        resolve: (parent, args, context, info) => 'Mock result!',
        subscribe: (parent, args, context, info) => {
          /* return a mock async iterator */
        },
      },
    },
  },
});
3.7.9

1 year ago

4.1.0

11 months ago

4.0.0

1 year ago

4.0.2

12 months ago

4.0.0-next.1

1 year ago

4.0.0-next.0

1 year ago

3.7.8

2 years ago

3.7.1

3 years ago

3.7.0

3 years ago

3.7.5

3 years ago

3.7.4

3 years ago

3.7.3

3 years ago

3.7.2

3 years ago

3.7.7

3 years ago

3.7.6

3 years ago

3.6.1

3 years ago

3.6.0

3 years ago

3.5.0

3 years ago

3.4.0

3 years ago

3.3.0

3 years ago

3.2.0

3 years ago

3.1.1

3 years ago

3.1.0

3 years ago

3.0.1

3 years ago

3.0.0

3 years ago