https://github.com/remorses/graphql-easy-mocks
Mock server for graphql frontend development
https://github.com/remorses/graphql-easy-mocks
Last synced: 7 months ago
JSON representation
Mock server for graphql frontend development
- Host: GitHub
- URL: https://github.com/remorses/graphql-easy-mocks
- Owner: remorses
- Created: 2019-09-03T17:28:29.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-30T04:40:34.000Z (almost 3 years ago)
- Last Synced: 2025-06-21T23:37:13.755Z (7 months ago)
- Language: TypeScript
- Size: 239 KB
- Stars: 1
- Watchers: 2
- Forks: 1
- Open Issues: 5
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
## Usage
```
version: "3"
services:
mocker:
image: mongoke/graphql-mocker
ports:
- 7090:80
environment:
- PORT=80
- URL=http://gqlapi:8080/graphql
- MOCKS_PATH=/mocks.js
- PRESERVE_MUTATIONS=1
# maintain mutations from original schema
- PRESERVE_QUERIES=allAssets, queryName
# maintain certain queries
volumes:
- ./tests/mocks.js:/mocks.js
gqlapi:
ports:
- 7060:8080
build: your api
```
## Usage as cli
## Install
```
npm install -g graphql-easy-mocks
```
## Then run
`graphql-easy-mocks --port 9000 -f schema.graphql -m mocks.js`
```javascript
// mocks.js
const faker = require('faker')
module.exports = {
String: () => 'works!',
Int: () => faker.random.number(100),
}
```
Then start the server with the app
```json
"scripts": {
"start": "REACT_APP_TESTING=1 concurrently 'npm:mock-server' 'react-scripts start'",
"mock-server": "graphql-easy-mocks -p 9000 -f schema.graphql -m mocks.js",
}
```
Then use it as your server url inside your app.
```js
import ApolloClient from 'apollo-boost'
const uri = process.env.REACT_APP_TESTING
? 'http://localhost:9000'
: 'https://countries.trevorblades.com'
export default new ApolloClient({
uri,
})
```