2019-05-20 04:41:28 -04:00
|
|
|
import Vue from 'vue';
|
|
|
|
import VueApollo from 'vue-apollo';
|
2019-05-24 05:39:18 -04:00
|
|
|
import { IntrospectionFragmentMatcher } from 'apollo-cache-inmemory';
|
2019-11-07 13:06:21 -05:00
|
|
|
import axios from '~/lib/utils/axios_utils';
|
2019-05-20 04:41:28 -04:00
|
|
|
import createDefaultClient from '~/lib/graphql';
|
2019-05-24 05:39:18 -04:00
|
|
|
import introspectionQueryResultData from './fragmentTypes.json';
|
2019-06-25 10:26:55 -04:00
|
|
|
import { fetchLogsTree } from './log_tree';
|
2019-05-20 04:41:28 -04:00
|
|
|
|
|
|
|
Vue.use(VueApollo);
|
|
|
|
|
2019-05-24 05:39:18 -04:00
|
|
|
// We create a fragment matcher so that we can create a fragment from an interface
|
|
|
|
// Without this, Apollo throws a heuristic fragment matcher warning
|
|
|
|
const fragmentMatcher = new IntrospectionFragmentMatcher({
|
|
|
|
introspectionQueryResultData,
|
|
|
|
});
|
|
|
|
|
|
|
|
const defaultClient = createDefaultClient(
|
2019-06-25 10:26:55 -04:00
|
|
|
{
|
|
|
|
Query: {
|
|
|
|
commit(_, { path, fileName, type }) {
|
|
|
|
return new Promise(resolve => {
|
|
|
|
fetchLogsTree(defaultClient, path, '0', {
|
|
|
|
resolve,
|
|
|
|
entry: {
|
|
|
|
name: fileName,
|
|
|
|
type,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
});
|
|
|
|
},
|
2019-11-07 13:06:21 -05:00
|
|
|
readme(_, { url }) {
|
|
|
|
return axios
|
2020-06-23 14:09:28 -04:00
|
|
|
.get(url, { params: { format: 'json', viewer: 'rich' } })
|
2019-11-07 13:06:21 -05:00
|
|
|
.then(({ data }) => ({ ...data, __typename: 'ReadmeFile' }));
|
|
|
|
},
|
2019-06-25 10:26:55 -04:00
|
|
|
},
|
|
|
|
},
|
2019-05-24 05:39:18 -04:00
|
|
|
{
|
|
|
|
cacheConfig: {
|
|
|
|
fragmentMatcher,
|
|
|
|
dataIdFromObject: obj => {
|
2020-03-18 11:09:45 -04:00
|
|
|
/* eslint-disable @gitlab/require-i18n-strings */
|
2019-05-24 05:39:18 -04:00
|
|
|
// 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-21 11:21:10 -04:00
|
|
|
return `${encodeURIComponent(obj.flatPath)}-${obj.id}`;
|
2019-05-24 05:39:18 -04:00
|
|
|
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-03-18 11:09:45 -04:00
|
|
|
/* eslint-enable @gitlab/require-i18n-strings */
|
2019-05-24 05:39:18 -04:00
|
|
|
},
|
2019-05-16 04:18:52 -04:00
|
|
|
},
|
|
|
|
},
|
2019-05-24 05:39:18 -04:00
|
|
|
);
|
2019-05-20 04:41:28 -04:00
|
|
|
|
|
|
|
export default new VueApollo({
|
|
|
|
defaultClient,
|
|
|
|
});
|