Update log_tree to use immutables

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