Add wordsCount to article schema
This commit is contained in:
@ -126,6 +126,7 @@ export type Article = {
|
||||
updatedAt: Scalars['Date'];
|
||||
uploadFileId?: Maybe<Scalars['ID']>;
|
||||
url: Scalars['String'];
|
||||
wordsCount?: Maybe<Scalars['Int']>;
|
||||
};
|
||||
|
||||
|
||||
@ -2151,6 +2152,7 @@ export type SearchItem = {
|
||||
updatedAt?: Maybe<Scalars['Date']>;
|
||||
uploadFileId?: Maybe<Scalars['ID']>;
|
||||
url: Scalars['String'];
|
||||
wordsCount?: Maybe<Scalars['Int']>;
|
||||
};
|
||||
|
||||
export type SearchItemEdge = {
|
||||
@ -4003,6 +4005,7 @@ export type ArticleResolvers<ContextType = ResolverContext, ParentType extends R
|
||||
updatedAt?: Resolver<ResolversTypes['Date'], ParentType, ContextType>;
|
||||
uploadFileId?: Resolver<Maybe<ResolversTypes['ID']>, ParentType, ContextType>;
|
||||
url?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
|
||||
wordsCount?: Resolver<Maybe<ResolversTypes['Int']>, ParentType, ContextType>;
|
||||
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
|
||||
};
|
||||
|
||||
@ -5162,6 +5165,7 @@ export type SearchItemResolvers<ContextType = ResolverContext, ParentType extend
|
||||
updatedAt?: Resolver<Maybe<ResolversTypes['Date']>, ParentType, ContextType>;
|
||||
uploadFileId?: Resolver<Maybe<ResolversTypes['ID']>, ParentType, ContextType>;
|
||||
url?: Resolver<ResolversTypes['String'], ParentType, ContextType>;
|
||||
wordsCount?: Resolver<Maybe<ResolversTypes['Int']>, ParentType, ContextType>;
|
||||
__isTypeOf?: IsTypeOfResolverFn<ParentType, ContextType>;
|
||||
};
|
||||
|
||||
|
||||
@ -102,6 +102,7 @@ type Article {
|
||||
updatedAt: Date!
|
||||
uploadFileId: ID
|
||||
url: String!
|
||||
wordsCount: Int
|
||||
}
|
||||
|
||||
type ArticleEdge {
|
||||
@ -1578,6 +1579,7 @@ type SearchItem {
|
||||
updatedAt: Date
|
||||
uploadFileId: ID
|
||||
url: String!
|
||||
wordsCount: Int
|
||||
}
|
||||
|
||||
type SearchItemEdge {
|
||||
|
||||
@ -6,7 +6,7 @@
|
||||
import { createReactionResolver, deleteReactionResolver } from './reaction'
|
||||
import { Claims, WithDataSourcesContext } from './types'
|
||||
import { createImageProxyUrl } from '../utils/imageproxy'
|
||||
import { userDataToUser, validatedDate } from '../utils/helpers'
|
||||
import { userDataToUser, validatedDate, wordsCount } from '../utils/helpers'
|
||||
|
||||
import {
|
||||
Article,
|
||||
@ -510,6 +510,10 @@ export const functionResolvers = {
|
||||
image(article: { image?: string }): string | undefined {
|
||||
return article.image && createImageProxyUrl(article.image, 260, 260)
|
||||
},
|
||||
wordsCount(article: { wordsCount?: number; content?: string }) {
|
||||
if (article.wordsCount) return article.wordsCount
|
||||
return article.content ? wordsCount(article.content) : undefined
|
||||
},
|
||||
},
|
||||
ArticleSavingRequest: {
|
||||
async article(request: { userId: string; articleId: string }, __: unknown) {
|
||||
|
||||
@ -385,6 +385,7 @@ const schema = gql`
|
||||
language: String
|
||||
readAt: Date
|
||||
recommendations: [Recommendation!]
|
||||
wordsCount: Int
|
||||
}
|
||||
|
||||
# Query: article
|
||||
@ -1548,6 +1549,7 @@ const schema = gql`
|
||||
highlights: [Highlight!]
|
||||
siteIcon: String
|
||||
recommendations: [Recommendation!]
|
||||
wordsCount: Int
|
||||
}
|
||||
|
||||
type SearchItemEdge {
|
||||
|
||||
@ -1,4 +1,9 @@
|
||||
import { generateSlug, stringToHash, validatedDate } from '../utils/helpers'
|
||||
import {
|
||||
generateSlug,
|
||||
stringToHash,
|
||||
validatedDate,
|
||||
wordsCount,
|
||||
} from '../utils/helpers'
|
||||
import {
|
||||
FAKE_URL_PREFIX,
|
||||
parsePreparedContent,
|
||||
@ -78,6 +83,7 @@ export const saveEmail = async (
|
||||
state: ArticleSavingRequestStatus.Succeeded,
|
||||
siteIcon: parseResult.parsedContent?.siteIcon ?? undefined,
|
||||
siteName: parseResult.parsedContent?.siteName ?? undefined,
|
||||
wordsCount: wordsCount(content),
|
||||
}
|
||||
|
||||
const page = await getPageByParam({
|
||||
|
||||
Reference in New Issue
Block a user