diff --git a/README.md b/README.md index 68ad1e5..5c50145 100644 --- a/README.md +++ b/README.md @@ -64,6 +64,10 @@ NEXT_PUBLIC_STAGING=true ; To enable verbose logging. NEXT_PUBLIC_VERBOSE_LOGS=true + +; Set the page size to fetch when resolving paginated resources. +; If not set, 25 will be used. +NEXT_PUBLIC_PAGINATION_PAGE_SIZE=10 ``` For more information on environment variables see the [Next.js documentation](https://nextjs.org/docs/basic-features/environment-variables). diff --git a/src/lib/common/animethemes/api.ts b/src/lib/common/animethemes/api.ts index 5cee37b..603dd10 100644 --- a/src/lib/common/animethemes/api.ts +++ b/src/lib/common/animethemes/api.ts @@ -2,7 +2,7 @@ import pLimit from "p-limit"; import type { ResolveTree } from "graphql-parse-resolve-info"; import { parseResolveInfo } from "graphql-parse-resolve-info"; import devLog from "utils/devLog"; -import { CLIENT_API_URL, SERVER_API_KEY, SERVER_API_URL, AUTH_REFERER } from "utils/config.mjs"; +import { CLIENT_API_URL, SERVER_API_KEY, SERVER_API_URL, AUTH_REFERER, PAGINATION_PAGE_SIZE } from "utils/config.mjs"; import type { GraphQLFieldResolver, GraphQLOutputType, GraphQLResolveInfo } from "graphql"; import type { Path } from "graphql/jsutils/Path"; import type { IncomingMessage } from "node:http"; @@ -303,7 +303,7 @@ export function apiResolver(config: ApiResolverConfig): GraphQLFieldResolver & { links: { next: string } }; context.apiRequests++; diff --git a/src/lib/common/animethemes/resolvers.ts b/src/lib/common/animethemes/resolvers.ts index 92c09a8..fce9bea 100644 --- a/src/lib/common/animethemes/resolvers.ts +++ b/src/lib/common/animethemes/resolvers.ts @@ -99,7 +99,8 @@ const resolvers: IResolvers = { playlistAll: apiResolver({ endpoint: (_, { limit, orderBy, orderDesc }) => `/playlist?sort=${orderDesc ? "-" : ""}${orderBy}&page[size]=${limit}&fields[playlist]=id,name,visibility,tracks_count`, - extractor: (result) => result.playlists + extractor: (result) => result.playlists, + pagination: true, }), me: () => ({}), }, @@ -111,6 +112,7 @@ const resolvers: IResolvers = { playlistAll: apiResolver({ endpoint: (_, { filterVideoId }) => `/me/playlist?fields[playlist]=id,name,visibility,tracks_count${filterVideoId ? `&filter[track][video_id]=${filterVideoId}` : ``}`, extractor: (result) => result.playlists, + pagination: true, }), }, Year: { diff --git a/src/utils/config.mjs b/src/utils/config.mjs index ef13853..e1bee64 100644 --- a/src/utils/config.mjs +++ b/src/utils/config.mjs @@ -23,7 +23,9 @@ const AUTH_PATH = process.env.NEXT_PUBLIC_AUTH_PATH; const STAGING = !!process.env.NEXT_PUBLIC_STAGING; const VERBOSE_LOGS = !!process.env.NEXT_PUBLIC_VERBOSE_LOGS; - +const PAGINATION_PAGE_SIZE = process.env.NEXT_PUBLIC_PAGINATION_PAGE_SIZE + ? Number(process.env.NEXT_PUBLIC_PAGINATION_PAGE_SIZE) + : null; function validateConfig() { let isValid = true; @@ -59,5 +61,6 @@ export { STAGING, VERBOSE_LOGS, AUTH_REFERER, + PAGINATION_PAGE_SIZE, validateConfig, };