Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
export function createMockClient(handlers = [], resolvers = {}, cacheOptions = {}) {
const cache = new InMemoryCache({
...defaultCacheOptions,
...cacheOptions,
});
const mockClient = createMockApolloClient({ cache, resolvers });
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');
}
return mockClient;
}
const createClient = (extraResolverArgs) => {
return createMockClient({
cache: new InMemoryCache({
fragmentMatcher: { match: () => true },
addTypename: false,
}),
resolvers: createResolvers({ endpoints: FAKE_ENDPOINTS, ...extraResolverArgs }),
});
};
{
query: getSearchBuilder({
type: SearchType.REVIEWS,
sort: SearchSort.SALARY,
}),
handler: (params: ISearchQueryParams) =>
Promise.resolve({
data: getMockAllSearch(params, {
type: SearchType.REVIEWS,
sort: SearchSort.SALARY,
}),
}),
},
];
const mockClient = createMockClient();
export default mockClient;
API_CALLS.forEach(call => {
mockClient.setRequestHandler(call.query, call.handler);
});