Skip to content

Instantly share code, notes, and snippets.

@TNick
Last active March 7, 2020 06:42
Show Gist options
  • Save TNick/d7253113de3b683aa67a0d7e6fa4aab4 to your computer and use it in GitHub Desktop.
Save TNick/d7253113de3b683aa67a0d7e6fa4aab4 to your computer and use it in GitHub Desktop.
react-admin standalone fake server for graphql
const express = require('express');
const cors = require('cors');
const generateData = require('data-generator-retail').default;
const jsonGraphqlExpress = require('json-graphql-server').default;
const log = require('debug')('fakeServer:alone-graphql:log');
log('-------------------------------------------------');
log('fakeServer is starting');
log('-------------------------------------------------');
const PORT = 4000;
const app = express();
const data = generateData({ serializeDate: false });
log('data with %d entries generated', Object.keys(data).length);
app.use(cors());
app.use('/graphql', jsonGraphqlExpress(data));
log('-------------------------------------------------');
log('fakeServer started; listening to localhost:%d', PORT);
log('-------------------------------------------------');
app.listen(PORT);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment