feat: expose pagination: false to REST / GraphQL (#9952)
Exposes `pagination: false` to REST / GraphQL to improve performance on large collections by avoiding count query. This will also be nice for our SDK https://github.com/payloadcms/payload/pull/9463 to have the same properties.
This commit is contained in:
@@ -13,6 +13,7 @@ export type Resolver = (
|
||||
limit?: number
|
||||
locale?: string
|
||||
page?: number
|
||||
pagination?: boolean
|
||||
sort?: string
|
||||
where?: Where
|
||||
},
|
||||
@@ -53,6 +54,7 @@ export function findResolver(collection: Collection): Resolver {
|
||||
draft: args.draft,
|
||||
limit: args.limit,
|
||||
page: args.page,
|
||||
pagination: args.pagination,
|
||||
req,
|
||||
sort: args.sort,
|
||||
where: args.where,
|
||||
|
||||
@@ -12,6 +12,7 @@ export type Resolver = (
|
||||
limit?: number
|
||||
locale?: string
|
||||
page?: number
|
||||
pagination?: boolean
|
||||
sort?: string
|
||||
where: Where
|
||||
},
|
||||
@@ -50,6 +51,7 @@ export function findVersionsResolver(collection: Collection): Resolver {
|
||||
depth: 0,
|
||||
limit: args.limit,
|
||||
page: args.page,
|
||||
pagination: args.pagination,
|
||||
req: isolateObjectProperty(req, 'transactionID'),
|
||||
sort: args.sort,
|
||||
where: args.where,
|
||||
|
||||
@@ -11,6 +11,7 @@ export type Resolver = (
|
||||
limit?: number
|
||||
locale?: string
|
||||
page?: number
|
||||
pagination?: boolean
|
||||
sort?: string
|
||||
where: Where
|
||||
},
|
||||
@@ -26,6 +27,7 @@ export function findVersions(globalConfig: SanitizedGlobalConfig): Resolver {
|
||||
globalConfig,
|
||||
limit: args.limit,
|
||||
page: args.page,
|
||||
pagination: args.pagination,
|
||||
req: isolateObjectProperty(context.req, 'transactionID'),
|
||||
sort: args.sort,
|
||||
where: args.where,
|
||||
|
||||
@@ -196,6 +196,7 @@ export function initCollections({ config, graphqlResult }: InitCollectionsGraphQ
|
||||
: {}),
|
||||
limit: { type: GraphQLInt },
|
||||
page: { type: GraphQLInt },
|
||||
pagination: { type: GraphQLBoolean },
|
||||
sort: { type: GraphQLString },
|
||||
},
|
||||
resolve: findResolver(collection),
|
||||
@@ -351,6 +352,7 @@ export function initCollections({ config, graphqlResult }: InitCollectionsGraphQ
|
||||
: {}),
|
||||
limit: { type: GraphQLInt },
|
||||
page: { type: GraphQLInt },
|
||||
pagination: { type: GraphQLBoolean },
|
||||
sort: { type: GraphQLString },
|
||||
},
|
||||
resolve: findVersionsResolver(collection),
|
||||
|
||||
@@ -166,6 +166,7 @@ export function initGlobals({ config, graphqlResult }: InitGlobalsGraphQLArgs):
|
||||
: {}),
|
||||
limit: { type: GraphQLInt },
|
||||
page: { type: GraphQLInt },
|
||||
pagination: { type: GraphQLBoolean },
|
||||
sort: { type: GraphQLString },
|
||||
},
|
||||
resolve: findVersions(global),
|
||||
|
||||
@@ -13,17 +13,19 @@ import type { CollectionRouteHandler } from '../types.js'
|
||||
|
||||
import { headersWithCors } from '../../../utilities/headersWithCors.js'
|
||||
export const find: CollectionRouteHandler = async ({ collection, req }) => {
|
||||
const { depth, draft, joins, limit, page, populate, select, sort, where } = req.query as {
|
||||
depth?: string
|
||||
draft?: string
|
||||
joins?: JoinQuery
|
||||
limit?: string
|
||||
page?: string
|
||||
populate?: Record<string, unknown>
|
||||
select?: Record<string, unknown>
|
||||
sort?: string
|
||||
where?: Where
|
||||
}
|
||||
const { depth, draft, joins, limit, page, pagination, populate, select, sort, where } =
|
||||
req.query as {
|
||||
depth?: string
|
||||
draft?: string
|
||||
joins?: JoinQuery
|
||||
limit?: string
|
||||
page?: string
|
||||
pagination?: string
|
||||
populate?: Record<string, unknown>
|
||||
select?: Record<string, unknown>
|
||||
sort?: string
|
||||
where?: Where
|
||||
}
|
||||
|
||||
const result = await findOperation({
|
||||
collection,
|
||||
@@ -32,6 +34,7 @@ export const find: CollectionRouteHandler = async ({ collection, req }) => {
|
||||
joins: sanitizeJoinParams(joins),
|
||||
limit: isNumber(limit) ? Number(limit) : undefined,
|
||||
page: isNumber(page) ? Number(page) : undefined,
|
||||
pagination: pagination === 'false' ? false : undefined,
|
||||
populate: sanitizePopulateParam(populate),
|
||||
req,
|
||||
select: sanitizeSelectParam(select),
|
||||
|
||||
@@ -9,10 +9,11 @@ import type { CollectionRouteHandler } from '../types.js'
|
||||
import { headersWithCors } from '../../../utilities/headersWithCors.js'
|
||||
|
||||
export const findVersions: CollectionRouteHandler = async ({ collection, req }) => {
|
||||
const { depth, limit, page, populate, select, sort, where } = req.query as {
|
||||
const { depth, limit, page, pagination, populate, select, sort, where } = req.query as {
|
||||
depth?: string
|
||||
limit?: string
|
||||
page?: string
|
||||
pagination?: string
|
||||
populate?: Record<string, unknown>
|
||||
select?: Record<string, unknown>
|
||||
sort?: string
|
||||
@@ -24,6 +25,7 @@ export const findVersions: CollectionRouteHandler = async ({ collection, req })
|
||||
depth: isNumber(depth) ? Number(depth) : undefined,
|
||||
limit: isNumber(limit) ? Number(limit) : undefined,
|
||||
page: isNumber(page) ? Number(page) : undefined,
|
||||
pagination: pagination === 'false' ? false : undefined,
|
||||
populate: sanitizePopulateParam(populate),
|
||||
req,
|
||||
select: sanitizeSelectParam(select),
|
||||
|
||||
@@ -9,10 +9,11 @@ import type { GlobalRouteHandler } from '../types.js'
|
||||
import { headersWithCors } from '../../../utilities/headersWithCors.js'
|
||||
|
||||
export const findVersions: GlobalRouteHandler = async ({ globalConfig, req }) => {
|
||||
const { depth, limit, page, populate, select, sort, where } = req.query as {
|
||||
const { depth, limit, page, pagination, populate, select, sort, where } = req.query as {
|
||||
depth?: string
|
||||
limit?: string
|
||||
page?: string
|
||||
pagination?: string
|
||||
populate?: Record<string, unknown>
|
||||
select?: Record<string, unknown>
|
||||
sort?: string
|
||||
@@ -24,6 +25,7 @@ export const findVersions: GlobalRouteHandler = async ({ globalConfig, req }) =>
|
||||
globalConfig,
|
||||
limit: isNumber(limit) ? Number(limit) : undefined,
|
||||
page: isNumber(page) ? Number(page) : undefined,
|
||||
pagination: pagination === 'false' ? false : undefined,
|
||||
populate: sanitizePopulateParam(populate),
|
||||
req,
|
||||
select: sanitizeSelectParam(select),
|
||||
|
||||
Reference in New Issue
Block a user