Last active
December 16, 2017 13:29
-
-
Save adambisek/78b65654f809cb618ef54b52d460c4ec to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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