Commit 5020ec91 authored by Martin Wortschack's avatar Martin Wortschack

Merge branch...

Merge branch '32085-fe-improve-documentation-and-static-checks-regarding-mutation-errors-conventions' into 'master'

Ensure all mutations have 'errors' field and a proper handler

See merge request gitlab-org/gitlab!27328
parents 77885f3a 9850207b
mutation ($projectPath: ID!, $iid: String!, $healthStatus: HealthStatus) { mutation($projectPath: ID!, $iid: String!, $healthStatus: HealthStatus) {
updateIssue(input: { projectPath: $projectPath, iid: $iid, healthStatus: $healthStatus}) { updateIssue(input: { projectPath: $projectPath, iid: $iid, healthStatus: $healthStatus }) {
issue { issue {
healthStatus healthStatus
} }
errors
} }
} }
...@@ -137,7 +137,10 @@ export default { ...@@ -137,7 +137,10 @@ export default {
mutation: DeleteSnippetMutation, mutation: DeleteSnippetMutation,
variables: { id: this.snippet.id }, variables: { id: this.snippet.id },
}) })
.then(() => { .then(({ data }) => {
if (data?.destroySnippet?.errors) {
throw new Error(data?.destroySnippet?.errors[0]);
}
this.isDeleting = false; this.isDeleting = false;
this.errorMessage = undefined; this.errorMessage = undefined;
this.closeDeleteModal(); this.closeDeleteModal();
......
...@@ -33,7 +33,12 @@ export default class SidebarMediator extends CESidebarMediator { ...@@ -33,7 +33,12 @@ export default class SidebarMediator extends CESidebarMediator {
this.store.setFetchingState('status', true); this.store.setFetchingState('status', true);
return this.service return this.service
.updateWithGraphQl(updateStatusMutation, { healthStatus }) .updateWithGraphQl(updateStatusMutation, { healthStatus })
.then(({ data }) => this.store.setStatus(data?.updateIssue?.issue?.healthStatus)) .then(({ data }) => {
if (data?.updateIssue?.errors?.length > 0) {
throw data.updateIssue.errors[0];
}
this.store.setStatus(data?.updateIssue?.issue?.healthStatus);
})
.catch(error => { .catch(error => {
throw error; throw error;
}) })
......
...@@ -32,7 +32,7 @@ describe('Snippet header component', () => { ...@@ -32,7 +32,7 @@ describe('Snippet header component', () => {
const errorMsg = 'Foo bar'; const errorMsg = 'Foo bar';
const err = { message: errorMsg }; const err = { message: errorMsg };
const resolveMutate = jest.fn(() => Promise.resolve()); const resolveMutate = jest.fn(() => Promise.resolve({ data: {} }));
const rejectMutation = jest.fn(() => Promise.reject(err)); const rejectMutation = jest.fn(() => Promise.reject(err));
const mutationTypes = { const mutationTypes = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment