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:
-1
@@ -19,7 +19,6 @@ describe('getResolverArgs', () => {
|
||||
isNullable: true,
|
||||
isArray: true,
|
||||
},
|
||||
limit: { type: GraphQLInt, isNullable: true },
|
||||
},
|
||||
findOne: {
|
||||
filter: { kind: GqlInputTypeDefinitionKind.Filter, isNullable: false },
|
||||
|
||||
-4
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user