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

65 lines
1.6 KiB
JavaScript
Raw Normal View History

2021-09-04 01:27:46 +05:30
import { IntrospectionFragmentMatcher } from 'apollo-cache-inmemory';
2021-01-29 00:20:46 +05:30
import produce from 'immer';
2021-03-11 19:13:27 +05:30
import Vue from 'vue';
2021-01-29 00:20:46 +05:30
import VueApollo from 'vue-apollo';
import createDefaultClient from '~/lib/graphql';
2021-09-04 01:27:46 +05:30
import introspectionQueryResultData from './graphql/fragmentTypes.json';
2021-01-29 00:20:46 +05:30
import getCurrentIntegrationQuery from './graphql/queries/get_current_integration.query.graphql';
2021-09-04 01:27:46 +05:30
const fragmentMatcher = new IntrospectionFragmentMatcher({
introspectionQueryResultData,
});
2021-01-29 00:20:46 +05:30
Vue.use(VueApollo);
const resolvers = {
Mutation: {
updateCurrentIntegration: (
_,
2021-04-17 20:07:23 +05:30
{
id = null,
name,
active,
token,
type,
url,
apiUrl,
payloadExample,
payloadAttributeMappings,
payloadAlertFields,
},
2021-01-29 00:20:46 +05:30
{ cache },
) => {
const sourceData = cache.readQuery({ query: getCurrentIntegrationQuery });
2021-03-08 18:12:59 +05:30
const data = produce(sourceData, (draftData) => {
2021-01-29 00:20:46 +05:30
if (id === null) {
draftData.currentIntegration = null;
} else {
draftData.currentIntegration = {
id,
name,
active,
token,
type,
url,
apiUrl,
2021-04-17 20:07:23 +05:30
payloadExample,
payloadAttributeMappings,
payloadAlertFields,
2021-01-29 00:20:46 +05:30
};
}
});
cache.writeQuery({ query: getCurrentIntegrationQuery, data });
},
},
};
export default new VueApollo({
defaultClient: createDefaultClient(resolvers, {
2021-09-04 01:27:46 +05:30
cacheConfig: {
fragmentMatcher,
},
2021-01-29 00:20:46 +05:30
assumeImmutableResults: true,
}),
});