omnivore/packages/web/lib/networking/mutations/deleteWebhookMutation.ts

40 lines
899 B
TypeScript
Raw Permalink Normal View History

2022-06-01 10:43:43 +00:00
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`
2024-07-09 01:42:18 +00:00
mutation DeleteWebhook($id: ID!) {
deleteWebhook(id: $id) {
2022-06-01 10:43:43 +00:00
... on DeleteWebhookSuccess {
webhook {
id
}
}
... on DeleteWebhookError {
errorCodes
}
}
}
`
try {
2024-07-09 01:42:18 +00:00
const data = (await gqlFetcher(mutation, { id })) as DeleteWebhookResult
2022-06-01 10:43:43 +00:00
return data.errorCodes ? undefined : data.deleteWebhook.webhook.id
} catch (error) {
console.log('deleteWebhookMutation error', error)
return undefined
}
}