debian-mirror-gitlab/app/assets/javascripts/graphql_shared/issuable_client.js

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

68 lines
2 KiB
JavaScript
Raw Normal View History

2022-07-23 23:45:48 +05:30
import produce from 'immer';
2021-12-11 22:18:48 +05:30
import VueApollo from 'vue-apollo';
2023-01-13 00:05:48 +05:30
import { defaultDataIdFromObject } from '@apollo/client/core';
2022-10-11 01:57:18 +05:30
import { concatPagination } from '@apollo/client/utilities';
import getIssueStateQuery from '~/issues/show/queries/get_issue_state.query.graphql';
2021-12-11 22:18:48 +05:30
import createDefaultClient from '~/lib/graphql';
2022-10-11 01:57:18 +05:30
import typeDefs from '~/work_items/graphql/typedefs.graphql';
2022-07-23 23:45:48 +05:30
2023-01-13 00:05:48 +05:30
export const config = {
2022-07-23 23:45:48 +05:30
typeDefs,
cacheConfig: {
2023-01-13 00:05:48 +05:30
// included temporarily until Vuex is removed from boards app
dataIdFromObject: (object) => {
// eslint-disable-next-line no-underscore-dangle
return object.__typename === 'BoardList' ? object.iid : defaultDataIdFromObject(object);
2022-07-23 23:45:48 +05:30
},
typePolicies: {
2022-10-11 01:57:18 +05:30
Project: {
fields: {
projectMembers: {
keyArgs: ['fullPath', 'search', 'relations', 'first'],
},
},
},
2022-07-23 23:45:48 +05:30
WorkItem: {
fields: {
2022-08-27 11:52:29 +05:30
widgets: {
2022-11-25 23:54:43 +05:30
merge(existing = [], incoming) {
if (existing.length === 0) {
return incoming;
}
return existing.map((existingWidget) => {
2023-01-13 00:05:48 +05:30
const incomingWidget = incoming.find(
(w) => w.type && w.type === existingWidget.type,
);
2022-11-25 23:54:43 +05:30
return incomingWidget || existingWidget;
});
2022-08-27 11:52:29 +05:30
},
},
2022-07-23 23:45:48 +05:30
},
},
2022-10-11 01:57:18 +05:30
MemberInterfaceConnection: {
fields: {
nodes: concatPagination(),
},
},
2022-07-23 23:45:48 +05:30
},
},
};
export const resolvers = {
Mutation: {
2022-10-11 01:57:18 +05:30
updateIssueState: (_, { issueType = undefined, isDirty = false }, { cache }) => {
const sourceData = cache.readQuery({ query: getIssueStateQuery });
const data = produce(sourceData, (draftData) => {
draftData.issueState = { issueType, isDirty };
});
cache.writeQuery({ query: getIssueStateQuery, data });
},
2022-07-23 23:45:48 +05:30
},
};
2021-12-11 22:18:48 +05:30
2023-01-13 00:05:48 +05:30
export const defaultClient = createDefaultClient(resolvers, config);
2021-12-11 22:18:48 +05:30
2022-10-11 01:57:18 +05:30
export const apolloProvider = new VueApollo({
defaultClient,
});