Commit be6c2db0 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch 'enable-specifying-cache-option-mock-apollo' into 'master'

Configure cache options for mock-apollo-client

See merge request gitlab-org/gitlab!56828
parents 9e20404b c3352754
......@@ -1437,6 +1437,34 @@ describe('My Index test with `createMockApollo`', () => {
});
```
When you need to configure the mocked apollo client's caching behavior,
provide additional cache options when creating a mocked client instance and the provided options will merge with the default cache option:
```javascript
const defaultCacheOptions = {
fragmentMatcher: { match: () => true },
addTypename: false,
};
```
```javascript
function createMockApolloProvider({ props = {}, requestHandlers } = {}) {
Vue.use(VueApollo);
const mockApollo = createMockApollo(
requestHandlers,
{},
{
dataIdFromObject: (object) =>
// eslint-disable-next-line no-underscore-dangle
object.__typename === 'Requirement' ? object.iid : defaultDataIdFromObject(object),
},
);
return mockApollo;
}
```
## Handling errors
The GitLab GraphQL mutations have two distinct error modes: [Top-level](#top-level-errors) and [errors-as-data](#errors-as-data).
......
......@@ -2,11 +2,15 @@ import { InMemoryCache } from 'apollo-cache-inmemory';
import { createMockClient } from 'mock-apollo-client';
import VueApollo from 'vue-apollo';
export default (handlers = [], resolvers = {}) => {
const fragmentMatcher = { match: () => true };
const defaultCacheOptions = {
fragmentMatcher: { match: () => true },
addTypename: false,
};
export default (handlers = [], resolvers = {}, cacheOptions = {}) => {
const cache = new InMemoryCache({
fragmentMatcher,
addTypename: false,
...defaultCacheOptions,
...cacheOptions,
});
const mockClient = createMockClient({ cache, resolvers });
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment