Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add directionality to the SearchItem and Article Grahql type in the schema #3617

Merged
merged 3 commits into from
Mar 4, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions packages/api/src/generated/graphql.ts
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,7 @@ export type Article = {
contentReader: ContentReader;
createdAt: Scalars['Date'];
description?: Maybe<Scalars['String']>;
directionality?: Maybe<DirectionalityType>;
feedContent?: Maybe<Scalars['String']>;
folder: Scalars['String'];
hasContent?: Maybe<Scalars['Boolean']>;
Expand Down Expand Up @@ -729,6 +730,11 @@ export type DeviceTokensSuccess = {
deviceTokens: Array<DeviceToken>;
};

export enum DirectionalityType {
Ltr = 'LTR',
Rtl = 'RTL'
}

export type EmptyTrashError = {
__typename?: 'EmptyTrashError';
errorCodes: Array<EmptyTrashErrorCode>;
Expand Down Expand Up @@ -2404,6 +2410,7 @@ export enum SearchErrorCode {

export type SearchItem = {
__typename?: 'SearchItem';
aiSummary?: Maybe<Scalars['String']>;
annotation?: Maybe<Scalars['String']>;
archivedAt?: Maybe<Scalars['Date']>;
author?: Maybe<Scalars['String']>;
Expand All @@ -2412,6 +2419,7 @@ export type SearchItem = {
contentReader: ContentReader;
createdAt: Scalars['Date'];
description?: Maybe<Scalars['String']>;
directionality?: Maybe<DirectionalityType>;
feedContent?: Maybe<Scalars['String']>;
folder: Scalars['String'];
highlights?: Maybe<Array<Highlight>>;
Expand Down Expand Up @@ -3378,6 +3386,7 @@ export enum UploadImportFileType {
export type User = {
__typename?: 'User';
email?: Maybe<Scalars['String']>;
features?: Maybe<Array<Maybe<Scalars['String']>>>;
followersCount?: Maybe<Scalars['Int']>;
friendsCount?: Maybe<Scalars['Int']>;
id: Scalars['ID'];
Expand Down Expand Up @@ -3707,6 +3716,7 @@ export type ResolversTypes = {
DeviceTokensErrorCode: DeviceTokensErrorCode;
DeviceTokensResult: ResolversTypes['DeviceTokensError'] | ResolversTypes['DeviceTokensSuccess'];
DeviceTokensSuccess: ResolverTypeWrapper<DeviceTokensSuccess>;
DirectionalityType: DirectionalityType;
EmptyTrashError: ResolverTypeWrapper<EmptyTrashError>;
EmptyTrashErrorCode: EmptyTrashErrorCode;
EmptyTrashResult: ResolversTypes['EmptyTrashError'] | ResolversTypes['EmptyTrashSuccess'];
Expand Down Expand Up @@ -4605,6 +4615,7 @@ export type ArticleResolvers<ContextType = ResolverContext, ParentType extends R
contentReader?: Resolver<ResolversTypes['ContentReader'], ParentType, ContextType>;
createdAt?: Resolver<ResolversTypes['Date'], ParentType, ContextType>;
description?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
directionality?: Resolver<Maybe<ResolversTypes['DirectionalityType']>, ParentType, ContextType>;
feedContent?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
folder?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
hasContent?: Resolver<Maybe<ResolversTypes['Boolean']>, ParentType, ContextType>;
Expand Down Expand Up @@ -5945,6 +5956,7 @@ export type SearchErrorResolvers<ContextType = ResolverContext, ParentType exten
};

export type SearchItemResolvers<ContextType = ResolverContext, ParentType extends ResolversParentTypes['SearchItem'] = ResolversParentTypes['SearchItem']> = {
aiSummary?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
annotation?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
archivedAt?: Resolver<Maybe<ResolversTypes['Date']>, ParentType, ContextType>;
author?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
Expand All @@ -5953,6 +5965,7 @@ export type SearchItemResolvers<ContextType = ResolverContext, ParentType extend
contentReader?: Resolver<ResolversTypes['ContentReader'], ParentType, ContextType>;
createdAt?: Resolver<ResolversTypes['Date'], ParentType, ContextType>;
description?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
directionality?: Resolver<Maybe<ResolversTypes['DirectionalityType']>, ParentType, ContextType>;
feedContent?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
folder?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
highlights?: Resolver<Maybe<Array<ResolversTypes['Highlight']>>, ParentType, ContextType>;
Expand Down Expand Up @@ -6528,6 +6541,7 @@ export type UploadImportFileSuccessResolvers<ContextType = ResolverContext, Pare

export type UserResolvers<ContextType = ResolverContext, ParentType extends ResolversParentTypes['User'] = ResolversParentTypes['User']> = {
email?: Resolver<Maybe<ResolversTypes['String']>, ParentType, ContextType>;
features?: Resolver<Maybe<Array<Maybe<ResolversTypes['String']>>>, ParentType, ContextType>;
followersCount?: Resolver<Maybe<ResolversTypes['Int']>, ParentType, ContextType>;
friendsCount?: Resolver<Maybe<ResolversTypes['Int']>, ParentType, ContextType>;
id?: Resolver<ResolversTypes['ID'], ParentType, ContextType>;
Expand Down
9 changes: 9 additions & 0 deletions packages/api/src/generated/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ type Article {
contentReader: ContentReader!
createdAt: Date!
description: String
directionality: DirectionalityType
feedContent: String
folder: String!
hasContent: Boolean
Expand Down Expand Up @@ -646,6 +647,11 @@ type DeviceTokensSuccess {
deviceTokens: [DeviceToken!]!
}

enum DirectionalityType {
LTR
RTL
}

type EmptyTrashError {
errorCodes: [EmptyTrashErrorCode!]!
}
Expand Down Expand Up @@ -1832,6 +1838,7 @@ enum SearchErrorCode {
}

type SearchItem {
aiSummary: String
annotation: String
archivedAt: Date
author: String
Expand All @@ -1840,6 +1847,7 @@ type SearchItem {
contentReader: ContentReader!
createdAt: Date!
description: String
directionality: DirectionalityType
feedContent: String
folder: String!
highlights: [Highlight!]
Expand Down Expand Up @@ -2733,6 +2741,7 @@ enum UploadImportFileType {

type User {
email: String
features: [String]
followersCount: Int
friendsCount: Int
id: ID!
Expand Down
7 changes: 7 additions & 0 deletions packages/api/src/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@ const schema = gql`
note: String
}

enum DirectionalityType {
LTR
RTL
}

type Article {
id: ID!
title: String!
Expand Down Expand Up @@ -399,6 +404,7 @@ const schema = gql`
wordsCount: Int
folder: String!
feedContent: String
directionality: DirectionalityType
}

# Query: article
Expand Down Expand Up @@ -1649,6 +1655,7 @@ const schema = gql`
links: JSON
folder: String!
aiSummary: String
directionality: DirectionalityType
}

type SearchItemEdge {
Expand Down
13 changes: 12 additions & 1 deletion packages/api/src/services/save_page.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import { Readability } from '@omnivore/readability'
import { DeepPartial } from 'typeorm'
import { Highlight } from '../entity/highlight'
import { LibraryItem, LibraryItemState } from '../entity/library_item'
import {
DirectionalityType,
LibraryItem,
LibraryItemState,
} from '../entity/library_item'
import { User } from '../entity/user'
import { homePageURL } from '../env'
import {
Expand Down Expand Up @@ -126,6 +130,7 @@ export const savePage = async (
rssFeedUrl: input.rssFeedUrl,
folder: input.folder,
feedContent: input.feedContent,
dir: parseResult.parsedContent?.dir,
})
const isImported =
input.source === 'csv-importer' || input.source === 'pocket'
Expand Down Expand Up @@ -204,6 +209,7 @@ export const parsedContentToLibraryItem = ({
rssFeedUrl,
folder,
feedContent,
dir,
}: {
url: string
userId: string
Expand All @@ -224,6 +230,7 @@ export const parsedContentToLibraryItem = ({
rssFeedUrl?: string | null
folder?: string | null
feedContent?: string | null
dir?: string | null
}): DeepPartial<LibraryItem> & { originalUrl: string } => {
logger.info('save_page', { url, state, itemId })
return {
Expand Down Expand Up @@ -267,5 +274,9 @@ export const parsedContentToLibraryItem = ({
state === ArticleSavingRequestStatus.Archived ? new Date() : null,
deletedAt: state === ArticleSavingRequestStatus.Deleted ? new Date() : null,
feedContent,
directionality:
dir?.toLowerCase() === 'rtl'
? DirectionalityType.RTL
: DirectionalityType.LTR, // default to LTR
}
}
3 changes: 3 additions & 0 deletions packages/api/src/utils/helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ import {
ContentReader,
CreateArticleError,
CreateArticleSuccess,
DirectionalityType,
FeedArticle,
Highlight,
PageType,
Expand Down Expand Up @@ -227,6 +228,7 @@ export const libraryItemToArticle = (item: LibraryItem): Article => ({
uploadFileId: item.uploadFile?.id,
pageType: item.itemType as unknown as PageType,
wordsCount: item.wordCount,
directionality: item.directionality as unknown as DirectionalityType,
})

export const libraryItemToSearchItem = (item: LibraryItem): SearchItem => ({
Expand All @@ -245,6 +247,7 @@ export const libraryItemToSearchItem = (item: LibraryItem): SearchItem => ({
image: item.thumbnail,
highlights: item.highlights?.map(highlightDataToHighlight),
wordsCount: item.wordCount,
directionality: item.directionality as unknown as DirectionalityType,
})

export const isParsingTimeout = (libraryItem: LibraryItem): boolean => {
Expand Down
Loading