diff --git a/apps/main/src/pages/widget/comment/[pageURL].tsx b/apps/main/src/pages/widget/comment/[pageURL].tsx index 473016fa0..2a598cd42 100644 --- a/apps/main/src/pages/widget/comment/[pageURL].tsx +++ b/apps/main/src/pages/widget/comment/[pageURL].tsx @@ -26,7 +26,7 @@ import { query } from '$/server/common/gql'; import { ThemeOfPageDocument } from '$/server/graphql/generated/page'; import { PageByUrlOnlyDocument, - PagesDocument, + FreshPagesDocument, } from '$/server/graphql/generated/page'; import { CommonWidgetProps } from '$/types/page.type'; import { Theme } from '$/types/theme.type'; @@ -87,10 +87,16 @@ const client = getAdminGqlClient(); // Get all project then prerender all their page comments export const getStaticPaths: GetStaticPaths = async () => { - const pages = await query(PagesDocument, {}, 'pages'); + const freshPages = await query( + FreshPagesDocument, + { + limit: 50, + }, + 'pages', + ); const paths: { params: PathParams }[] = - pages.map(({ url }) => { + freshPages.map(({ url }) => { return { params: { pageURL: url, diff --git a/apps/main/src/server/graphql/generated/page.tsx b/apps/main/src/server/graphql/generated/page.tsx index 155e44047..8a090bef1 100644 --- a/apps/main/src/server/graphql/generated/page.tsx +++ b/apps/main/src/server/graphql/generated/page.tsx @@ -49,11 +49,18 @@ export type UpdatePagesMutation = { } | null; }; -export type PagesQueryVariables = Types.Exact<{ [key: string]: never }>; +export type FreshPagesQueryVariables = Types.Exact<{ + limit: Types.Scalars['Int']; +}>; -export type PagesQuery = { +export type FreshPagesQuery = { __typename?: 'query_root'; - pages: Array<{ __typename?: 'Page'; id: string; url: string }>; + pages: Array<{ + __typename?: 'Page'; + id: string; + url: string; + createdAt: string; + }>; }; export type PageByUrlOnlyQueryVariables = Types.Exact<{ @@ -447,24 +454,62 @@ export const UpdatePagesDocument = { }, ], } as unknown as DocumentNode; -export const PagesDocument = { +export const FreshPagesDocument = { kind: 'Document', definitions: [ { kind: 'OperationDefinition', operation: 'query', - name: { kind: 'Name', value: 'pages' }, + name: { kind: 'Name', value: 'freshPages' }, + variableDefinitions: [ + { + kind: 'VariableDefinition', + variable: { + kind: 'Variable', + name: { kind: 'Name', value: 'limit' }, + }, + type: { + kind: 'NonNullType', + type: { kind: 'NamedType', name: { kind: 'Name', value: 'Int' } }, + }, + }, + ], selectionSet: { kind: 'SelectionSet', selections: [ { kind: 'Field', name: { kind: 'Name', value: 'pages' }, + arguments: [ + { + kind: 'Argument', + name: { kind: 'Name', value: 'order_by' }, + value: { + kind: 'ObjectValue', + fields: [ + { + kind: 'ObjectField', + name: { kind: 'Name', value: 'createdAt' }, + value: { kind: 'EnumValue', value: 'desc' }, + }, + ], + }, + }, + { + kind: 'Argument', + name: { kind: 'Name', value: 'limit' }, + value: { + kind: 'Variable', + name: { kind: 'Name', value: 'limit' }, + }, + }, + ], selectionSet: { kind: 'SelectionSet', selections: [ { kind: 'Field', name: { kind: 'Name', value: 'id' } }, { kind: 'Field', name: { kind: 'Name', value: 'url' } }, + { kind: 'Field', name: { kind: 'Name', value: 'createdAt' } }, ], }, }, @@ -472,7 +517,7 @@ export const PagesDocument = { }, }, ], -} as unknown as DocumentNode; +} as unknown as DocumentNode; export const PageByUrlOnlyDocument = { kind: 'Document', definitions: [ diff --git a/apps/main/src/server/graphql/page.graphql b/apps/main/src/server/graphql/page.graphql index 7efa91d07..d719669a4 100644 --- a/apps/main/src/server/graphql/page.graphql +++ b/apps/main/src/server/graphql/page.graphql @@ -37,11 +37,12 @@ mutation updatePages($projectId: uuid!, $title: String!, $url: String!) { } } -# Used in pages/widget/comment/[pageId].tsx -query pages { - pages { +# Used in pages/widget/comment/[pageURL].tsx +query freshPages($limit: Int!) { + pages(order_by: { createdAt: desc }, limit: $limit) { id url + createdAt } }