1- import { GraphQLNonNull , GraphQLID , GraphQLString } from 'graphql'
1+ import { GraphQLNonNull , GraphQLID } from 'graphql'
22import { mutationWithClientMutationId , fromGlobalId } from 'graphql-relay'
33import { t } from '@lingui/macro'
44
5+ import { removeDomainUnion } from '../unions'
6+
57export const removeDomain = new mutationWithClientMutationId ( {
68 name : 'RemoveDomain' ,
79 description : 'This mutation allows the removal of unused domains.' ,
@@ -16,13 +18,11 @@ export const removeDomain = new mutationWithClientMutationId({
1618 } ,
1719 } ) ,
1820 outputFields : ( ) => ( {
19- status : {
20- type : GraphQLNonNull ( GraphQLString ) ,
21+ result : {
22+ type : GraphQLNonNull ( removeDomainUnion ) ,
2123 description :
22- 'Status string to inform the user if the domain was successfully removed.' ,
23- resolve : async ( payload ) => {
24- return payload . status
25- } ,
24+ '`RemoveDomainUnion` returning either a `DomainResultType`, or `DomainErrorType` object.' ,
25+ resolve : ( payload ) => payload ,
2626 } ,
2727 } ) ,
2828 mutateAndGetPayload : async (
@@ -55,7 +55,11 @@ export const removeDomain = new mutationWithClientMutationId({
5555 console . warn (
5656 `User: ${ userKey } attempted to remove ${ domainId } however no domain is associated with that id.` ,
5757 )
58- throw new Error ( i18n . _ ( t `Unable to remove unknown domain.` ) )
58+ return {
59+ _type : 'error' ,
60+ code : 400 ,
61+ description : i18n . _ ( t `Unable to remove unknown domain.` ) ,
62+ }
5963 }
6064
6165 // Get Org from db
@@ -66,9 +70,13 @@ export const removeDomain = new mutationWithClientMutationId({
6670 console . warn (
6771 `User: ${ userKey } attempted to remove ${ domain . slug } in org: ${ orgId } however there is no organization associated with that id.` ,
6872 )
69- throw new Error (
70- i18n . _ ( t `Unable to remove domain from unknown organization.` ) ,
71- )
73+ return {
74+ _type : 'error' ,
75+ code : 400 ,
76+ description : i18n . _ (
77+ t `Unable to remove domain from unknown organization.` ,
78+ ) ,
79+ }
7280 }
7381
7482 // Get permission
@@ -79,22 +87,26 @@ export const removeDomain = new mutationWithClientMutationId({
7987 console . warn (
8088 `User: ${ userKey } attempted to remove ${ domain . slug } in ${ org . slug } but does not have permission to remove a domain from a verified check org.` ,
8189 )
82- throw new Error (
83- i18n . _ (
90+ return {
91+ _type : 'error' ,
92+ code : 403 ,
93+ description : i18n . _ (
8494 t `Permission Denied: Please contact super admin for help with removing domain.` ,
8595 ) ,
86- )
96+ }
8797 }
8898
8999 if ( permission !== 'super_admin' && permission !== 'admin' ) {
90100 console . warn (
91101 `User: ${ userKey } attempted to remove ${ domain . slug } in ${ org . slug } however they do not have permission in that org.` ,
92102 )
93- throw new Error (
94- i18n . _ (
103+ return {
104+ _type : 'error' ,
105+ code : 403 ,
106+ description : i18n . _ (
95107 t `Permission Denied: Please contact organization admin for help with removing domain.` ,
96108 ) ,
97- )
109+ }
98110 }
99111
100112 // Check to see if more than one organization has a claim to this domain
@@ -241,6 +253,7 @@ export const removeDomain = new mutationWithClientMutationId({
241253 `User: ${ userKey } successfully removed domain: ${ domain . slug } from org: ${ org . slug } .` ,
242254 )
243255 return {
256+ _type : 'result' ,
244257 status : i18n . _ (
245258 t `Successfully removed domain: ${ domain . slug } from ${ org . slug } .` ,
246259 ) ,
0 commit comments