diff options
Diffstat (limited to 'app/assets/javascripts/work_items/graphql')
8 files changed, 197 insertions, 1 deletions
diff --git a/app/assets/javascripts/work_items/graphql/local_update_work_item.mutation.graphql b/app/assets/javascripts/work_items/graphql/local_update_work_item.mutation.graphql new file mode 100644 index 00000000000..0d31ecef6f8 --- /dev/null +++ b/app/assets/javascripts/work_items/graphql/local_update_work_item.mutation.graphql @@ -0,0 +1,9 @@ +#import "./work_item.fragment.graphql" + +mutation localUpdateWorkItem($input: LocalWorkItemAssigneesInput) { + localUpdateWorkItem(input: $input) @client { + workItem { + ...WorkItem + } + } +} diff --git a/app/assets/javascripts/work_items/graphql/provider.js b/app/assets/javascripts/work_items/graphql/provider.js index 3c2955ce1e2..09d929faae2 100644 --- a/app/assets/javascripts/work_items/graphql/provider.js +++ b/app/assets/javascripts/work_items/graphql/provider.js @@ -1,11 +1,93 @@ +import produce from 'immer'; import Vue from 'vue'; import VueApollo from 'vue-apollo'; import createDefaultClient from '~/lib/graphql'; +import { WIDGET_TYPE_ASSIGNEE } from '../constants'; +import typeDefs from './typedefs.graphql'; +import workItemQuery from './work_item.query.graphql'; + +export const temporaryConfig = { + typeDefs, + cacheConfig: { + possibleTypes: { + LocalWorkItemWidget: ['LocalWorkItemAssignees'], + }, + typePolicies: { + WorkItem: { + fields: { + mockWidgets: { + read(widgets) { + return ( + widgets || [ + { + __typename: 'LocalWorkItemAssignees', + type: 'ASSIGNEES', + nodes: [ + { + __typename: 'UserCore', + id: 'gid://gitlab/User/1', + avatarUrl: '', + webUrl: '', + // eslint-disable-next-line @gitlab/require-i18n-strings + name: 'John Doe', + username: 'doe_I', + }, + { + __typename: 'UserCore', + id: 'gid://gitlab/User/2', + avatarUrl: '', + webUrl: '', + // eslint-disable-next-line @gitlab/require-i18n-strings + name: 'Marcus Rutherford', + username: 'ruthfull', + }, + ], + }, + { + __typename: 'LocalWorkItemWeight', + type: 'WEIGHT', + weight: 0, + }, + ] + ); + }, + }, + }, + }, + }, + }, +}; + +export const resolvers = { + Mutation: { + localUpdateWorkItem(_, { input }, { cache }) { + const sourceData = cache.readQuery({ + query: workItemQuery, + variables: { id: input.id }, + }); + + const data = produce(sourceData, (draftData) => { + const assigneesWidget = draftData.workItem.mockWidgets.find( + (widget) => widget.type === WIDGET_TYPE_ASSIGNEE, + ); + assigneesWidget.nodes = assigneesWidget.nodes.filter((assignee) => + input.assigneeIds.includes(assignee.id), + ); + }); + + cache.writeQuery({ + query: workItemQuery, + variables: { id: input.id }, + data, + }); + }, + }, +}; export function createApolloProvider() { Vue.use(VueApollo); - const defaultClient = createDefaultClient(); + const defaultClient = createDefaultClient(resolvers, temporaryConfig); return new VueApollo({ defaultClient, diff --git a/app/assets/javascripts/work_items/graphql/typedefs.graphql b/app/assets/javascripts/work_items/graphql/typedefs.graphql new file mode 100644 index 00000000000..bfe2f0fe0ce --- /dev/null +++ b/app/assets/javascripts/work_items/graphql/typedefs.graphql @@ -0,0 +1,36 @@ +enum LocalWidgetType { + ASSIGNEES + WEIGHT +} + +interface LocalWorkItemWidget { + type: LocalWidgetType! +} + +type LocalWorkItemAssignees implements LocalWorkItemWidget { + type: LocalWidgetType! + nodes: [UserCore] +} + +type LocalWorkItemWeight implements LocalWorkItemWidget { + type: LocalWidgetType! + weight: Int +} + +extend type WorkItem { + mockWidgets: [LocalWorkItemWidget] +} + +type LocalWorkItemAssigneesInput { + id: WorkItemID! + assigneeIds: [ID!] +} + +type LocalWorkItemPayload { + workItem: WorkItem! + errors: [String!] +} + +extend type Mutation { + localUpdateWorkItem(input: LocalWorkItemAssigneesInput!): LocalWorkItemPayload +} diff --git a/app/assets/javascripts/work_items/graphql/update_work_item_task.mutation.graphql b/app/assets/javascripts/work_items/graphql/update_work_item_task.mutation.graphql new file mode 100644 index 00000000000..470de060ee3 --- /dev/null +++ b/app/assets/javascripts/work_items/graphql/update_work_item_task.mutation.graphql @@ -0,0 +1,8 @@ +mutation workItemUpdateTask($input: WorkItemUpdateTaskInput!) { + workItemUpdate: workItemUpdateTask(input: $input) { + workItem { + id + descriptionHtml + } + } +} diff --git a/app/assets/javascripts/work_items/graphql/update_work_item_widgets.mutation.graphql b/app/assets/javascripts/work_items/graphql/update_work_item_widgets.mutation.graphql new file mode 100644 index 00000000000..148b340b439 --- /dev/null +++ b/app/assets/javascripts/work_items/graphql/update_work_item_widgets.mutation.graphql @@ -0,0 +1,10 @@ +#import "./work_item.fragment.graphql" + +mutation workItemUpdateWidgets($input: WorkItemUpdateWidgetsInput!) { + workItemUpdateWidgets(input: $input) { + workItem { + ...WorkItem + } + errors + } +} diff --git a/app/assets/javascripts/work_items/graphql/work_item.fragment.graphql b/app/assets/javascripts/work_items/graphql/work_item.fragment.graphql index e25fd102699..04701f6899e 100644 --- a/app/assets/javascripts/work_items/graphql/work_item.fragment.graphql +++ b/app/assets/javascripts/work_items/graphql/work_item.fragment.graphql @@ -11,4 +11,11 @@ fragment WorkItem on WorkItem { deleteWorkItem updateWorkItem } + widgets { + ... on WorkItemWidgetDescription { + type + description + descriptionHtml + } + } } diff --git a/app/assets/javascripts/work_items/graphql/work_item.query.graphql b/app/assets/javascripts/work_items/graphql/work_item.query.graphql index 3b46fed97ec..30bc61f5c59 100644 --- a/app/assets/javascripts/work_items/graphql/work_item.query.graphql +++ b/app/assets/javascripts/work_items/graphql/work_item.query.graphql @@ -3,5 +3,21 @@ query workItem($id: WorkItemID!) { workItem(id: $id) { ...WorkItem + mockWidgets @client { + ... on LocalWorkItemAssignees { + type + nodes { + id + avatarUrl + name + username + webUrl + } + } + ... on LocalWorkItemWeight { + type + weight + } + } } } diff --git a/app/assets/javascripts/work_items/graphql/work_item_links.query.graphql b/app/assets/javascripts/work_items/graphql/work_item_links.query.graphql new file mode 100644 index 00000000000..c2496f53cc8 --- /dev/null +++ b/app/assets/javascripts/work_items/graphql/work_item_links.query.graphql @@ -0,0 +1,28 @@ +query workItemQuery($id: WorkItemID!) { + workItem(id: $id) { + id + workItemType { + id + } + title + widgets { + type + ... on WorkItemWidgetHierarchy { + type + parent { + id + } + children { + nodes { + id + workItemType { + id + } + title + state + } + } + } + } + } +} |