import { gql } from 'graphql-request' import { Label, labelFragment } from '../fragments/labelFragment' import { gqlFetcher } from '../networkHelpers' type SetLabelsResult = { setLabels: SetLabels } type SetLabels = { labels: Label[] errorCodes?: unknown[] } export async function setLabelsMutation( pageId: string, labelIds: string[] ): Promise { const mutation = gql` mutation SetLabels($input: SetLabelsInput!) { setLabels(input: $input) { ... on SetLabelsSuccess { labels { ...LabelFields } } ... on SetLabelsError { errorCodes } } } ${labelFragment} ` try { const data = (await gqlFetcher(mutation, { input: { pageId, labelIds }, })) as SetLabelsResult return data.setLabels.errorCodes ? undefined : data.setLabels.labels } catch (error) { console.log(' -- SetLabelsOutput error', error) return undefined } }