Socket
Book a DemoInstallSign in
Socket

mgdg

Package Overview
Dependencies
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

mgdg

Mock Graphql Data Generator

1.1.2
latest
Source
npmnpm
Version published
Weekly downloads
205
-53.93%
Maintainers
1
Weekly downloads
 
Created
Source

Mock GraphQL Data Generator

Takes a valid GraphQL Schema + Data Resolvers and generates valid query and mutation responses

Usage

Define Resolvers

// resolvers/Rocket.ts

import { MockResolvedValue, ShallowProperties } from 'mgdg'
import { Rocket } from '../../api'
import faker from 'faker'

const MockRocket = (
  _parent,
  args,
): MockResolvedValue<ShallowProperties<Rocket>> => {
  return {
    id: () => faker.random.uuid(),
    name: () => faker.random.word(),
    type: () => faker.random.word(),
  }
}

export default MockRocket

Setup Mock Server

// mocker.ts

import MockFactory from 'mgdg'

// Valid GraphQL Schema
import schemaJson from './schema'

import Rocket from './resolvers/Rocket'

export default new MockFactory(
  schemaJson as any,
  { mocks: { Rocket }
)

Execute Query

import gql from 'graphql-tag'

import mocker from './mocker'

const query = gql`
  query Rocket($id: ID!) {
    rocket(id: $id) {
      id
      name
      type
    }
  }
`

const rocketResults = mocker.mockQuery(query, { variables: { id: 'rocket-1' } })

console.log(rocketResults)

For more details, see this demo

Keywords

graphql

FAQs

Package last updated on 27 Jan 2021

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.