Add default limit when fetching records (#14532)

- set default limit on front find many hooks
- use default constant in rest api find many endpoint
- set a max limit in rest api find many endpoint
This commit is contained in:
Etienne
2025-09-17 10:32:47 +02:00
committed by GitHub
parent 61b9d82950
commit dc435a7946
13 changed files with 38 additions and 21 deletions
@@ -19,7 +19,6 @@ describe('getResolverArgs', () => {
isNullable: true,
isArray: true,
},
limit: { type: GraphQLInt, isNullable: true },
},
findOne: {
filter: { kind: GqlInputTypeDefinitionKind.Filter, isNullable: false },
@@ -28,10 +28,6 @@ export const getResolverArgs = (
type: GraphQLString,
isNullable: true,
},
limit: {
type: GraphQLInt,
isNullable: true,
},
filter: {
kind: GqlInputTypeDefinitionKind.Filter,
isNullable: true,
@@ -1,10 +1,18 @@
import { BadRequestException, Injectable } from '@nestjs/common';
import {
QUERY_DEFAULT_LIMIT_RECORDS,
QUERY_MAX_RECORDS,
} from 'twenty-shared/constants';
import { type RequestContext } from 'src/engine/api/rest/types/RequestContext';
@Injectable()
export class LimitInputFactory {
create(request: RequestContext, defaultLimit = 60): number {
create(
request: RequestContext,
defaultLimit = QUERY_DEFAULT_LIMIT_RECORDS,
): number {
if (!request.query?.limit) {
return defaultLimit;
}
@@ -16,6 +24,6 @@ export class LimitInputFactory {
);
}
return limit;
return Math.min(limit, QUERY_MAX_RECORDS);
}
}