From f3edb9ca7a82a1ebe325ee42e96546ea2419cf9a Mon Sep 17 00:00:00 2001 From: Jackson Harper Date: Thu, 24 Mar 2022 09:54:59 -0700 Subject: [PATCH] Reduce the data fetched when creating highlights This reduces the fields on the highlight type, and reduces what we fetch. We are doing this so its easier to bind from Swift and pass back simpler types for create/update/merge highlight operations --- .../web/lib/highlights/highlightGenerator.ts | 16 ++++++---- .../networking/fragments/highlightFragment.ts | 16 ---------- .../mutations/createHighlightMutation.ts | 31 ++----------------- .../mutations/mergeHighlightMutation.ts | 9 ------ 4 files changed, 13 insertions(+), 59 deletions(-) diff --git a/packages/web/lib/highlights/highlightGenerator.ts b/packages/web/lib/highlights/highlightGenerator.ts index 365f12367..3b2dfab1e 100644 --- a/packages/web/lib/highlights/highlightGenerator.ts +++ b/packages/web/lib/highlights/highlightGenerator.ts @@ -67,12 +67,16 @@ function nodeAttributesFromHighlight( const patch = highlight.patch const id = highlight.id const withNote = !!highlight.annotation - const customColor = !highlight.createdByMe - ? stringToColour(highlight.user.profile.username) - : undefined - const tooltip = !highlight.createdByMe - ? `Created by: @${highlight.user.profile.username}` - : undefined + const customColor = undefined + const tooltip = undefined + // We've disabled shared highlights, so passing undefined + // here now, and removing the user object from highlights + // !highlight.createdByMe + // ? stringToColour(highlight.user.profile.username) + // : undefined + // const tooltip = !highlight.createdByMe + // ? `Created by: @${highlight.user.profile.username}` + // : undefined return makeHighlightNodeAttributes(patch, id, withNote, customColor, tooltip) } diff --git a/packages/web/lib/networking/fragments/highlightFragment.ts b/packages/web/lib/networking/fragments/highlightFragment.ts index dd33cb455..2e8567bf5 100644 --- a/packages/web/lib/networking/fragments/highlightFragment.ts +++ b/packages/web/lib/networking/fragments/highlightFragment.ts @@ -9,18 +9,6 @@ export const highlightFragment = gql` suffix patch annotation - createdAt - updatedAt - sharedAt - user { - id - name - profile { - id - pictureUrl - username - } - } createdByMe } ` @@ -33,11 +21,7 @@ export type Highlight = { suffix?: string patch: string annotation?: string - createdAt: string - updatedAt: string - user: User createdByMe: boolean - sharedAt?: string } export type User = { diff --git a/packages/web/lib/networking/mutations/createHighlightMutation.ts b/packages/web/lib/networking/mutations/createHighlightMutation.ts index 364fb65d7..c0f9290e3 100644 --- a/packages/web/lib/networking/mutations/createHighlightMutation.ts +++ b/packages/web/lib/networking/mutations/createHighlightMutation.ts @@ -1,6 +1,6 @@ import { gql } from 'graphql-request' import { gqlFetcher } from '../networkHelpers' -import { Highlight } from './../fragments/highlightFragment' +import { Highlight, highlightFragment } from './../fragments/highlightFragment' export type CreateHighlightInput = { prefix: string @@ -28,7 +28,7 @@ export async function createHighlightMutation( createHighlight(input: $input) { ... on CreateHighlightSuccess { highlight { - ...NewHighlight + ...HighlightFields } } @@ -37,7 +37,7 @@ export async function createHighlightMutation( } } } - ${NewHighlightFragment} + ${highlightFragment} ` try { @@ -48,28 +48,3 @@ export async function createHighlightMutation( return undefined } } - -const NewHighlightFragment = gql` - fragment NewHighlight on Highlight { - id - shortId - quote - prefix - suffix - patch - createdAt - updatedAt - annotation - sharedAt - user { - id - name - profile { - id - pictureUrl - username - } - } - createdByMe - } -` diff --git a/packages/web/lib/networking/mutations/mergeHighlightMutation.ts b/packages/web/lib/networking/mutations/mergeHighlightMutation.ts index 76928de23..c157c28f8 100644 --- a/packages/web/lib/networking/mutations/mergeHighlightMutation.ts +++ b/packages/web/lib/networking/mutations/mergeHighlightMutation.ts @@ -41,15 +41,6 @@ export async function mergeHighlightMutation( updatedAt annotation sharedAt - user { - id - name - profile { - id - pictureUrl - username - } - } createdByMe } overlapHighlightIdList