Skip to content

Commit

Permalink
fix: correct wrong errors and error codes for query/mutation list limit
Browse files Browse the repository at this point in the history
  • Loading branch information
Etienne-Buschong committed Jan 9, 2025
1 parent 0d03120 commit db982e3
Show file tree
Hide file tree
Showing 5 changed files with 8 additions and 8 deletions.
7 changes: 3 additions & 4 deletions spec/authorization/move-errors-to-output-nodes.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,15 @@ import { moveErrorsToOutputNodes } from '../../src/authorization/move-errors-to-
import {
ConditionalQueryNode,
ConstBoolQueryNode,
FLEX_SEARCH_TOO_MANY_OBJECTS,
ListQueryNode,
ObjectQueryNode,
PreExecQueryParms,
PropertySpecification,
FLEX_SEARCH_TOO_MANY_OBJECTS,
RuntimeErrorQueryNode,
TransformListQueryNode,
WithPreExecutionQueryNode,
} from '../../src/query-tree';
import { TOO_MANY_OBJECTS_ERROR } from '../../src/schema-generation/flex-search-generator';

describe('move-errors-to-output-nodes', () => {
it('moves errors in filter up', () => {
Expand Down Expand Up @@ -153,10 +152,10 @@ describe('move-errors-to-output-nodes', () => {
new WithPreExecutionQueryNode({
resultNode: new ConditionalQueryNode(
new ConstBoolQueryNode(true),
new RuntimeErrorQueryNode(TOO_MANY_OBJECTS_ERROR, {
new RuntimeErrorQueryNode('Too many objects.', {
code: FLEX_SEARCH_TOO_MANY_OBJECTS,
}),
new RuntimeErrorQueryNode(TOO_MANY_OBJECTS_ERROR, {
new RuntimeErrorQueryNode('Too many objects.', {
code: FLEX_SEARCH_TOO_MANY_OBJECTS,
}),
),
Expand Down
1 change: 1 addition & 0 deletions src/query-tree/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ export const FLEX_SEARCH_TOO_MANY_OBJECTS = 'FLEX_SEARCH_TOO_MANY_OBJECTS';
export const BILLING_KEY_FIELD_NOT_FILLED_ERROR = 'BILLING_KEY_FIELD_NOT_FILLED';
export const NOT_SUPPORTED_ERROR = 'NOT_SUPPORTED';
export const ARGUMENT_OUT_OF_RANGE_ERROR = 'ARGUMENT_OUT_OF_RANGE';
export const TOO_MANY_OBJECTS_ERROR = 'TOO_MANY_OBJECTS';

export const RUNTIME_ERROR_TOKEN = '__cruddl_runtime_error';
export const RUNTIME_ERROR_CODE_PROPERTY = '__cruddl_runtime_error_code';
Expand Down
2 changes: 1 addition & 1 deletion src/query-tree/validation.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { RelationSide, RootEntityType } from '../model';
import { TOO_MANY_OBJECTS_ERROR } from './../schema-generation/flex-search-generator';
import { QueryNode } from './base';
import { TOO_MANY_OBJECTS_ERROR } from './errors';

export interface QueryResultValidatorFunctionProvider {
/**
Expand Down
3 changes: 1 addition & 2 deletions src/schema-generation/flex-search-generator.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,6 @@ import { orderArgMatchesPrimarySort } from './utils/flex-search-utils';
import { or } from './utils/input-types';

export const DEFAULT_FLEXSEARCH_MAX_FILTERABLE_AMOUNT: number = 1000;
export const TOO_MANY_OBJECTS_ERROR = 'Too many objects.';

/**
* Augments list fields with filter and pagination features
Expand Down Expand Up @@ -243,7 +242,7 @@ export class FlexSearchGenerator {
],
resultNode: new ConditionalQueryNode(
assertionVariable,
new RuntimeErrorQueryNode(TOO_MANY_OBJECTS_ERROR, {
new RuntimeErrorQueryNode('Too many objects.', {
code: FLEX_SEARCH_TOO_MANY_OBJECTS,
}),
sourceNode,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ import {
OrderSpecification,
PreExecQueryParms,
QueryNode,
RuntimeError,
RuntimeErrorQueryNode,
TransformListQueryNode,
VariableQueryNode,
Expand Down Expand Up @@ -120,7 +121,7 @@ export class OrderByAndPaginationAugmentation {
executionOptions.implicitLimitForRootEntityQueries &&
data.length > executionOptions.implicitLimitForRootEntityQueries
) {
throw new Error(
throw new RuntimeError(
`Collection is truncated by default to ${executionOptions.implicitLimitForRootEntityQueries} elements but contains more elements than this limit. Specify a limit manually to retrieve all elements of the collection.`,
);
}
Expand Down

0 comments on commit db982e3

Please sign in to comment.