Update log_tree to use immutables

- graphql config
- log_tree update
- test adjustments
parent cc86d001
...@@ -58,6 +58,7 @@ const defaultClient = createDefaultClient( ...@@ -58,6 +58,7 @@ const defaultClient = createDefaultClient(
/* eslint-enable @gitlab/require-i18n-strings */ /* eslint-enable @gitlab/require-i18n-strings */
}, },
}, },
assumeImmutableResults: true,
}, },
); );
......
import produce from 'immer';
import { normalizeData } from 'ee_else_ce/repository/utils/commit'; import { normalizeData } from 'ee_else_ce/repository/utils/commit';
import axios from '~/lib/utils/axios_utils'; import axios from '~/lib/utils/axios_utils';
import commitsQuery from './queries/commits.query.graphql'; import commitsQuery from './queries/commits.query.graphql';
...@@ -34,16 +35,18 @@ export function fetchLogsTree(client, path, offset, resolver = null) { ...@@ -34,16 +35,18 @@ export function fetchLogsTree(client, path, offset, resolver = null) {
params: { format: 'json', offset }, params: { format: 'json', offset },
}, },
) )
.then(({ data, headers }) => { .then(({ data: newData, headers }) => {
const headerLogsOffset = headers['more-logs-offset']; const headerLogsOffset = headers['more-logs-offset'];
const { commits } = client.readQuery({ query: commitsQuery }); const sourceData = client.readQuery({ query: commitsQuery });
const newCommitData = [...commits, ...normalizeData(data, path)]; const data = produce(sourceData, draftState => {
draftState.commits.push(...normalizeData(newData, path));
});
client.writeQuery({ client.writeQuery({
query: commitsQuery, query: commitsQuery,
data: { commits: newCommitData }, data,
}); });
resolvers.forEach(r => resolveCommit(newCommitData, path, r)); resolvers.forEach(r => resolveCommit(data.commits, path, r));
fetchpromise = null; fetchpromise = null;
......
...@@ -100,11 +100,13 @@ describe('fetchLogsTree', () => { ...@@ -100,11 +100,13 @@ describe('fetchLogsTree', () => {
); );
})); }));
it('writes query to client', () => it('writes query to client', async () => {
fetchLogsTree(client, '', '0', resolver).then(() => { await fetchLogsTree(client, '', '0', resolver);
expect(client.writeQuery).toHaveBeenCalledWith({ expect(client.writeQuery).toHaveBeenCalledWith({
query: expect.anything(), query: expect.anything(),
data: { data: {
projectPath: 'gitlab-org/gitlab-foss',
escapedRef: 'master',
commits: [ commits: [
expect.objectContaining({ expect.objectContaining({
__typename: 'LogTreeCommit', __typename: 'LogTreeCommit',
...@@ -112,12 +114,14 @@ describe('fetchLogsTree', () => { ...@@ -112,12 +114,14 @@ describe('fetchLogsTree', () => {
committedDate: '2019-01-01', committedDate: '2019-01-01',
fileName: 'index.js', fileName: 'index.js',
filePath: '/index.js', filePath: '/index.js',
lockLabel: false,
message: 'testing message', message: 'testing message',
sha: '123', sha: '123',
titleHtml: undefined,
type: 'blob', type: 'blob',
}), }),
], ],
}, },
}); });
})); });
}); });
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