Skip to content
This repository has been archived by the owner on Dec 30, 2023. It is now read-only.

Basic improvements #7

Merged
merged 4 commits into from
Sep 2, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,25 @@
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`

You can also install this package globally:
`npm install fast-graphql-mock`


### Globally
yarn:

`yarn global add fast-graphql-mock`


npm:

`npm install -g fast-graphql-mock`

## Usage
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "fast-graphql-mock",
"version": "1.0.2",
"version": "1.0.4",
"description": "A library for mocking GraphQL schema using one command",
"bin": "src/index.js",
"repository": {
Expand Down
2 changes: 2 additions & 0 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ program
.option('-f --file <file>', 'schema file location', 'schema.graphql')
.option('-p --port <port>', 'apollo server port', '4000')

program.parse(process.argv)

const options = program.opts()

const schema = mockSchema(options.file)
Expand Down
9 changes: 9 additions & 0 deletions src/mock.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
const graphqlImport = require('graphql-import')
const graphqlTools = require('graphql-tools')
const fs = require('fs')

function checkIfFileExist(path) {
if (!fs.existsSync(path)) {
console.error(`${path} does not exist`)
process.exit(1)
}
}

function mockSchema(file) {
checkIfFileExist(file)
const schemaFile = graphqlImport.importSchema(file)
const schema = graphqlTools.makeExecutableSchema({ typeDefs: schemaFile })
graphqlTools.addMockFunctionsToSchema({ schema })
Expand Down