Skip to content

Instantly share code, notes, and snippets.

@adambisek
Last active December 16, 2017 13:29
Show Gist options
  • Save adambisek/78b65654f809cb618ef54b52d460c4ec to your computer and use it in GitHub Desktop.
Save adambisek/78b65654f809cb618ef54b52d460c4ec to your computer and use it in GitHub Desktop.
import faker from 'faker';
import { ApolloClient } from 'react-apollo';
import MockNetworkInterface from 'apollo-mocknetworkinterface';
const createResponse = (request) => { // pure function returning data
console.log('creating mocked response for request:', request); // eslint-disable-line no-console
// will log: creating mocked response for request: { query: { kind: 'Document' ...
return {
data: {
component: {
id: 1, // use static value
email: faker.internet.email(), // or generate anything
url: request.variables.url, // note that you can even use anything from the request
},
},
};
};
const networkInterface = new MockNetworkInterface(createResponse, { timeout: 100 }); // simulate network latency
const client = new ApolloClient({ networkInterface, addTypename: false });
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment