Fix IN filter with empty array (#7202)

## Context
The api currently allows empty array in the IN filter but the expected
behaviour is not very clear. Typeorm seems to return all records when it
is empty which could lead to undesired result. Instead we decided to
throw an error.
I've updated the FE accordingly to skip calls when array is empty.

<img width="696" alt="Screenshot 2024-09-23 at 14 20 28"
src="https://github.com/user-attachments/assets/4b641430-ff17-40a6-bbc5-75e9a1d55f50">
This commit is contained in:
Weiko
2024-09-23 15:12:49 +02:00
committed by GitHub
parent bb875b1ea8
commit d8e16cbfd1
2 changed files with 8 additions and 3 deletions

View File

@@ -44,6 +44,7 @@ export const SettingsAccountsMessageChannelsContainer = () => {
in: accounts.map((account) => account.id),
},
},
skip: !accounts.length,
});
const tabs = [

View File

@@ -1,4 +1,3 @@
import { isArray } from 'class-validator';
import { ObjectLiteral, WhereExpressionBuilder } from 'typeorm';
import { FieldMetadataInterface } from 'src/engine/metadata-modules/field-metadata/interfaces/field-metadata.interface';
@@ -49,8 +48,13 @@ export class GraphqlQueryFilterFieldParser {
}
const [[operator, value]] = Object.entries(filterValue);
if (operator === 'in' && (!isArray(value) || value.length === 0)) {
return;
if (operator === 'in') {
if (!Array.isArray(value) || value.length === 0) {
throw new GraphqlQueryRunnerException(
`Invalid filter value for field ${key}. Expected non-empty array`,
GraphqlQueryRunnerExceptionCode.INVALID_QUERY_INPUT,
);
}
}
const { sql, params } = this.computeWhereConditionParts(