Add get webhook query in web
This commit is contained in:
62
packages/web/lib/networking/queries/useGetWebhookQuery.tsx
Normal file
62
packages/web/lib/networking/queries/useGetWebhookQuery.tsx
Normal file
@ -0,0 +1,62 @@
|
||||
import { gql } from 'graphql-request'
|
||||
import useSWR from 'swr'
|
||||
import { makeGqlFetcher } from '../networkHelpers'
|
||||
import { Webhook } from './useGetWebhooksQuery'
|
||||
|
||||
interface WebhookQueryResponse {
|
||||
isValidating?: boolean
|
||||
webhook?: Webhook
|
||||
revalidate?: () => void
|
||||
}
|
||||
|
||||
interface WebhookQueryResponseData {
|
||||
webhook: WebhookData
|
||||
}
|
||||
|
||||
interface WebhookData {
|
||||
webhook: unknown
|
||||
}
|
||||
|
||||
export function useGetWebhookQuery(id: string): WebhookQueryResponse {
|
||||
const query = gql`
|
||||
query GetWebhook($id: ID!) {
|
||||
webhook(id: $id) {
|
||||
... on WebhookSuccess {
|
||||
webhook {
|
||||
id
|
||||
url
|
||||
eventTypes
|
||||
contentType
|
||||
method
|
||||
enabled
|
||||
createdAt
|
||||
updatedAt
|
||||
}
|
||||
}
|
||||
... on WebhookError {
|
||||
errorCodes
|
||||
}
|
||||
}
|
||||
}
|
||||
`
|
||||
|
||||
const { data, mutate, isValidating } = useSWR(query, makeGqlFetcher({ id }))
|
||||
console.log('webhook data', data)
|
||||
|
||||
try {
|
||||
if (data) {
|
||||
const result = data as WebhookQueryResponseData
|
||||
const webhook = result.webhook.webhook as Webhook
|
||||
return {
|
||||
isValidating,
|
||||
webhook,
|
||||
revalidate: () => {
|
||||
mutate()
|
||||
},
|
||||
}
|
||||
}
|
||||
} catch (error) {
|
||||
console.log('error', error)
|
||||
}
|
||||
return {}
|
||||
}
|
||||
Reference in New Issue
Block a user