Files
omnivore/packages/web/lib/networking/mutations/deleteWebhookMutation.ts
2022-06-01 18:43:43 +08:00

40 lines
871 B
TypeScript

import { gql } from 'graphql-request'
import { gqlFetcher } from '../networkHelpers'
import { Webhook } from '../queries/useGetWebhooksQuery'
interface DeleteWebhookResult {
deleteWebhook: DeleteWebhook
errorCodes?: unknown[]
}
type DeleteWebhook = {
webhook: Webhook
}
export async function deleteWebhookMutation(
id: string
): Promise<any | undefined> {
const mutation = gql`
mutation {
deleteWebhook(id: "${id}") {
... on DeleteWebhookSuccess {
webhook {
id
}
}
... on DeleteWebhookError {
errorCodes
}
}
}
`
try {
const data = (await gqlFetcher(mutation)) as DeleteWebhookResult
return data.errorCodes ? undefined : data.deleteWebhook.webhook.id
} catch (error) {
console.log('deleteWebhookMutation error', error)
return undefined
}
}