mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Add setLabelsForHighlight mutation
This commit is contained in:
parent
009cd59628
commit
ed14ac910c
1 changed files with 43 additions and 0 deletions
|
|
@ -0,0 +1,43 @@
|
|||
import { gql } from 'graphql-request'
|
||||
import { Label, labelFragment } from '../fragments/labelFragment'
|
||||
import { gqlFetcher } from '../networkHelpers'
|
||||
|
||||
export type SetLabelsForHighlightResult = {
|
||||
setLabelsForHighlight: SetLabelsForHighlight
|
||||
errorCodes?: unknown[]
|
||||
}
|
||||
|
||||
type SetLabelsForHighlight = {
|
||||
labels: Label[]
|
||||
}
|
||||
|
||||
export async function setLabelsForHighlight(
|
||||
highlightId: string,
|
||||
labelIds: string[]
|
||||
): Promise<Label[] | undefined> {
|
||||
const mutation = gql`
|
||||
mutation SetLabelsForHighlight($input: SetLabelsForHighlightInput!) {
|
||||
setLabelsForHighlight(input: $input) {
|
||||
... on SetLabelsSuccess {
|
||||
labels {
|
||||
...LabelFields
|
||||
}
|
||||
}
|
||||
... on SetLabelsError {
|
||||
errorCodes
|
||||
}
|
||||
}
|
||||
}
|
||||
${labelFragment}
|
||||
`
|
||||
|
||||
try {
|
||||
const data = (await gqlFetcher(mutation, {
|
||||
input: { highlightId, labelIds },
|
||||
})) as SetLabelsForHighlightResult
|
||||
return data.errorCodes ? undefined : data.setLabelsForHighlight.labels
|
||||
} catch (error) {
|
||||
console.log('setLabelsForHighlightInput error', error)
|
||||
return undefined
|
||||
}
|
||||
}
|
||||
Loading…
Reference in a new issue