debian-mirror-gitlab/spec/frontend/__helpers__/mock_apollo_helper.js

24 lines
716 B
JavaScript
Raw Normal View History

2020-11-24 15:15:51 +05:30
import { InMemoryCache } from 'apollo-cache-inmemory';
import { createMockClient } from 'mock-apollo-client';
import VueApollo from 'vue-apollo';
2021-01-29 00:20:46 +05:30
export default (handlers = [], resolvers = {}) => {
2020-11-24 15:15:51 +05:30
const fragmentMatcher = { match: () => true };
const cache = new InMemoryCache({
fragmentMatcher,
addTypename: false,
});
2021-01-29 00:20:46 +05:30
const mockClient = createMockClient({ cache, resolvers });
2020-11-24 15:15:51 +05:30
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;
};