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,24 +100,28 @@ describe('fetchLogsTree', () => { ...@@ -100,24 +100,28 @@ 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: {
commits: [ projectPath: 'gitlab-org/gitlab-foss',
expect.objectContaining({ escapedRef: 'master',
__typename: 'LogTreeCommit', commits: [
commitPath: 'https://test.com', expect.objectContaining({
committedDate: '2019-01-01', __typename: 'LogTreeCommit',
fileName: 'index.js', commitPath: 'https://test.com',
filePath: '/index.js', committedDate: '2019-01-01',
message: 'testing message', fileName: 'index.js',
sha: '123', filePath: '/index.js',
type: 'blob', lockLabel: false,
}), message: 'testing message',
], sha: '123',
}, titleHtml: undefined,
}); 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