Files
omnivore/packages/web/lib/networking/mutations/updateHighlightMutation.ts
Jackson Harper 6daa599b76 Separate the mutations out of lower level components
This will let us handle the mutations differently on native
iOS and should help in avoiding making web calls directly from
the web view, so we can avoid CORs and introduce a caching
layer.
2022-03-22 13:58:39 -07:00

49 lines
983 B
TypeScript

import { gql } from 'graphql-request'
import { gqlFetcher } from '../networkHelpers'
export type UpdateHighlightInput = {
highlightId: string
annotation?: string
sharedAt?: string
}
type UpdateHighlightOutput = {
updateHighlight: HighlightOutput
}
type HighlightOutput = {
highlight: HighlightId
}
type HighlightId = {
id: string
}
export async function updateHighlightMutation(
input: UpdateHighlightInput
): Promise<string | undefined> {
const mutation = gql`
mutation UpdateHighlight($input: UpdateHighlightInput!) {
updateHighlight(input: $input) {
... on UpdateHighlightSuccess {
highlight {
id
}
}
... on UpdateHighlightError {
errorCodes
}
}
}
`
try {
const data = await gqlFetcher(mutation, { input })
const output = data as UpdateHighlightOutput | undefined
return output?.updateHighlight.highlight.id
} catch {
return undefined
}
}