From 9164383fa328d484cd092e47e8dc960f22bd9450 Mon Sep 17 00:00:00 2001 From: tonyrewin Date: Tue, 15 Nov 2022 15:05:56 +0300 Subject: [PATCH] new-api-refactoring --- src/graphql/query/article-by-slug.ts | 47 --- src/graphql/query/articles-for-authors.ts | 42 --- src/graphql/query/articles-for-communities.ts | 40 --- src/graphql/query/articles-for-feed.ts | 42 --- src/graphql/query/articles-for-topics.ts | 40 --- ...ecent-published.ts => articles-load-by.ts} | 10 +- src/graphql/query/articles-recent-all.ts | 40 --- src/graphql/query/articles-top-month.ts | 40 --- src/graphql/query/articles-top-rated.ts | 41 --- src/graphql/query/articles-top-viewed.ts | 41 --- ...-reactions.ts => author-reacted-shouts.ts} | 0 ...authors-by-slugs.ts => authors-load-by.ts} | 4 +- ...d-messages.ts => chat-messages-load-by.ts} | 4 +- .../query/{im-chats.ts => chats-load.ts} | 0 src/graphql/query/collections-for-me.ts | 13 - src/graphql/query/collections-for-user.ts | 13 - src/graphql/query/layout-recent.ts | 40 --- src/graphql/query/layout-top-month.ts | 40 --- src/graphql/query/layout-top.ts | 40 --- ...ons-for-shouts.ts => reactions-load-by.ts} | 4 +- src/graphql/query/search-results.ts | 42 --- src/graphql/types.gen.ts | 321 ++++-------------- src/utils/apiClient.ts | 124 ++++--- 23 files changed, 160 insertions(+), 868 deletions(-) delete mode 100644 src/graphql/query/article-by-slug.ts delete mode 100644 src/graphql/query/articles-for-authors.ts delete mode 100644 src/graphql/query/articles-for-communities.ts delete mode 100644 src/graphql/query/articles-for-feed.ts delete mode 100644 src/graphql/query/articles-for-topics.ts rename src/graphql/query/{articles-recent-published.ts => articles-load-by.ts} (80%) delete mode 100644 src/graphql/query/articles-recent-all.ts delete mode 100644 src/graphql/query/articles-top-month.ts delete mode 100644 src/graphql/query/articles-top-rated.ts delete mode 100644 src/graphql/query/articles-top-viewed.ts rename src/graphql/query/{articles-for-author-reactions.ts => author-reacted-shouts.ts} (100%) rename src/graphql/query/{authors-by-slugs.ts => authors-load-by.ts} (66%) rename src/graphql/query/{im-load-messages.ts => chat-messages-load-by.ts} (59%) rename src/graphql/query/{im-chats.ts => chats-load.ts} (100%) delete mode 100644 src/graphql/query/collections-for-me.ts delete mode 100644 src/graphql/query/collections-for-user.ts delete mode 100644 src/graphql/query/layout-recent.ts delete mode 100644 src/graphql/query/layout-top-month.ts delete mode 100644 src/graphql/query/layout-top.ts rename src/graphql/query/{reactions-for-shouts.ts => reactions-load-by.ts} (71%) delete mode 100644 src/graphql/query/search-results.ts diff --git a/src/graphql/query/article-by-slug.ts b/src/graphql/query/article-by-slug.ts deleted file mode 100644 index 01bbfef3..00000000 --- a/src/graphql/query/article-by-slug.ts +++ /dev/null @@ -1,47 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query GetShoutBySlugQuery($slug: String!) { - getShoutBySlug(slug: $slug) { - _id: slug - slug - title - subtitle - layout - cover - # community - body - authors { - _id: slug - name - slug - userpic - caption - } - mainTopic - topics { - title - body - slug - stat { - _id: shouts - shouts - authors - followers - } - } - createdAt - updatedAt - publishedAt - visibility - media - stat { - _id: viewed - viewed - reacted - rating - commented - } - } - } -` diff --git a/src/graphql/query/articles-for-authors.ts b/src/graphql/query/articles-for-authors.ts deleted file mode 100644 index 1c178999..00000000 --- a/src/graphql/query/articles-for-authors.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query ShoutsForAuthorsQuery($slugs: [String]!, $limit: Int!, $offset: Int!) { - shoutsByAuthors(slugs: $slugs, limit: $limit, offset: $offset) { - _id: slug - title - subtitle - layout - slug - cover - # community - mainTopic - topics { - title - body - slug - stat { - _id: shouts - shouts - authors - followers - } - } - authors { - _id: slug - name - slug - bio - links - userpic - } - createdAt - publishedAt - stat { - _id: viewed - viewed - reacted - } - } - } -` diff --git a/src/graphql/query/articles-for-communities.ts b/src/graphql/query/articles-for-communities.ts deleted file mode 100644 index 7951f5e5..00000000 --- a/src/graphql/query/articles-for-communities.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query ShoutsForCommunitiesQuery($slugs: [String]!, $limit: Int!, $offset: Int!) { - shoutsByCommunities(slugs: $slugs, limit: $limit, offset: $offset) { - _id: slug - title - subtitle - layout - slug - cover - # community { ... } - mainTopic - topics { - title - body - slug - stat { - _id: shouts - shouts - authors - followers - } - } - authors { - _id: slug - name - slug - userpic - } - createdAt - publishedAt - stat { - _id: viewed - viewed - reacted - } - } - } -` diff --git a/src/graphql/query/articles-for-feed.ts b/src/graphql/query/articles-for-feed.ts deleted file mode 100644 index 564682c2..00000000 --- a/src/graphql/query/articles-for-feed.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query ShoutsBySessionQuery($limit: Int!, $offset: Int!) { - shoutsForFeed(limit: $limit, offset: $offset) { - _id: slug - title - subtitle - layout - slug - cover - # community - mainTopic - topics { - title - body - slug - stat { - _id: shouts - shouts - authors - followers - } - } - authors { - _id: slug - name - slug - userpic - } - createdAt - publishedAt - stat { - _id: viewed - viewed - reacted - rating - commented - } - } - } -` diff --git a/src/graphql/query/articles-for-topics.ts b/src/graphql/query/articles-for-topics.ts deleted file mode 100644 index 37b23744..00000000 --- a/src/graphql/query/articles-for-topics.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query ShoutsForTopicsQuery($slugs: [String]!, $limit: Int!, $offset: Int!) { - shoutsByTopics(slugs: $slugs, limit: $limit, offset: $offset) { - _id: slug - title - subtitle - layout - slug - cover - # community - mainTopic - topics { - title - body - slug - stat { - _id: shouts - shouts - authors - followers - } - } - authors { - _id: slug - name - slug - userpic - } - createdAt - publishedAt - stat { - _id: viewed - viewed - reacted - } - } - } -` diff --git a/src/graphql/query/articles-recent-published.ts b/src/graphql/query/articles-load-by.ts similarity index 80% rename from src/graphql/query/articles-recent-published.ts rename to src/graphql/query/articles-load-by.ts index f1566c1c..50d4f46c 100644 --- a/src/graphql/query/articles-recent-published.ts +++ b/src/graphql/query/articles-load-by.ts @@ -1,14 +1,16 @@ import { gql } from '@urql/core' export default gql` - query RecentPublishedQuery($limit: Int!, $offset: Int!) { - recentPublished(limit: $limit, offset: $offset) { + query LoadShoutsByQuery($by: ShoutsBy, $limit: Int!, $offset: Int!) { + loadShoutsBy(by: $by, amount: $limit, offset: $offset) { _id: slug title subtitle slug layout cover + # community + mainTopic topics { title body @@ -26,10 +28,8 @@ export default gql` slug userpic } - # community - mainTopic - publishedAt createdAt + publishedAt stat { _id: viewed viewed diff --git a/src/graphql/query/articles-recent-all.ts b/src/graphql/query/articles-recent-all.ts deleted file mode 100644 index 98ecf597..00000000 --- a/src/graphql/query/articles-recent-all.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query RecentAllQuery($limit: Int!, $offset: Int!) { - recentAll(limit: $limit, offset: $offset) { - _id: slug - title - subtitle - slug - layout - cover - topics { - title - body - slug - stat { - _id: shouts - shouts - authors - followers - } - } - authors { - _id: slug - name - slug - userpic - } - # community - mainTopic - createdAt - stat { - _id: viewed - viewed - reacted - rating - } - } - } -` diff --git a/src/graphql/query/articles-top-month.ts b/src/graphql/query/articles-top-month.ts deleted file mode 100644 index eed65ce7..00000000 --- a/src/graphql/query/articles-top-month.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query TopMonthShoutsQuery($limit: Int!, $offset: Int!) { - topMonth(limit: $limit, offset: $offset) { - _id: slug - title - subtitle - layout - slug - cover - # community - mainTopic - topics { - title - body - slug - stat { - _id: shouts - shouts - authors - followers - } - } - authors { - _id: slug - name - slug - userpic - } - createdAt - publishedAt - stat { - _id: viewed - viewed - reacted - } - } - } -` diff --git a/src/graphql/query/articles-top-rated.ts b/src/graphql/query/articles-top-rated.ts deleted file mode 100644 index 96060302..00000000 --- a/src/graphql/query/articles-top-rated.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query TopOverallShoutsQuery($limit: Int!, $offset: Int!) { - topOverall(limit: $limit, offset: $offset) { - _id: slug - title - subtitle - slug - layout - cover - # community - mainTopic - topics { - title - body - slug - stat { - _id: shouts - shouts - authors - followers - } - } - authors { - _id: slug - name - slug - userpic - } - createdAt - publishedAt - stat { - _id: viewed - viewed - reacted - rating - } - } - } -` diff --git a/src/graphql/query/articles-top-viewed.ts b/src/graphql/query/articles-top-viewed.ts deleted file mode 100644 index 32252add..00000000 --- a/src/graphql/query/articles-top-viewed.ts +++ /dev/null @@ -1,41 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query TopViewedShoutsQuery($limit: Int!, $offset: Int!) { - topViewed(limit: $limit, offset: $offset) { - _id: slug - title - subtitle - slug - layout - cover - # community - mainTopic - topics { - title - body - slug - stat { - _id: shouts - shouts - authors - followers - } - } - authors { - _id: slug - name - slug - userpic - } - createdAt - publishedAt - stat { - _id: viewed - viewed - reacted - rating - } - } - } -` diff --git a/src/graphql/query/articles-for-author-reactions.ts b/src/graphql/query/author-reacted-shouts.ts similarity index 100% rename from src/graphql/query/articles-for-author-reactions.ts rename to src/graphql/query/author-reacted-shouts.ts diff --git a/src/graphql/query/authors-by-slugs.ts b/src/graphql/query/authors-load-by.ts similarity index 66% rename from src/graphql/query/authors-by-slugs.ts rename to src/graphql/query/authors-load-by.ts index c21c62c0..710a2d3f 100644 --- a/src/graphql/query/authors-by-slugs.ts +++ b/src/graphql/query/authors-load-by.ts @@ -1,8 +1,8 @@ import { gql } from '@urql/core' export default gql` - query GetAuthorsBySlugsQuery($slugs: [String]!) { - getUsersBySlugs(slugs: $slugs) { + query AuthorLoadByQuery($by: AuthorsBy, $limit: Int, $offset: Int) { + loadAuthorsBy(by: $by, amount: $limit, offset: $offset) { _id: slug slug name diff --git a/src/graphql/query/im-load-messages.ts b/src/graphql/query/chat-messages-load-by.ts similarity index 59% rename from src/graphql/query/im-load-messages.ts rename to src/graphql/query/chat-messages-load-by.ts index ec3b83bf..711d7922 100644 --- a/src/graphql/query/im-load-messages.ts +++ b/src/graphql/query/chat-messages-load-by.ts @@ -1,8 +1,8 @@ import { gql } from '@urql/core' export default gql` - query LoadMessagesQuery($chatId: String!, $offset: Int, $amount: Int) { - loadChat(chatId: $chatId, offset: $offset, amount: $amount) { + query LoadMessagesQuery($by: MessagesBy!, $amount: Int, $offset: Int) { + loadMessagesBy(by: $by, amount: $amount, offset: $offset) { error messages { author diff --git a/src/graphql/query/im-chats.ts b/src/graphql/query/chats-load.ts similarity index 100% rename from src/graphql/query/im-chats.ts rename to src/graphql/query/chats-load.ts diff --git a/src/graphql/query/collections-for-me.ts b/src/graphql/query/collections-for-me.ts deleted file mode 100644 index 7080e2a6..00000000 --- a/src/graphql/query/collections-for-me.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query { - getMyCollections { - id - title - desc - slug - amount - } - } -` diff --git a/src/graphql/query/collections-for-user.ts b/src/graphql/query/collections-for-user.ts deleted file mode 100644 index 5f390068..00000000 --- a/src/graphql/query/collections-for-user.ts +++ /dev/null @@ -1,13 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query CollectionsUserQuery($slug: String!) { - getUserCollections(user: $slug) { - id - title - desc - slug - amount - } - } -` diff --git a/src/graphql/query/layout-recent.ts b/src/graphql/query/layout-recent.ts deleted file mode 100644 index 91b84957..00000000 --- a/src/graphql/query/layout-recent.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query RecentShoutsForLayout($layout: String!, $amount: Int, $offset: Int) { - recentLayoutShouts(layout: $layout, amount: $amount, offset: $offset) { - _id: slug - title - subtitle - layout - slug - cover - # community - mainTopic - topics { - title - body - slug - stat { - _id: shouts - shouts - authors - followers - } - } - authors { - _id: slug - name - slug - userpic - } - createdAt - publishedAt - stat { - _id: viewed - viewed - reacted - } - } - } -` diff --git a/src/graphql/query/layout-top-month.ts b/src/graphql/query/layout-top-month.ts deleted file mode 100644 index 2e3100ff..00000000 --- a/src/graphql/query/layout-top-month.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query TopMonthShoutsForLayout($layout: String!, $amount: Int, $offset: Int) { - topMonthLayoutShouts(layout: $layout, amount: $amount, offset: $offset) { - _id: slug - title - subtitle - layout - slug - cover - # community - mainTopic - topics { - title - body - slug - stat { - _id: shouts - shouts - authors - followers - } - } - authors { - _id: slug - name - slug - userpic - } - createdAt - publishedAt - stat { - _id: viewed - viewed - reacted - } - } - } -` diff --git a/src/graphql/query/layout-top.ts b/src/graphql/query/layout-top.ts deleted file mode 100644 index 34da1292..00000000 --- a/src/graphql/query/layout-top.ts +++ /dev/null @@ -1,40 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query TopShoutsForLayout($layout: String!, $amount: Int, $offset: Int) { - topLayoutShouts(layout: $layout, amount: $amount, offset: $offset) { - _id: slug - title - subtitle - layout - slug - cover - # community - mainTopic - topics { - title - body - slug - stat { - _id: shouts - shouts - authors - followers - } - } - authors { - _id: slug - name - slug - userpic - } - createdAt - publishedAt - stat { - _id: viewed - viewed - reacted - } - } - } -` diff --git a/src/graphql/query/reactions-for-shouts.ts b/src/graphql/query/reactions-load-by.ts similarity index 71% rename from src/graphql/query/reactions-for-shouts.ts rename to src/graphql/query/reactions-load-by.ts index 40469e97..3eef630f 100644 --- a/src/graphql/query/reactions-for-shouts.ts +++ b/src/graphql/query/reactions-load-by.ts @@ -1,8 +1,8 @@ import { gql } from '@urql/core' export default gql` - query ReactionsForShoutsQuery($shouts: [String]!, $limit: Int!, $offset: Int!) { - reactionsForShouts(shouts: $shouts, limit: $limit, offset: $offset) { + query LoadReactionsByQuery($by: ReactionsBy, $limit: Int!, $offset: Int!) { + loadReactionsBy(by: $by, amount: $limit, offset: $offset) { id createdBy { slug diff --git a/src/graphql/query/search-results.ts b/src/graphql/query/search-results.ts deleted file mode 100644 index 1f551664..00000000 --- a/src/graphql/query/search-results.ts +++ /dev/null @@ -1,42 +0,0 @@ -import { gql } from '@urql/core' - -export default gql` - query SearchResultsQuery($q: String!, $limit: Int!, $offset: Int!) { - searchQuery(q: $q, limit: $limit, offset: $offset) { - _id: slug - title - subtitle - layout - slug - cover - # community - mainTopic - topics { - title - body - slug - stat { - _id: shouts - shouts - authors - followers - } - } - authors { - _id: slug - name - slug - userpic - } - createdAt - publishedAt - stat { - _id: viewed - viewed - reacted - rating - commented - } - } - } -` diff --git a/src/graphql/types.gen.ts b/src/graphql/types.gen.ts index 8f2e7454..ef7187e8 100644 --- a/src/graphql/types.gen.ts +++ b/src/graphql/types.gen.ts @@ -41,6 +41,17 @@ export type AuthorStat = { rating?: Maybe } +export type AuthorsBy = { + createdAt?: InputMaybe + days?: InputMaybe + lastSeen?: InputMaybe + name?: InputMaybe + order?: InputMaybe + slug?: InputMaybe + stat?: InputMaybe + topic?: InputMaybe +} + export type Chat = { admins?: Maybe>> createdAt: Scalars['Int'] @@ -88,12 +99,6 @@ export type Collection = { title: Scalars['String'] } -export type CollectionInput = { - desc?: InputMaybe - pic?: InputMaybe - title: Scalars['String'] -} - export type Community = { createdAt: Scalars['DateTime'] createdBy: User @@ -104,12 +109,6 @@ export type Community = { slug: Scalars['String'] } -export type CommunityInput = { - desc?: InputMaybe - pic?: InputMaybe - title: Scalars['String'] -} - export enum FollowingEntity { Author = 'AUTHOR', Community = 'COMMUNITY', @@ -133,25 +132,28 @@ export enum MessageStatus { Updated = 'UPDATED' } +export type MessagesBy = { + author?: InputMaybe + body?: InputMaybe + chat?: InputMaybe + days?: InputMaybe + order?: InputMaybe + stat?: InputMaybe +} + export type Mutation = { confirmEmail: AuthResult createChat: Result - createCollection: Result - createCommunity: Result createMessage: Result createReaction: Result createShout: Result createTopic: Result deleteChat: Result - deleteCollection: Result - deleteCommunity: Result deleteMessage: Result deleteReaction: Result deleteShout: Result destroyTopic: Result - enterChat: Result follow: Result - incrementView: Result inviteAuthor: Result inviteChat: Result markAsRead: Result @@ -162,9 +164,8 @@ export type Mutation = { sendLink: Result unfollow: Result updateChat: Result - updateCollection: Result - updateCommunity: Result updateMessage: Result + updateOnlineStatus: Result updateProfile: Result updateReaction: Result updateShout: Result @@ -180,14 +181,6 @@ export type MutationCreateChatArgs = { title?: InputMaybe } -export type MutationCreateCollectionArgs = { - collection: CollectionInput -} - -export type MutationCreateCommunityArgs = { - community: CommunityInput -} - export type MutationCreateMessageArgs = { body: Scalars['String'] chatId: Scalars['String'] @@ -210,14 +203,6 @@ export type MutationDeleteChatArgs = { chatId: Scalars['String'] } -export type MutationDeleteCollectionArgs = { - slug: Scalars['String'] -} - -export type MutationDeleteCommunityArgs = { - slug: Scalars['String'] -} - export type MutationDeleteMessageArgs = { chatId: Scalars['String'] id: Scalars['Int'] @@ -235,19 +220,11 @@ export type MutationDestroyTopicArgs = { slug: Scalars['String'] } -export type MutationEnterChatArgs = { - chatId: Scalars['String'] -} - export type MutationFollowArgs = { slug: Scalars['String'] what: FollowingEntity } -export type MutationIncrementViewArgs = { - shout: Scalars['String'] -} - export type MutationInviteAuthorArgs = { author: Scalars['String'] shout: Scalars['String'] @@ -293,14 +270,6 @@ export type MutationUpdateChatArgs = { chat: ChatInput } -export type MutationUpdateCollectionArgs = { - collection: CollectionInput -} - -export type MutationUpdateCommunityArgs = { - community: CommunityInput -} - export type MutationUpdateMessageArgs = { body: Scalars['String'] chatId: Scalars['String'] @@ -348,98 +317,66 @@ export type ProfileInput = { export type Query = { authorsAll: Array> - collectionsAll: Array> getAuthor: User getCollabs: Array> - getCommunities: Array> - getCommunity: Community - getShoutBySlug: Shout getTopic: Topic - getUserCollections: Array> - getUserRoles: Array> - getUsersBySlugs: Array> isEmailUsed: Scalars['Boolean'] + loadAuthorsBy: Array> loadChats: Result - loadMessages: Result + loadMessagesBy: Result + loadReactionsBy: Array> + loadShoutsBy: Array> markdownBody: Scalars['String'] - reactionsByAuthor: Array> - reactionsForShouts: Array> - recentAll: Array> - recentCandidates: Array> - recentCommented: Array> - recentLayoutShouts: Array> - recentPublished: Array> - recentReacted: Array> - searchChats: Result - searchMessages: Result - searchQuery?: Maybe>> searchUsers: Result - shoutsByAuthors: Array> - shoutsByCollection: Array> - shoutsByCommunities: Array> - shoutsByLayout: Array> - shoutsByTopics: Array> - shoutsForFeed: Array> signIn: AuthResult signOut: AuthResult - topAuthors: Array> - topCommented: Array> - topLayoutShouts: Array> - topMonth: Array> - topMonthLayoutShouts: Array> - topOverall: Array> - topPublished: Array> topicsAll: Array> topicsByAuthor: Array> topicsByCommunity: Array> topicsRandom: Array> userFollowedAuthors: Array> - userFollowedCommunities: Array> userFollowedTopics: Array> userFollowers: Array> - userReactedShouts: Array> } export type QueryGetAuthorArgs = { slug: Scalars['String'] } -export type QueryGetCommunityArgs = { - slug?: InputMaybe -} - -export type QueryGetShoutBySlugArgs = { - slug: Scalars['String'] -} - export type QueryGetTopicArgs = { slug: Scalars['String'] } -export type QueryGetUserCollectionsArgs = { - author: Scalars['String'] -} - -export type QueryGetUserRolesArgs = { - slug: Scalars['String'] -} - -export type QueryGetUsersBySlugsArgs = { - slugs: Array> -} - export type QueryIsEmailUsedArgs = { email: Scalars['String'] } +export type QueryLoadAuthorsByArgs = { + amount?: InputMaybe + by?: InputMaybe + offset?: InputMaybe +} + export type QueryLoadChatsArgs = { amount?: InputMaybe offset?: InputMaybe } -export type QueryLoadMessagesArgs = { +export type QueryLoadMessagesByArgs = { amount?: InputMaybe - chatId: Scalars['String'] + by: MessagesBy + offset?: InputMaybe +} + +export type QueryLoadReactionsByArgs = { + amount?: InputMaybe + by: ReactionBy + limit?: InputMaybe +} + +export type QueryLoadShoutsByArgs = { + amount?: InputMaybe + by?: InputMaybe offset?: InputMaybe } @@ -447,106 +384,10 @@ export type QueryMarkdownBodyArgs = { body: Scalars['String'] } -export type QueryReactionsByAuthorArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] - slug: Scalars['String'] -} - -export type QueryReactionsForShoutsArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] - shouts: Array> -} - -export type QueryRecentAllArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] -} - -export type QueryRecentCandidatesArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] -} - -export type QueryRecentCommentedArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] -} - -export type QueryRecentLayoutShoutsArgs = { - amount?: InputMaybe - layout: Scalars['String'] - offset?: InputMaybe -} - -export type QueryRecentPublishedArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] -} - -export type QueryRecentReactedArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] -} - -export type QuerySearchChatsArgs = { - amount?: InputMaybe - offset?: InputMaybe - q: Scalars['String'] -} - -export type QuerySearchMessagesArgs = { - amount?: InputMaybe - offset?: InputMaybe - q: Scalars['String'] -} - -export type QuerySearchQueryArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] - q?: InputMaybe -} - export type QuerySearchUsersArgs = { amount?: InputMaybe offset?: InputMaybe - q: Scalars['String'] -} - -export type QueryShoutsByAuthorsArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] - slugs: Array> -} - -export type QueryShoutsByCollectionArgs = { - collection: Scalars['String'] - limit: Scalars['Int'] - offset: Scalars['Int'] -} - -export type QueryShoutsByCommunitiesArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] - slugs: Array> -} - -export type QueryShoutsByLayoutArgs = { - amount: Scalars['Int'] - layout?: InputMaybe - offset: Scalars['Int'] -} - -export type QueryShoutsByTopicsArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] - slugs: Array> -} - -export type QueryShoutsForFeedArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] + query: Scalars['String'] } export type QuerySignInArgs = { @@ -555,44 +396,6 @@ export type QuerySignInArgs = { password?: InputMaybe } -export type QueryTopAuthorsArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] -} - -export type QueryTopCommentedArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] -} - -export type QueryTopLayoutShoutsArgs = { - amount?: InputMaybe - layout: Scalars['String'] - offset?: InputMaybe -} - -export type QueryTopMonthArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] -} - -export type QueryTopMonthLayoutShoutsArgs = { - amount?: InputMaybe - layout: Scalars['String'] - offset?: InputMaybe -} - -export type QueryTopOverallArgs = { - limit: Scalars['Int'] - offset: Scalars['Int'] -} - -export type QueryTopPublishedArgs = { - daysago: Scalars['Int'] - limit: Scalars['Int'] - offset: Scalars['Int'] -} - export type QueryTopicsByAuthorArgs = { author: Scalars['String'] } @@ -609,10 +412,6 @@ export type QueryUserFollowedAuthorsArgs = { slug: Scalars['String'] } -export type QueryUserFollowedCommunitiesArgs = { - slug: Scalars['String'] -} - export type QueryUserFollowedTopicsArgs = { slug: Scalars['String'] } @@ -621,10 +420,6 @@ export type QueryUserFollowersArgs = { slug: Scalars['String'] } -export type QueryUserReactedShoutsArgs = { - slug: Scalars['String'] -} - export type Rating = { rater: Scalars['String'] value: Scalars['Int'] @@ -647,6 +442,16 @@ export type Reaction = { updatedAt?: Maybe } +export type ReactionBy = { + author?: InputMaybe + body?: InputMaybe + days?: InputMaybe + order?: InputMaybe + shout?: InputMaybe + stat?: InputMaybe + topic?: InputMaybe +} + export type ReactionInput = { body?: InputMaybe kind: Scalars['Int'] @@ -757,6 +562,20 @@ export type ShoutInput = { visibleForUsers?: InputMaybe>> } +export type ShoutsBy = { + author?: InputMaybe + body?: InputMaybe + days?: InputMaybe + layout?: InputMaybe + order?: InputMaybe + published?: InputMaybe + slug?: InputMaybe + stat?: InputMaybe + title?: InputMaybe + topic?: InputMaybe + visibility?: InputMaybe +} + export type Stat = { commented?: Maybe ranking?: Maybe diff --git a/src/utils/apiClient.ts b/src/utils/apiClient.ts index 15f77fd8..a0eb2884 100644 --- a/src/utils/apiClient.ts +++ b/src/utils/apiClient.ts @@ -9,11 +9,8 @@ import type { } from '../graphql/types.gen' import { publicGraphQLClient } from '../graphql/publicGraphQLClient' import { getToken, privateGraphQLClient } from '../graphql/privateGraphQLClient' -import articleBySlug from '../graphql/query/article-by-slug' -import articlesRecentAll from '../graphql/query/articles-recent-all' -import articlesRecentPublished from '../graphql/query/articles-recent-published' import topicsAll from '../graphql/query/topics-all' -import reactionsForShouts from '../graphql/query/reactions-for-shouts' +import reactionsForShouts from '../graphql/query/reactions-load-by' import mySession from '../graphql/mutation/my-session' import authLogoutQuery from '../graphql/mutation/auth-logout' import authLoginQuery from '../graphql/query/auth-login' @@ -23,26 +20,20 @@ import authConfirmEmailMutation from '../graphql/mutation/auth-confirm-email' import authSendLinkMutation from '../graphql/mutation/auth-send-link' import followMutation from '../graphql/mutation/follow' import unfollowMutation from '../graphql/mutation/unfollow' -import articlesForAuthors from '../graphql/query/articles-for-authors' -import articlesForTopics from '../graphql/query/articles-for-topics' -import searchResults from '../graphql/query/search-results' import topicsRandomQuery from '../graphql/query/topics-random' -import articlesTopMonth from '../graphql/query/articles-top-month' -import articlesTopRated from '../graphql/query/articles-top-rated' import authorsAll from '../graphql/query/authors-all' import reactionCreate from '../graphql/mutation/reaction-create' import reactionDestroy from '../graphql/mutation/reaction-destroy' import reactionUpdate from '../graphql/mutation/reaction-update' import incrementView from '../graphql/mutation/increment-view' import createArticle from '../graphql/mutation/article-create' -import myChats from '../graphql/query/im-chats' -import loadChat from '../graphql/query/im-load-messages' -import getRecentByLayout from '../graphql/query/layout-recent' -import getTopByLayout from '../graphql/query/layout-top' -import getTopMonthByLayout from '../graphql/query/layout-top-month' -import type { LayoutType } from '../stores/zine/layouts' +import myChats from '../graphql/query/chats-load' +import loadChat from '../graphql/query/chat-messages-load-by' import topicBySlug from '../graphql/query/topic-by-slug' import authorBySlug from '../graphql/query/author-by-slug' +import shoutsLoadBy from '../graphql/query/articles-load-by' +import reactionsLoadBy from '../graphql/query/reactions-load-by' +import authorsLoadBy from '../graphql/query/authors-load-by' const FEED_SIZE = 50 @@ -157,12 +148,21 @@ export const apiClient = { }, getTopArticles: async () => { - const response = await publicGraphQLClient.query(articlesTopRated, { limit: 10, offset: 0 }).toPromise() - return response.data.topOverall + const by = { + stat: 'rating', + visibility: 'public' + } + const response = await publicGraphQLClient.query(shoutsLoadBy, { by, limit: 10, offset: 0 }).toPromise() + return response.data.loadShoutsBy }, getTopMonthArticles: async () => { - const response = await publicGraphQLClient.query(articlesTopMonth, { limit: 10, offset: 0 }).toPromise() - return response.data.topMonth + const by = { + stat: 'rating', + visibility: 'public', + days: 30 + } + const response = await publicGraphQLClient.query(shoutsLoadBy, { by, limit: 10, offset: 0 }).toPromise() + return response.data.loadShoutsBy }, getRecentPublishedArticles: async ({ limit = FEED_SIZE, @@ -171,9 +171,12 @@ export const apiClient = { limit?: number offset?: number }) => { - const response = await publicGraphQLClient.query(articlesRecentPublished, { limit, offset }).toPromise() + const by = { + visibility: 'public' + } + const response = await publicGraphQLClient.query(shoutsLoadBy, { by, limit, offset }).toPromise() - return response.data.recentPublished + return response.data.loadShoutsBy }, getRandomTopics: async ({ amount }: { amount: number }) => { const response = await publicGraphQLClient.query(topicsRandomQuery, { amount }).toPromise() @@ -187,17 +190,19 @@ export const apiClient = { getSearchResults: async ({ query, limit = FEED_SIZE, - offset = 0, - layout = 'literature' + offset = 0 }: { query: string limit: number offset?: number - layout?: LayoutType }): Promise => { + const by = { + title: query, + body: query + } const response = await publicGraphQLClient - .query(searchResults, { - q: query, + .query(shoutsLoadBy, { + by, limit, offset }) @@ -213,7 +218,8 @@ export const apiClient = { offset?: number }): Promise => { const response = await publicGraphQLClient - .query(articlesRecentAll, { + .query(shoutsLoadBy, { + by: {}, limit, offset }) @@ -230,9 +236,13 @@ export const apiClient = { limit: number offset?: number }): Promise => { + const by = { + topics: topicSlugs, + visibility: 'public' + } const response = await publicGraphQLClient - .query(articlesForTopics, { - slugs: topicSlugs, + .query(shoutsLoadBy, { + by, limit, offset }) @@ -253,13 +263,17 @@ export const apiClient = { limit: number offset?: number }): Promise => { + const by = { + authors: authorSlugs, + visibility: 'public' + } const vars = { - slugs: authorSlugs, + by, limit, offset } - console.debug(vars) - const response = await publicGraphQLClient.query(articlesForAuthors, vars).toPromise() + // console.debug(vars) + const response = await publicGraphQLClient.query(shoutsLoadBy, vars).toPromise() if (response.error) { console.error('[api-client] getArticlesForAuthors', response.error) @@ -298,7 +312,10 @@ export const apiClient = { return response.data.refreshSession }, getPublishedArticles: async ({ limit = FEED_SIZE, offset }: { limit?: number; offset?: number }) => { - const response = await publicGraphQLClient.query(articlesRecentPublished, { limit, offset }).toPromise() + const by = { + visibility: 'public' + } + const response = await publicGraphQLClient.query(shoutsLoadBy, { by, limit, offset }).toPromise() if (response.error) { console.error('[api-client] getPublishedArticles', response.error) @@ -329,7 +346,9 @@ export const apiClient = { return response.data.getTopic }, getArticle: async ({ slug }: { slug: string }): Promise => { - const response = await publicGraphQLClient.query(articleBySlug, { slug }).toPromise() + const response = await publicGraphQLClient + .query(shoutsLoadBy, { by: { slug }, amount: 1, offset: 0 }) + .toPromise() return response.data?.getShoutBySlug }, @@ -382,29 +401,44 @@ export const apiClient = { return resp.data.myChats }, getRecentLayoutShouts: async ({ layout = 'article', amount = 50, offset = 0 }) => { - const resp = await publicGraphQLClient.query(getRecentByLayout, { amount, offset, layout }).toPromise() + const by = { + layout + } + const resp = await publicGraphQLClient.query(shoutsLoadBy, { by, amount, offset }).toPromise() return resp.data.recentLayoutShouts }, getTopLayoutShouts: async ({ layout = 'article', amount = 50, offset = 0 }) => { - const resp = await publicGraphQLClient.query(getTopByLayout, { amount, offset, layout }).toPromise() + const by = { + layout, + stat: 'rating', + order: 'rating' + } + const resp = await publicGraphQLClient.query(shoutsLoadBy, { by, amount, offset }).toPromise() return resp.data.topLayoutShouts }, getTopMonthLayoutShouts: async ({ layout = 'article', amount = 50, offset = 0 }) => { - const resp = await publicGraphQLClient - .query(getTopMonthByLayout, { amount, offset, layout }) - .toPromise() + const by = { + layout, + stat: 'rating', + order: 'rating', + days: 30 + } + const resp = await publicGraphQLClient.query(shoutsLoadBy, { amount, offset, layout }).toPromise() return resp.data.topMonthLayoutShouts }, getChatMessages: async ({ - chatId, - offset = 0, - amount = 50 + chat, + amount = 50, + offset = 0 }: { - chatId: string - offset?: number + chat: string amount?: number + offset?: number }) => { - const resp = await privateGraphQLClient.query(loadChat, { chatId, offset, amount }).toPromise() + const by = { + chat + } + const resp = await privateGraphQLClient.query(loadChat, { by, offset, amount }).toPromise() return resp.data.loadChat } }