Skip to content

Commit

Permalink
feat: expose pagination: false to REST / GraphQL (#9952)
Browse files Browse the repository at this point in the history
Exposes `pagination: false` to REST / GraphQL to improve performance on
large collections by avoiding count query.
This will also be nice for our SDK
#9463 to have the same
properties.
  • Loading branch information
r1tsuu authored Dec 13, 2024
1 parent 0d07ce2 commit b101fec
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 13 deletions.
2 changes: 2 additions & 0 deletions packages/graphql/src/resolvers/collections/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export type Resolver = (
limit?: number
locale?: string
page?: number
pagination?: boolean
sort?: string
where?: Where
},
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/graphql/src/resolvers/collections/findVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ export type Resolver = (
limit?: number
locale?: string
page?: number
pagination?: boolean
sort?: string
where: Where
},
Expand Down Expand Up @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/graphql/src/resolvers/globals/findVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export type Resolver = (
limit?: number
locale?: string
page?: number
pagination?: boolean
sort?: string
where: Where
},
Expand All @@ -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,
Expand Down
2 changes: 2 additions & 0 deletions packages/graphql/src/schema/initCollections.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down Expand Up @@ -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),
Expand Down
1 change: 1 addition & 0 deletions packages/graphql/src/schema/initGlobals.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
25 changes: 14 additions & 11 deletions packages/next/src/routes/rest/collections/find.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion packages/next/src/routes/rest/collections/findVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down
4 changes: 3 additions & 1 deletion packages/next/src/routes/rest/globals/findVersions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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),
Expand Down

0 comments on commit b101fec

Please sign in to comment.