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);
|
||||
}
|
||||
}
|
||||
|
||||
+7
-2
@@ -1,3 +1,8 @@
|
||||
import {
|
||||
QUERY_DEFAULT_LIMIT_RECORDS,
|
||||
QUERY_MAX_RECORDS,
|
||||
} from 'twenty-shared/constants';
|
||||
|
||||
import { OrderByDirection } from 'src/engine/api/graphql/workspace-query-builder/interfaces/object-record.interface';
|
||||
|
||||
import {
|
||||
@@ -21,8 +26,8 @@ describe('computeParameters', () => {
|
||||
schema: {
|
||||
type: 'integer',
|
||||
minimum: 0,
|
||||
maximum: 60,
|
||||
default: 60,
|
||||
maximum: QUERY_MAX_RECORDS,
|
||||
default: QUERY_DEFAULT_LIMIT_RECORDS,
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
import { type OpenAPIV3_1 } from 'openapi-types';
|
||||
import {
|
||||
QUERY_DEFAULT_LIMIT_RECORDS,
|
||||
QUERY_MAX_RECORDS,
|
||||
} from 'twenty-shared/constants';
|
||||
|
||||
import { OrderByDirection } from 'src/engine/api/graphql/workspace-query-builder/interfaces/object-record.interface';
|
||||
|
||||
@@ -13,8 +17,8 @@ export const computeLimitParameters = (
|
||||
schema: {
|
||||
type: 'integer',
|
||||
minimum: 0,
|
||||
maximum: fromMetadata ? 1000 : 60,
|
||||
default: fromMetadata ? 1000 : 60,
|
||||
maximum: fromMetadata ? 1000 : QUERY_MAX_RECORDS,
|
||||
default: fromMetadata ? 1000 : QUERY_DEFAULT_LIMIT_RECORDS,
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user