Add setWebhook mutation

This commit is contained in:
Hongbo Wu
2022-06-01 21:08:13 +08:00
parent 4b4783b9b5
commit c83f9290e6

View File

@ -0,0 +1,43 @@
import { gql } from 'graphql-request'
import { gqlFetcher } from '../networkHelpers'
import { Webhook, WebhookEvent } from '../queries/useGetWebhooksQuery'
interface SetWebhookResult {
setWebhook: SetWebhook
errorCodes?: unknown[]
}
type SetWebhook = {
webhook: Webhook
}
export async function setWebhookMutation(
id: string,
url: string,
eventTypes: WebhookEvent[]
): Promise<any | undefined> {
const mutation = gql`
mutation SetWebhook($input: SetWebhookInput!) {
setWebhook(input: $input) {
... on SetWebhookSuccess {
webhook {
id
}
}
... on SetWebhookError {
errorCodes
}
}
}
`
try {
const data = (await gqlFetcher(mutation, {
input: { id, url, eventTypes },
})) as SetWebhookResult
return data.errorCodes ? undefined : data.setWebhook.webhook.id
} catch (error) {
console.log('setWebhookMutation error', error)
return undefined
}
}