mirror of
https://github.com/lingble/twenty.git
synced 2025-11-02 05:37:56 +00:00
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:
@@ -44,6 +44,7 @@ export const SettingsAccountsMessageChannelsContainer = () => {
|
||||
in: accounts.map((account) => account.id),
|
||||
},
|
||||
},
|
||||
skip: !accounts.length,
|
||||
});
|
||||
|
||||
const tabs = [
|
||||
|
||||
@@ -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(
|
||||
|
||||
Reference in New Issue
Block a user