From 44c7d07d4c280344445315c72eeecdeb6bc2858d Mon Sep 17 00:00:00 2001 From: Cesare Naldi Date: Thu, 12 Dec 2024 17:40:06 +0100 Subject: [PATCH] chore: rename post fragments --- packages/graphql/src/enums.ts | 16 ++++ packages/graphql/src/fragments/post.ts | 103 ++++++++++++++----------- packages/graphql/src/graphql.ts | 4 +- packages/graphql/src/notifications.ts | 10 +-- packages/graphql/src/post.ts | 16 ++-- packages/graphql/src/timeline.ts | 6 +- 6 files changed, 93 insertions(+), 62 deletions(-) diff --git a/packages/graphql/src/enums.ts b/packages/graphql/src/enums.ts index fbd80f252..850357fff 100644 --- a/packages/graphql/src/enums.ts +++ b/packages/graphql/src/enums.ts @@ -24,3 +24,19 @@ export enum AccountReportReason { RepetitiveSpam = 'REPETITIVE_SPAM', Other = 'OTHER', } + +/** + * Enum for the different type of Post Actions. + */ +export enum PostActionType { + SimpleCollectAction = 'SIMPLE_COLLECT_ACTION', + UnknownAction = 'UNKNOWN_ACTION', +} + +/** + * Enum for the different types of reactions a user can have on a post. + */ +export enum PostReactionType { + Upvote = 'UPVOTE', + Downvote = 'DOWNVOTE', +} diff --git a/packages/graphql/src/fragments/post.ts b/packages/graphql/src/fragments/post.ts index 6e2642c76..1e0aa2aee 100644 --- a/packages/graphql/src/fragments/post.ts +++ b/packages/graphql/src/fragments/post.ts @@ -4,18 +4,16 @@ import { AccountFragment } from './account'; import { ActionInputInfo, Amount, BooleanValue, NetworkAddress } from './common'; import { App, Feed } from './primitives'; -export type PostActionType = ReturnType>; - -export const RecipientDataOutput = graphql( +export const RecipientDataOutputFragment = graphql( `fragment RecipientDataOutput on RecipientDataOutput { __typename recipient split }`, ); -export type RecipientDataOutput = FragmentOf; +export type RecipientDataOutput = FragmentOf; -export const SimpleCollectActionSettings = graphql( +export const SimpleCollectActionSettingsFragment = graphql( `fragment SimpleCollectActionSettings on SimpleCollectActionSettings { __typename contract { @@ -34,11 +32,13 @@ export const SimpleCollectActionSettings = graphql( ...RecipientDataOutput } }`, - [Amount, NetworkAddress, RecipientDataOutput], + [Amount, NetworkAddress, RecipientDataOutputFragment], ); -export type SimpleCollectActionSettings = FragmentOf; +export type SimpleCollectActionSettingsFragment = FragmentOf< + typeof SimpleCollectActionSettingsFragment +>; -export const UnknownActionSettings = graphql( +export const UnknownActionSettingsFragment = graphql( `fragment UnknownActionSettings on UnknownActionSettings { __typename initializeCalldata @@ -51,9 +51,9 @@ export const UnknownActionSettings = graphql( }`, [NetworkAddress], ); -export type UnknownActionSettings = FragmentOf; +export type UnknownActionSettings = FragmentOf; -export const PostAction = graphql( +export const PostActionFragment = graphql( `fragment PostAction on PostAction { ... on SimpleCollectActionSettings { ...SimpleCollectActionSettings @@ -62,21 +62,19 @@ export const PostAction = graphql( ...UnknownActionSettings } }`, - [SimpleCollectActionSettings, UnknownActionSettings], + [SimpleCollectActionSettingsFragment, UnknownActionSettingsFragment], ); -export type PostAction = FragmentOf; +export type PostAction = FragmentOf; // TODO add metadata fragments once problems with current schema are resolved -export const PostMetadata = graphql( +export const PostMetadataFragment = graphql( `fragment PostMetadata on PostMetadata { __typename }`, ); -export type PostMetadata = FragmentOf; - -export type PostReactionType = ReturnType>; +export type PostMetadata = FragmentOf; -export const LoggedInPostOperations = graphql( +export const LoggedInPostOperationsFragment = graphql( `fragment LoggedInPostOperations on LoggedInPostOperations { __typename id @@ -100,16 +98,16 @@ export const LoggedInPostOperations = graphql( }`, [BooleanValue], ); -export type LoggedInPostOperations = FragmentOf; +export type LoggedInPostOperations = FragmentOf; -export const PostReference = graphql( +export const PostReferenceFragment = graphql( `fragment PostReference on PostReference { id }`, ); -export type PostReference = FragmentOf; +export type PostReference = FragmentOf; -export const ReferencedPost = graphql( +export const ReferencedPostFragment = graphql( `fragment ReferencedPost on Post { __typename id @@ -134,10 +132,17 @@ export const ReferencedPost = graphql( } } `, - [AccountFragment, App, Feed, PostMetadata, PostAction, LoggedInPostOperations], + [ + AccountFragment, + App, + Feed, + PostMetadataFragment, + PostActionFragment, + LoggedInPostOperationsFragment, + ], ); -export const NestedPost = graphql( +export const NestedPostFragment = graphql( `fragment NestedPost on NestedPost { ...on Post { ...ReferencedPost @@ -146,11 +151,11 @@ export const NestedPost = graphql( ...PostReference } }`, - [PostReference, ReferencedPost], + [PostReferenceFragment, ReferencedPostFragment], ); -export type NestedPost = FragmentOf; +export type NestedPost = FragmentOf; -export const Post = graphql( +export const PostFragment = graphql( `fragment Post on Post { __typename id @@ -184,21 +189,29 @@ export const Post = graphql( } } `, - [AccountFragment, App, Feed, PostMetadata, PostAction, NestedPost, LoggedInPostOperations], + [ + AccountFragment, + App, + Feed, + PostMetadataFragment, + PostActionFragment, + NestedPostFragment, + LoggedInPostOperationsFragment, + ], ); -export type Post = FragmentOf; +export type Post = FragmentOf; // operations: LoggedInPostOperations -export const Repost = graphql( +export const RepostFragment = graphql( `fragment Repost on Repost { __typename id }`, [], ); -export type Repost = FragmentOf; +export type Repost = FragmentOf; -export const AnyPost = graphql( +export const AnyPostFragment = graphql( `fragment AnyPost on AnyPost { ...on Post { ...Post @@ -208,11 +221,11 @@ export const AnyPost = graphql( ...Repost } }`, - [Post, Repost], + [PostFragment, RepostFragment], ); -export type AnyPost = FragmentOf; +export type AnyPost = FragmentOf; -export const KnownAction = graphql( +export const KnownActionFragment = graphql( `fragment KnownAction on KnownAction { __typename name @@ -231,9 +244,9 @@ export const KnownAction = graphql( }`, [NetworkAddress, ActionInputInfo], ); -export type KnownAction = FragmentOf; +export type KnownAction = FragmentOf; -export const UnknownAction = graphql( +export const UnknownActionFragment = graphql( `fragment UnknownAction on UnknownAction { __typename name @@ -243,9 +256,9 @@ export const UnknownAction = graphql( }`, [NetworkAddress], ); -export type UnknownAction = FragmentOf; +export type UnknownAction = FragmentOf; -export const ActionInfo = graphql( +export const ActionInfoFragment = graphql( `fragment ActionInfo on ActionInfo { ... on KnownAction { ...KnownAction @@ -254,20 +267,20 @@ export const ActionInfo = graphql( ...UnknownAction } }`, - [KnownAction, UnknownAction], + [KnownActionFragment, UnknownActionFragment], ); -export type ActionInfo = FragmentOf; +export type ActionInfo = FragmentOf; -export const PostReaction = graphql( +export const PostReactionFragment = graphql( `fragment PostReaction on PostReaction { __typename reactedAt reaction }`, ); -export type PostReaction = FragmentOf; +export type PostReaction = FragmentOf; -export const AccountPostReaction = graphql( +export const AccountPostReactionFragment = graphql( `fragment AccountPostReaction on AccountPostReaction { __typename account { @@ -277,6 +290,6 @@ export const AccountPostReaction = graphql( ...PostReaction } }`, - [AccountFragment, PostReaction], + [AccountFragment, PostReactionFragment], ); -export type AccountPostReaction = FragmentOf; +export type AccountPostReaction = FragmentOf; diff --git a/packages/graphql/src/graphql.ts b/packages/graphql/src/graphql.ts index f6fbd2c87..d8db9f8d8 100644 --- a/packages/graphql/src/graphql.ts +++ b/packages/graphql/src/graphql.ts @@ -23,7 +23,7 @@ import { never, } from '@lens-protocol/types'; import { type DocumentDecoration, type FragmentOf, initGraphQLTada } from 'gql.tada'; -import type { AccountReportReason, PageSize } from './enums'; +import type { AccountReportReason, PageSize, PostActionType, PostReactionType } from './enums'; import type { introspection } from './graphql-env'; export const graphql = initGraphQLTada<{ @@ -46,6 +46,8 @@ export const graphql = initGraphQLTada<{ Int: number; LegacyProfileId: LegacyProfileId; LegacyRefreshToken: CompactJwt; + PostActionType: PostActionType; + PostReactionType: PostReactionType; PageSize: PageSize; PostId: PostId; RefreshToken: RefreshToken; diff --git a/packages/graphql/src/notifications.ts b/packages/graphql/src/notifications.ts index f7aa90b6b..a0b248628 100644 --- a/packages/graphql/src/notifications.ts +++ b/packages/graphql/src/notifications.ts @@ -1,5 +1,5 @@ import type { FragmentOf } from 'gql.tada'; -import { AccountFragment, PaginatedResultInfo, Post } from './fragments'; +import { AccountFragment, PaginatedResultInfo, PostFragment } from './fragments'; import { type RequestOf, graphql } from './graphql'; const FollowNotification = graphql( @@ -34,7 +34,7 @@ const ReactionNotification = graphql( ...Post } }`, - [AccountFragment, Post], + [AccountFragment, PostFragment], ); export type ReactionNotification = FragmentOf; @@ -46,7 +46,7 @@ const CommentNotification = graphql( ...Post } }`, - [Post], + [PostFragment], ); export type CommentNotification = FragmentOf; @@ -77,7 +77,7 @@ const QuoteNotification = graphql( ...Post } }`, - [Post], + [PostFragment], ); export type QuoteNotification = FragmentOf; @@ -89,7 +89,7 @@ const MentionNotification = graphql( ...Post } }`, - [Post], + [PostFragment], ); export type MentionNotification = FragmentOf; diff --git a/packages/graphql/src/post.ts b/packages/graphql/src/post.ts index 4fa8e3fb3..94db20047 100644 --- a/packages/graphql/src/post.ts +++ b/packages/graphql/src/post.ts @@ -1,8 +1,8 @@ import type { FragmentOf } from 'gql.tada'; import { - AccountPostReaction, - ActionInfo, - AnyPost, + AccountPostReactionFragment, + ActionInfoFragment, + AnyPostFragment, PaginatedResultInfo, SelfFundedTransactionRequest, SponsoredTransactionRequest, @@ -73,7 +73,7 @@ export const PostQuery = graphql( ...AnyPost } }`, - [AnyPost], + [AnyPostFragment], ); export type PostRequest = RequestOf; @@ -88,7 +88,7 @@ export const PostActionsQuery = graphql( } } }`, - [ActionInfo, PaginatedResultInfo], + [ActionInfoFragment, PaginatedResultInfo], ); export type PostActionsRequest = RequestOf; @@ -103,7 +103,7 @@ export const PostReactionsQuery = graphql( } } }`, - [AccountPostReaction, PaginatedResultInfo], + [AccountPostReactionFragment, PaginatedResultInfo], ); export type PostReactionsRequest = RequestOf; @@ -118,7 +118,7 @@ export const PostBookmarksQuery = graphql( } } }`, - [AnyPost, PaginatedResultInfo], + [AnyPostFragment, PaginatedResultInfo], ); export type PostBookmarksRequest = RequestOf; @@ -133,7 +133,7 @@ export const PostReferencesQuery = graphql( } } }`, - [AnyPost, PaginatedResultInfo], + [AnyPostFragment, PaginatedResultInfo], ); export type PostReferencesRequest = RequestOf; diff --git a/packages/graphql/src/timeline.ts b/packages/graphql/src/timeline.ts index 9ab08dd74..5206c97dc 100644 --- a/packages/graphql/src/timeline.ts +++ b/packages/graphql/src/timeline.ts @@ -1,5 +1,5 @@ import type { FragmentOf } from 'gql.tada'; -import { PaginatedResultInfo, Post } from './fragments'; +import { PaginatedResultInfo, PostFragment } from './fragments'; import { type RequestOf, graphql } from './graphql'; const TimelineItem = graphql( @@ -16,7 +16,7 @@ const TimelineItem = graphql( ...Post } }`, - [Post], + [PostFragment], ); export type TimelineItem = FragmentOf; @@ -48,6 +48,6 @@ export const TimelineHighlightsQuery = graphql( } } }`, - [Post, PaginatedResultInfo], + [PostFragment, PaginatedResultInfo], ); export type TimelineHighlightsRequest = RequestOf;