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

54 lines
1.2 KiB
JavaScript
Raw Normal View History

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';
import getCurrentIntegrationQuery from './graphql/queries/get_current_integration.query.graphql';
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({
2022-04-04 11:22:00 +05:30
defaultClient: createDefaultClient(resolvers),
2021-01-29 00:20:46 +05:30
});