From ed14ac910c4b8f08260e6a1358de2113a8356954 Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Fri, 2 Dec 2022 16:23:23 +0800 Subject: [PATCH] Add setLabelsForHighlight mutation --- .../mutations/setLabelsForHighlight.ts | 43 +++++++++++++++++++ 1 file changed, 43 insertions(+) create mode 100644 packages/web/lib/networking/mutations/setLabelsForHighlight.ts diff --git a/packages/web/lib/networking/mutations/setLabelsForHighlight.ts b/packages/web/lib/networking/mutations/setLabelsForHighlight.ts new file mode 100644 index 000000000..e926314d3 --- /dev/null +++ b/packages/web/lib/networking/mutations/setLabelsForHighlight.ts @@ -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 { + 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 + } +}