2020-09-04 08:08:27 -04:00
|
|
|
import { InMemoryCache } from 'apollo-cache-inmemory';
|
|
|
|
import { createMockClient } from 'mock-apollo-client';
|
|
|
|
import VueApollo from 'vue-apollo';
|
|
|
|
|
2020-11-03 10:09:05 -05:00
|
|
|
export default (handlers = [], resolvers = {}) => {
|
2020-09-04 08:08:27 -04:00
|
|
|
const fragmentMatcher = { match: () => true };
|
|
|
|
const cache = new InMemoryCache({
|
|
|
|
fragmentMatcher,
|
|
|
|
addTypename: false,
|
|
|
|
});
|
|
|
|
|
2020-11-03 10:09:05 -05:00
|
|
|
const mockClient = createMockClient({ cache, resolvers });
|
2020-09-04 08:08:27 -04:00
|
|
|
|
|
|
|
if (Array.isArray(handlers)) {
|
|
|
|
handlers.forEach(([query, value]) => mockClient.setRequestHandler(query, value));
|
|
|
|
} else {
|
|
|
|
throw new Error('You should pass an array of handlers to mock Apollo client');
|
|
|
|
}
|
|
|
|
|
|
|
|
const apolloProvider = new VueApollo({ defaultClient: mockClient });
|
|
|
|
|
|
|
|
return apolloProvider;
|
|
|
|
};
|