Commit 09a11d98 authored by Natalia Tepluhina's avatar Natalia Tepluhina

Merge branch...

Merge branch '331113-refactor-snippets-application-to-update-apollo-cache-in-immutable-way' into 'master'

Refactor Snippets application to update Apollo cache in immutable way

See merge request gitlab-org/gitlab!62008
parents 51a0c8a7 b04374d5
......@@ -29,15 +29,6 @@ export default {
update(data) {
return this.onContentUpdate(data);
},
result() {
if (this.activeViewerType === RICH_BLOB_VIEWER) {
// eslint-disable-next-line vue/no-mutating-props
this.blob.richViewer.renderError = null;
} else {
// eslint-disable-next-line vue/no-mutating-props
this.blob.simpleViewer.renderError = null;
}
},
skip() {
return this.viewer.renderError;
},
......
......@@ -14,7 +14,13 @@ export default function appFactory(el, Component) {
}
const apolloProvider = new VueApollo({
defaultClient: createDefaultClient({}, { batchMax: 1 }),
defaultClient: createDefaultClient(
{},
{
batchMax: 1,
assumeImmutableResults: true,
},
),
});
const {
......
import { isEmpty } from 'lodash';
import GetSnippetQuery from 'shared_queries/snippet/snippet.query.graphql';
const blobsDefault = [];
......@@ -12,20 +13,18 @@ export const getSnippetMixin = {
};
},
update(data) {
const res = data.snippets.nodes[0];
const res = { ...data.snippets.nodes[0] };
// Set `snippet.blobs` since some child components are coupled to this.
if (res) {
if (!isEmpty(res)) {
// It's possible for us to not get any blobs in a response.
// In this case, we should default to current blobs.
res.blobs = res.blobs ? res.blobs.nodes : this.blobs;
res.blobs = res.blobs ? res.blobs.nodes : blobsDefault;
res.description = res.description || '';
}
return res;
},
result(res) {
this.blobs = res.data.snippets.nodes[0]?.blobs || blobsDefault;
},
skip() {
return this.newSnippet;
},
......@@ -41,12 +40,14 @@ export const getSnippetMixin = {
return {
snippet: {},
newSnippet: !this.snippetGid,
blobs: blobsDefault,
};
},
computed: {
isLoading() {
return this.$apollo.queries.snippet.loading;
},
blobs() {
return this.snippet?.blobs || [];
},
},
};
......@@ -71,7 +71,9 @@ describe('Snippet view app', () => {
it('renders correct snippet-blob components', () => {
createComponent({
data: {
blobs: [Blob, BinaryBlob],
snippet: {
blobs: [Blob, BinaryBlob],
},
},
});
const blobs = wrapper.findAll(SnippetBlob);
......
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