debian-mirror-gitlab/app/assets/javascripts/repository/graphql.js

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

64 lines
1.8 KiB
JavaScript
Raw Normal View History

2019-09-04 21:01:54 +05:30
import Vue from 'vue';
import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql';
2021-03-11 19:13:27 +05:30
import axios from '~/lib/utils/axios_utils';
2019-09-30 21:07:59 +05:30
import { fetchLogsTree } from './log_tree';
2019-09-04 21:01:54 +05:30
Vue.use(VueApollo);
const defaultClient = createDefaultClient(
2019-09-30 21:07:59 +05:30
{
Query: {
2021-09-04 01:27:46 +05:30
commit(_, { path, fileName, type, maxOffset }) {
2021-03-08 18:12:59 +05:30
return new Promise((resolve) => {
2021-09-04 01:27:46 +05:30
fetchLogsTree(
defaultClient,
path,
'0',
{
resolve,
entry: {
name: fileName,
type,
},
2019-09-30 21:07:59 +05:30
},
2021-09-04 01:27:46 +05:30
maxOffset,
);
2019-09-30 21:07:59 +05:30
});
},
2019-12-26 22:10:19 +05:30
readme(_, { url }) {
return axios
2020-07-28 23:09:34 +05:30
.get(url, { params: { format: 'json', viewer: 'rich' } })
2019-12-26 22:10:19 +05:30
.then(({ data }) => ({ ...data, __typename: 'ReadmeFile' }));
},
2019-09-30 21:07:59 +05:30
},
},
2019-09-04 21:01:54 +05:30
{
cacheConfig: {
2021-03-08 18:12:59 +05:30
dataIdFromObject: (obj) => {
2020-04-22 19:07:51 +05:30
/* eslint-disable @gitlab/require-i18n-strings */
2019-09-04 21:01:54 +05:30
// eslint-disable-next-line no-underscore-dangle
switch (obj.__typename) {
// We need to create a dynamic ID for each entry
// Each entry can have the same ID as the ID is a commit ID
// So we create a unique cache ID with the path and the ID
case 'TreeEntry':
case 'Submodule':
case 'Blob':
2020-04-22 19:07:51 +05:30
return `${encodeURIComponent(obj.flatPath)}-${obj.id}`;
2019-09-04 21:01:54 +05:30
default:
// If the type doesn't match any of the above we fallback
// to using the default Apollo ID
// eslint-disable-next-line no-underscore-dangle
return obj.id || obj._id;
}
2020-04-22 19:07:51 +05:30
/* eslint-enable @gitlab/require-i18n-strings */
2019-09-04 21:01:54 +05:30
},
},
},
);
export default new VueApollo({
defaultClient,
});