Socket
Socket
Sign inDemoInstall

graphql-rest-mocks

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

graphql-rest-mocks

Mock a REST API using GraphQL


Version published
Weekly downloads
1
Maintainers
1
Weekly downloads
 
Created
Source

Getting Started

Run npm i graphql-rest-mocks

Create a folder called ./contracts in your repository

Add a file called HelloWorld.graphql, with these contents:

type Request {
  id: ID!
}

type Response {
  string: String!
}

Add this script to your package.json:

{
  "scripts": {
    "start": "graphql-rest-mocks start ./contracts"
  }
}

Run npm run start

Visit localhost:4000/HelloWorld?id=200

You'll see a mock server producing data.

Add global types

Create a folder called ./types

Add a file called GlobalType.graphql, with these contents:

type GlobalType {
  someGlobalId: ID!
}

Change HelloWorld.graphql to use that global type, as below:

type Request {
  id: ID!
}

type Response {
  string: String!
  globalType: GlobalType!
}

No need to import it, or do anything fancy. Any type, scalar or enum declared in the global types folder is available to all contracts.

Change the script to use the types folder:

{
  "scripts": {
    "start": "graphql-rest-mocks start ./contracts --types ./types"
  }
}

Possible Types

https://www.apollographql.com/docs/apollo-server/schemas/types.html

TL;DR:

Int

Float

String

ID

Boolean

FAQs

Package last updated on 25 Apr 2019

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

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc