Skip to content

Commit

Permalink
chore: rename post fragments
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarenaldi committed Dec 12, 2024
1 parent 38c22ff commit 44c7d07
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 62 deletions.
16 changes: 16 additions & 0 deletions packages/graphql/src/enums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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',
}
103 changes: 58 additions & 45 deletions packages/graphql/src/fragments/post.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,16 @@ import { AccountFragment } from './account';
import { ActionInputInfo, Amount, BooleanValue, NetworkAddress } from './common';
import { App, Feed } from './primitives';

export type PostActionType = ReturnType<typeof graphql.scalar<'PostActionType'>>;

export const RecipientDataOutput = graphql(
export const RecipientDataOutputFragment = graphql(
`fragment RecipientDataOutput on RecipientDataOutput {
__typename
recipient
split
}`,
);
export type RecipientDataOutput = FragmentOf<typeof RecipientDataOutput>;
export type RecipientDataOutput = FragmentOf<typeof RecipientDataOutputFragment>;

export const SimpleCollectActionSettings = graphql(
export const SimpleCollectActionSettingsFragment = graphql(
`fragment SimpleCollectActionSettings on SimpleCollectActionSettings {
__typename
contract {
Expand All @@ -34,11 +32,13 @@ export const SimpleCollectActionSettings = graphql(
...RecipientDataOutput
}
}`,
[Amount, NetworkAddress, RecipientDataOutput],
[Amount, NetworkAddress, RecipientDataOutputFragment],
);
export type SimpleCollectActionSettings = FragmentOf<typeof SimpleCollectActionSettings>;
export type SimpleCollectActionSettingsFragment = FragmentOf<
typeof SimpleCollectActionSettingsFragment
>;

export const UnknownActionSettings = graphql(
export const UnknownActionSettingsFragment = graphql(
`fragment UnknownActionSettings on UnknownActionSettings {
__typename
initializeCalldata
Expand All @@ -51,9 +51,9 @@ export const UnknownActionSettings = graphql(
}`,
[NetworkAddress],
);
export type UnknownActionSettings = FragmentOf<typeof UnknownActionSettings>;
export type UnknownActionSettings = FragmentOf<typeof UnknownActionSettingsFragment>;

export const PostAction = graphql(
export const PostActionFragment = graphql(
`fragment PostAction on PostAction {
... on SimpleCollectActionSettings {
...SimpleCollectActionSettings
Expand All @@ -62,21 +62,19 @@ export const PostAction = graphql(
...UnknownActionSettings
}
}`,
[SimpleCollectActionSettings, UnknownActionSettings],
[SimpleCollectActionSettingsFragment, UnknownActionSettingsFragment],
);
export type PostAction = FragmentOf<typeof PostAction>;
export type PostAction = FragmentOf<typeof PostActionFragment>;

// 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<typeof PostMetadata>;

export type PostReactionType = ReturnType<typeof graphql.scalar<'PostReactionType'>>;
export type PostMetadata = FragmentOf<typeof PostMetadataFragment>;

export const LoggedInPostOperations = graphql(
export const LoggedInPostOperationsFragment = graphql(
`fragment LoggedInPostOperations on LoggedInPostOperations {
__typename
id
Expand All @@ -100,16 +98,16 @@ export const LoggedInPostOperations = graphql(
}`,
[BooleanValue],
);
export type LoggedInPostOperations = FragmentOf<typeof LoggedInPostOperations>;
export type LoggedInPostOperations = FragmentOf<typeof LoggedInPostOperationsFragment>;

export const PostReference = graphql(
export const PostReferenceFragment = graphql(
`fragment PostReference on PostReference {
id
}`,
);
export type PostReference = FragmentOf<typeof PostReference>;
export type PostReference = FragmentOf<typeof PostReferenceFragment>;

export const ReferencedPost = graphql(
export const ReferencedPostFragment = graphql(
`fragment ReferencedPost on Post {
__typename
id
Expand All @@ -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
Expand All @@ -146,11 +151,11 @@ export const NestedPost = graphql(
...PostReference
}
}`,
[PostReference, ReferencedPost],
[PostReferenceFragment, ReferencedPostFragment],
);
export type NestedPost = FragmentOf<typeof NestedPost>;
export type NestedPost = FragmentOf<typeof NestedPostFragment>;

export const Post = graphql(
export const PostFragment = graphql(
`fragment Post on Post {
__typename
id
Expand Down Expand Up @@ -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<typeof Post>;
export type Post = FragmentOf<typeof PostFragment>;

// operations: LoggedInPostOperations
export const Repost = graphql(
export const RepostFragment = graphql(
`fragment Repost on Repost {
__typename
id
}`,
[],
);
export type Repost = FragmentOf<typeof Repost>;
export type Repost = FragmentOf<typeof RepostFragment>;

export const AnyPost = graphql(
export const AnyPostFragment = graphql(
`fragment AnyPost on AnyPost {
...on Post {
...Post
Expand All @@ -208,11 +221,11 @@ export const AnyPost = graphql(
...Repost
}
}`,
[Post, Repost],
[PostFragment, RepostFragment],
);
export type AnyPost = FragmentOf<typeof AnyPost>;
export type AnyPost = FragmentOf<typeof AnyPostFragment>;

export const KnownAction = graphql(
export const KnownActionFragment = graphql(
`fragment KnownAction on KnownAction {
__typename
name
Expand All @@ -231,9 +244,9 @@ export const KnownAction = graphql(
}`,
[NetworkAddress, ActionInputInfo],
);
export type KnownAction = FragmentOf<typeof KnownAction>;
export type KnownAction = FragmentOf<typeof KnownActionFragment>;

export const UnknownAction = graphql(
export const UnknownActionFragment = graphql(
`fragment UnknownAction on UnknownAction {
__typename
name
Expand All @@ -243,9 +256,9 @@ export const UnknownAction = graphql(
}`,
[NetworkAddress],
);
export type UnknownAction = FragmentOf<typeof UnknownAction>;
export type UnknownAction = FragmentOf<typeof UnknownActionFragment>;

export const ActionInfo = graphql(
export const ActionInfoFragment = graphql(
`fragment ActionInfo on ActionInfo {
... on KnownAction {
...KnownAction
Expand All @@ -254,20 +267,20 @@ export const ActionInfo = graphql(
...UnknownAction
}
}`,
[KnownAction, UnknownAction],
[KnownActionFragment, UnknownActionFragment],
);
export type ActionInfo = FragmentOf<typeof ActionInfo>;
export type ActionInfo = FragmentOf<typeof ActionInfoFragment>;

export const PostReaction = graphql(
export const PostReactionFragment = graphql(
`fragment PostReaction on PostReaction {
__typename
reactedAt
reaction
}`,
);
export type PostReaction = FragmentOf<typeof PostReaction>;
export type PostReaction = FragmentOf<typeof PostReactionFragment>;

export const AccountPostReaction = graphql(
export const AccountPostReactionFragment = graphql(
`fragment AccountPostReaction on AccountPostReaction {
__typename
account {
Expand All @@ -277,6 +290,6 @@ export const AccountPostReaction = graphql(
...PostReaction
}
}`,
[AccountFragment, PostReaction],
[AccountFragment, PostReactionFragment],
);
export type AccountPostReaction = FragmentOf<typeof AccountPostReaction>;
export type AccountPostReaction = FragmentOf<typeof AccountPostReactionFragment>;
4 changes: 3 additions & 1 deletion packages/graphql/src/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<{
Expand All @@ -46,6 +46,8 @@ export const graphql = initGraphQLTada<{
Int: number;
LegacyProfileId: LegacyProfileId;
LegacyRefreshToken: CompactJwt;
PostActionType: PostActionType;
PostReactionType: PostReactionType;
PageSize: PageSize;
PostId: PostId;
RefreshToken: RefreshToken;
Expand Down
10 changes: 5 additions & 5 deletions packages/graphql/src/notifications.ts
Original file line number Diff line number Diff line change
@@ -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(
Expand Down Expand Up @@ -34,7 +34,7 @@ const ReactionNotification = graphql(
...Post
}
}`,
[AccountFragment, Post],
[AccountFragment, PostFragment],
);
export type ReactionNotification = FragmentOf<typeof ReactionNotification>;

Expand All @@ -46,7 +46,7 @@ const CommentNotification = graphql(
...Post
}
}`,
[Post],
[PostFragment],
);
export type CommentNotification = FragmentOf<typeof CommentNotification>;

Expand Down Expand Up @@ -77,7 +77,7 @@ const QuoteNotification = graphql(
...Post
}
}`,
[Post],
[PostFragment],
);
export type QuoteNotification = FragmentOf<typeof QuoteNotification>;

Expand All @@ -89,7 +89,7 @@ const MentionNotification = graphql(
...Post
}
}`,
[Post],
[PostFragment],
);
export type MentionNotification = FragmentOf<typeof MentionNotification>;

Expand Down
16 changes: 8 additions & 8 deletions packages/graphql/src/post.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import type { FragmentOf } from 'gql.tada';
import {
AccountPostReaction,
ActionInfo,
AnyPost,
AccountPostReactionFragment,
ActionInfoFragment,
AnyPostFragment,
PaginatedResultInfo,
SelfFundedTransactionRequest,
SponsoredTransactionRequest,
Expand Down Expand Up @@ -73,7 +73,7 @@ export const PostQuery = graphql(
...AnyPost
}
}`,
[AnyPost],
[AnyPostFragment],
);
export type PostRequest = RequestOf<typeof PostQuery>;

Expand All @@ -88,7 +88,7 @@ export const PostActionsQuery = graphql(
}
}
}`,
[ActionInfo, PaginatedResultInfo],
[ActionInfoFragment, PaginatedResultInfo],
);
export type PostActionsRequest = RequestOf<typeof PostActionsQuery>;

Expand All @@ -103,7 +103,7 @@ export const PostReactionsQuery = graphql(
}
}
}`,
[AccountPostReaction, PaginatedResultInfo],
[AccountPostReactionFragment, PaginatedResultInfo],
);
export type PostReactionsRequest = RequestOf<typeof PostReactionsQuery>;

Expand All @@ -118,7 +118,7 @@ export const PostBookmarksQuery = graphql(
}
}
}`,
[AnyPost, PaginatedResultInfo],
[AnyPostFragment, PaginatedResultInfo],
);
export type PostBookmarksRequest = RequestOf<typeof PostBookmarksQuery>;

Expand All @@ -133,7 +133,7 @@ export const PostReferencesQuery = graphql(
}
}
}`,
[AnyPost, PaginatedResultInfo],
[AnyPostFragment, PaginatedResultInfo],
);
export type PostReferencesRequest = RequestOf<typeof PostReferencesQuery>;

Expand Down
Loading

0 comments on commit 44c7d07

Please sign in to comment.