From be0b9eec9b4e65ab19d38fd5185cd65854e3ecc7 Mon Sep 17 00:00:00 2001 From: Ronald Van Ryswyk Date: Fri, 3 Nov 2023 12:40:29 +1030 Subject: [PATCH 01/14] Verbatin Search Terms - Stringify them --- .../src/interfaces/currentFilter.interface.ts | 3 ++ .../__tests__/graphql.service.spec.ts | 40 +++++++++++++++++++ .../graphql/src/services/graphql.service.ts | 5 +++ 3 files changed, 48 insertions(+) diff --git a/packages/common/src/interfaces/currentFilter.interface.ts b/packages/common/src/interfaces/currentFilter.interface.ts index fdec522a8..58bc1e393 100644 --- a/packages/common/src/interfaces/currentFilter.interface.ts +++ b/packages/common/src/interfaces/currentFilter.interface.ts @@ -16,4 +16,7 @@ export interface CurrentFilter { /** Target element selector from which the filter was triggered from. */ targetSelector?: string; + + /** If true, stringifies the search terms as is without modification */ + verbatim?: boolean; } diff --git a/packages/graphql/src/services/__tests__/graphql.service.spec.ts b/packages/graphql/src/services/__tests__/graphql.service.spec.ts index b3589baaa..f8d2461b0 100644 --- a/packages/graphql/src/services/__tests__/graphql.service.spec.ts +++ b/packages/graphql/src/services/__tests__/graphql.service.spec.ts @@ -1236,6 +1236,46 @@ describe('GraphqlService', () => { expect(removeSpaces(query)).toBe(removeSpaces(expectation)); expect(currentFilters).toEqual([]); }); + + describe("Verbatim ColumnFilters", () => { + describe.each` + description | verbatim | searchTerms | expectation + ${"Verbatim false, searchTerms: null"} | ${false} | ${null} | ${'query{users(first:10, offset:0) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, searchTerms: null"} | ${true} | ${null} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"null"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, searchTerms: ''"} | ${false} | ${''} | ${'query{users(first:10, offset:0) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, searchTerms: ''"} | ${true} | ${''} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"\\"\\""}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, searchTerms: []"} | ${false} | ${[]} | ${'query{users(first:10, offset:0) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, searchTerms: []"} | ${true} | ${[]} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[]"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, searchTerms: [null]"} | ${false} | ${[null]} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:""}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, searchTerms: [null]"} | ${true} | ${[null]} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[null]"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, searchTerms: [null]"} | ${false} | ${['']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:""}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, searchTerms: [null]"} | ${true} | ${['']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[\\"\\"]"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, 1 search term"} | ${false} | ${['female']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"female"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, 1 search term"} | ${true} | ${['female']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[\\"female\\"]"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, 2 search terms"} | ${false} | ${['female', 'male']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"female, male"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, 2 search terms"} | ${true} | ${['female', 'male']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[\\"female\\", \\"male\\"]"}]) { totalCount,nodes{ id,company,gender,name } }}'} + + + `(`$description`, ({ description, verbatim, searchTerms, expectation }) => { + + const mockColumn = { id: 'gender', field: 'gender' } as Column; + let mockColumnFilters: ColumnFilters; + + beforeEach(() => { + mockColumnFilters = { + gender: { columnId: 'gender', columnDef: mockColumn, searchTerms: searchTerms, operator: 'IN', type: FieldType.string, verbatim: verbatim }, + } as ColumnFilters; + + service.init(serviceOptions, paginationOptions, gridStub); + service.updateFilters(mockColumnFilters, false); + }); + + test(`buildQuery output matches ${expectation}`, () => { + const query = service.buildQuery(); + expect(removeSpaces(query)).toBe(removeSpaces(expectation)); + }); + }); + }); }); describe('presets', () => { diff --git a/packages/graphql/src/services/graphql.service.ts b/packages/graphql/src/services/graphql.service.ts index eda7f9be7..a1d5c115e 100644 --- a/packages/graphql/src/services/graphql.service.ts +++ b/packages/graphql/src/services/graphql.service.ts @@ -407,6 +407,11 @@ export class GraphqlService implements BackendService { throw new Error(`GraphQL filter could not find the field name to query the search, your column definition must include a valid "field" or "name" (optionally you can also use the "queryfield").`); } + if (columnFilter.verbatim) { + searchByArray.push({ field: fieldName, operator: columnFilter.operator, value: JSON.stringify(columnFilter.searchTerms) }); + continue; + } + fieldSearchValue = (fieldSearchValue === undefined || fieldSearchValue === null) ? '' : `${fieldSearchValue}`; // make sure it's a string // run regex to find possible filter operators unless the user disabled the feature From cbc38afcf79c150f538bbe3f41892496d41c4edb Mon Sep 17 00:00:00 2001 From: Ronald Van Ryswyk Date: Fri, 3 Nov 2023 13:14:33 +1030 Subject: [PATCH 02/14] verbatim test operator change and better description --- .../__tests__/graphql.service.spec.ts | 36 +++++++++---------- 1 file changed, 17 insertions(+), 19 deletions(-) diff --git a/packages/graphql/src/services/__tests__/graphql.service.spec.ts b/packages/graphql/src/services/__tests__/graphql.service.spec.ts index f8d2461b0..8bb2d2f68 100644 --- a/packages/graphql/src/services/__tests__/graphql.service.spec.ts +++ b/packages/graphql/src/services/__tests__/graphql.service.spec.ts @@ -1239,31 +1239,29 @@ describe('GraphqlService', () => { describe("Verbatim ColumnFilters", () => { describe.each` - description | verbatim | searchTerms | expectation - ${"Verbatim false, searchTerms: null"} | ${false} | ${null} | ${'query{users(first:10, offset:0) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim true, searchTerms: null"} | ${true} | ${null} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"null"}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim false, searchTerms: ''"} | ${false} | ${''} | ${'query{users(first:10, offset:0) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim true, searchTerms: ''"} | ${true} | ${''} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"\\"\\""}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim false, searchTerms: []"} | ${false} | ${[]} | ${'query{users(first:10, offset:0) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim true, searchTerms: []"} | ${true} | ${[]} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[]"}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim false, searchTerms: [null]"} | ${false} | ${[null]} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:""}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim true, searchTerms: [null]"} | ${true} | ${[null]} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[null]"}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim false, searchTerms: [null]"} | ${false} | ${['']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:""}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim true, searchTerms: [null]"} | ${true} | ${['']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[\\"\\"]"}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim false, 1 search term"} | ${false} | ${['female']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"female"}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim true, 1 search term"} | ${true} | ${['female']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[\\"female\\"]"}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim false, 2 search terms"} | ${false} | ${['female', 'male']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"female, male"}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim true, 2 search terms"} | ${true} | ${['female', 'male']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[\\"female\\", \\"male\\"]"}]) { totalCount,nodes{ id,company,gender,name } }}'} - - - `(`$description`, ({ description, verbatim, searchTerms, expectation }) => { + description | verbatim | operator | searchTerms | expectation + ${"Verbatim false, Filter for null"} | ${false} | ${'EQ'} | ${null} | ${'query{users(first:10, offset:0) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, Filter for null"} | ${true} | ${'EQ'} | ${null} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:EQ, value:"null"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, Empty String"} | ${false} | ${'EQ'} | ${''} | ${'query{users(first:10, offset:0) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, Empty String"} | ${true} | ${'EQ'} | ${''} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:EQ, value:"\\"\\""}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, Empty List"} | ${false} | ${'IN'} | ${[]} | ${'query{users(first:10, offset:0) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, Empty List"} | ${true} | ${'IN'} | ${[]} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[]"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, Filter for null (List version)"} | ${false} | ${'IN'} | ${[null]} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:""}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, Filter for null (List version)"} | ${true} | ${'IN'} | ${[null]} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[null]"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, Empty String (List Version)"} | ${false} | ${'IN'} | ${['']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:""}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, Empty String (List Version)"} | ${true} | ${'IN'} | ${['']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[\\"\\"]"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, Filter for females"} | ${false} | ${'IN'} | ${['female']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"female"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, Filter for females"} | ${true} | ${'IN'} | ${['female']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[\\"female\\"]"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, Filter for female/male"} | ${false} | ${'IN'} | ${['female', 'male']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"female, male"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, Filter for female/male"} | ${true} | ${'IN'} | ${['female', 'male']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[\\"female\\", \\"male\\"]"}]) { totalCount,nodes{ id,company,gender,name } }}'} + `(`$description`, ({ description, verbatim, operator, searchTerms, expectation }) => { const mockColumn = { id: 'gender', field: 'gender' } as Column; let mockColumnFilters: ColumnFilters; beforeEach(() => { mockColumnFilters = { - gender: { columnId: 'gender', columnDef: mockColumn, searchTerms: searchTerms, operator: 'IN', type: FieldType.string, verbatim: verbatim }, + gender: { columnId: 'gender', columnDef: mockColumn, searchTerms, operator, type: FieldType.string, verbatim }, } as ColumnFilters; service.init(serviceOptions, paginationOptions, gridStub); From 2275ccc16bc997375b9180b3572100c82800ceed Mon Sep 17 00:00:00 2001 From: Ronald Van Ryswyk Date: Fri, 3 Nov 2023 13:22:54 +1030 Subject: [PATCH 03/14] Rename verbatim to verbatimSearchTerms --- .../src/interfaces/currentFilter.interface.ts | 2 +- .../__tests__/graphql.service.spec.ts | 32 +++++++++---------- .../graphql/src/services/graphql.service.ts | 2 +- 3 files changed, 18 insertions(+), 18 deletions(-) diff --git a/packages/common/src/interfaces/currentFilter.interface.ts b/packages/common/src/interfaces/currentFilter.interface.ts index 58bc1e393..394b79d05 100644 --- a/packages/common/src/interfaces/currentFilter.interface.ts +++ b/packages/common/src/interfaces/currentFilter.interface.ts @@ -18,5 +18,5 @@ export interface CurrentFilter { targetSelector?: string; /** If true, stringifies the search terms as is without modification */ - verbatim?: boolean; + verbatimSearchTerms?: boolean; } diff --git a/packages/graphql/src/services/__tests__/graphql.service.spec.ts b/packages/graphql/src/services/__tests__/graphql.service.spec.ts index 8bb2d2f68..bcaa60bf1 100644 --- a/packages/graphql/src/services/__tests__/graphql.service.spec.ts +++ b/packages/graphql/src/services/__tests__/graphql.service.spec.ts @@ -1239,21 +1239,21 @@ describe('GraphqlService', () => { describe("Verbatim ColumnFilters", () => { describe.each` - description | verbatim | operator | searchTerms | expectation - ${"Verbatim false, Filter for null"} | ${false} | ${'EQ'} | ${null} | ${'query{users(first:10, offset:0) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim true, Filter for null"} | ${true} | ${'EQ'} | ${null} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:EQ, value:"null"}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim false, Empty String"} | ${false} | ${'EQ'} | ${''} | ${'query{users(first:10, offset:0) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim true, Empty String"} | ${true} | ${'EQ'} | ${''} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:EQ, value:"\\"\\""}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim false, Empty List"} | ${false} | ${'IN'} | ${[]} | ${'query{users(first:10, offset:0) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim true, Empty List"} | ${true} | ${'IN'} | ${[]} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[]"}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim false, Filter for null (List version)"} | ${false} | ${'IN'} | ${[null]} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:""}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim true, Filter for null (List version)"} | ${true} | ${'IN'} | ${[null]} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[null]"}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim false, Empty String (List Version)"} | ${false} | ${'IN'} | ${['']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:""}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim true, Empty String (List Version)"} | ${true} | ${'IN'} | ${['']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[\\"\\"]"}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim false, Filter for females"} | ${false} | ${'IN'} | ${['female']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"female"}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim true, Filter for females"} | ${true} | ${'IN'} | ${['female']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[\\"female\\"]"}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim false, Filter for female/male"} | ${false} | ${'IN'} | ${['female', 'male']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"female, male"}]) { totalCount,nodes{ id,company,gender,name } }}'} - ${"Verbatim true, Filter for female/male"} | ${true} | ${'IN'} | ${['female', 'male']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[\\"female\\", \\"male\\"]"}]) { totalCount,nodes{ id,company,gender,name } }}'} + description | verbatim | operator | searchTerms | expectation + ${"Verbatim false, Filter for null"} | ${false} | ${'EQ'} | ${null} | ${'query{users(first:10, offset:0) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, Filter for null"} | ${true} | ${'EQ'} | ${null} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:EQ, value:"null"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, Empty string"} | ${false} | ${'EQ'} | ${''} | ${'query{users(first:10, offset:0) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, Empty string"} | ${true} | ${'EQ'} | ${''} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:EQ, value:"\\"\\""}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, Empty list"} | ${false} | ${'IN'} | ${[]} | ${'query{users(first:10, offset:0) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, Empty list"} | ${true} | ${'IN'} | ${[]} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[]"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, Filter for null (in list)"} | ${false} | ${'IN'} | ${[null]} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:""}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, Filter for null (in list)"} | ${true} | ${'IN'} | ${[null]} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[null]"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, Filter for empty string (in list)"} | ${false} | ${'IN'} | ${['']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:""}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, Filter for empty string (in list)"} | ${true} | ${'IN'} | ${['']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[\\"\\"]"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, Filter for female"} | ${false} | ${'IN'} | ${['female']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"female"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, Filter for female"} | ${true} | ${'IN'} | ${['female']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[\\"female\\"]"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim false, Filter for female/male"} | ${false} | ${'IN'} | ${['female', 'male']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"female, male"}]) { totalCount,nodes{ id,company,gender,name } }}'} + ${"Verbatim true, Filter for female/male"} | ${true} | ${'IN'} | ${['female', 'male']} | ${'query{users(first:10, offset:0, filterBy:[{field:gender, operator:IN, value:"[\\"female\\", \\"male\\"]"}]) { totalCount,nodes{ id,company,gender,name } }}'} `(`$description`, ({ description, verbatim, operator, searchTerms, expectation }) => { const mockColumn = { id: 'gender', field: 'gender' } as Column; @@ -1261,7 +1261,7 @@ describe('GraphqlService', () => { beforeEach(() => { mockColumnFilters = { - gender: { columnId: 'gender', columnDef: mockColumn, searchTerms, operator, type: FieldType.string, verbatim }, + gender: { columnId: 'gender', columnDef: mockColumn, searchTerms, operator, type: FieldType.string, verbatimSearchTerms: verbatim }, } as ColumnFilters; service.init(serviceOptions, paginationOptions, gridStub); diff --git a/packages/graphql/src/services/graphql.service.ts b/packages/graphql/src/services/graphql.service.ts index a1d5c115e..f453752c3 100644 --- a/packages/graphql/src/services/graphql.service.ts +++ b/packages/graphql/src/services/graphql.service.ts @@ -407,7 +407,7 @@ export class GraphqlService implements BackendService { throw new Error(`GraphQL filter could not find the field name to query the search, your column definition must include a valid "field" or "name" (optionally you can also use the "queryfield").`); } - if (columnFilter.verbatim) { + if (columnFilter.verbatimSearchTerms) { searchByArray.push({ field: fieldName, operator: columnFilter.operator, value: JSON.stringify(columnFilter.searchTerms) }); continue; } From 917b16ea0477f7b96d1ec803a3356c8f46a07a50 Mon Sep 17 00:00:00 2001 From: Ronald Van Ryswyk Date: Fri, 3 Nov 2023 14:26:46 +1030 Subject: [PATCH 04/14] Allow `null` as a search term --- packages/common/src/enums/searchTerm.type.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/common/src/enums/searchTerm.type.ts b/packages/common/src/enums/searchTerm.type.ts index c86b21a2a..623c8793b 100644 --- a/packages/common/src/enums/searchTerm.type.ts +++ b/packages/common/src/enums/searchTerm.type.ts @@ -1 +1 @@ -export type SearchTerm = string | number | boolean | Date; +export type SearchTerm = string | number | boolean | Date | null; From 34ff0930852d93a7f35fee48d1cc457699a29a8f Mon Sep 17 00:00:00 2001 From: Ronald Van Ryswyk Date: Fri, 3 Nov 2023 14:48:03 +1030 Subject: [PATCH 05/14] Fix code break due to SearchTerm allowing to be null --- packages/common/src/filters/sliderFilter.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/common/src/filters/sliderFilter.ts b/packages/common/src/filters/sliderFilter.ts index c174c7318..40c52debd 100644 --- a/packages/common/src/filters/sliderFilter.ts +++ b/packages/common/src/filters/sliderFilter.ts @@ -211,7 +211,7 @@ export class SliderFilter implements Filter { sliderVals = (term1 as string).split('..'); this._currentValue = +(sliderVals?.[0] ?? 0); } else if (hasData(term1) || term1 === '') { - this._currentValue = +term1; + this._currentValue = term1 === null ? undefined : +term1; sliderVals = [term1 as string | number]; } } From 620170e3a8a857dcc54ade546d88b856dd7047f1 Mon Sep 17 00:00:00 2001 From: Ronald Van Ryswyk Date: Fri, 3 Nov 2023 15:10:29 +1030 Subject: [PATCH 06/14] stringify --- packages/common/src/interfaces/currentFilter.interface.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/common/src/interfaces/currentFilter.interface.ts b/packages/common/src/interfaces/currentFilter.interface.ts index 394b79d05..e3439d09f 100644 --- a/packages/common/src/interfaces/currentFilter.interface.ts +++ b/packages/common/src/interfaces/currentFilter.interface.ts @@ -17,6 +17,6 @@ export interface CurrentFilter { /** Target element selector from which the filter was triggered from. */ targetSelector?: string; - /** If true, stringifies the search terms as is without modification */ + /** If true, JSON.stringify is used on the searchTerms as is and used to build the filter query */ verbatimSearchTerms?: boolean; } From f3ce899782d653ff963ad93a69fd8d840ecad3ca Mon Sep 17 00:00:00 2001 From: Ronald Van Ryswyk Date: Fri, 3 Nov 2023 15:19:47 +1030 Subject: [PATCH 07/14] docuentation for `verbatimSearchTerms` --- packages/common/src/interfaces/currentFilter.interface.ts | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/packages/common/src/interfaces/currentFilter.interface.ts b/packages/common/src/interfaces/currentFilter.interface.ts index e3439d09f..1fff8fd92 100644 --- a/packages/common/src/interfaces/currentFilter.interface.ts +++ b/packages/common/src/interfaces/currentFilter.interface.ts @@ -17,6 +17,9 @@ export interface CurrentFilter { /** Target element selector from which the filter was triggered from. */ targetSelector?: string; - /** If true, JSON.stringify is used on the searchTerms as is and used to build the filter query */ + /** + * When false, searchTerms may be manipulated to be functional with certain filters eg: string only filters. + * When true, JSON.stringify is used on the searchTerms and used in the query "as-is". It is then the responsibility of the developer to sanitise the `searchTerms` property if necessary. + */ verbatimSearchTerms?: boolean; } From 391d9508d8a65f45b5eea9bb8e8a3104243b68a8 Mon Sep 17 00:00:00 2001 From: Ronald Van Ryswyk Date: Fri, 3 Nov 2023 16:41:13 +1030 Subject: [PATCH 08/14] Odata implementation of verbatimSearchTerms --- .../__tests__/grid-odata.service.spec.ts | 40 +++++++++++++++++++ .../odata/src/services/grid-odata.service.ts | 5 +++ 2 files changed, 45 insertions(+) diff --git a/packages/odata/src/services/__tests__/grid-odata.service.spec.ts b/packages/odata/src/services/__tests__/grid-odata.service.spec.ts index b0117bb24..85614357c 100644 --- a/packages/odata/src/services/__tests__/grid-odata.service.spec.ts +++ b/packages/odata/src/services/__tests__/grid-odata.service.spec.ts @@ -1532,6 +1532,46 @@ describe('GridOdataService', () => { }); }); + describe('updateFilters method', () => { + describe("Verbatim ColumnFilters", () => { + describe.each` + description | verbatim | operator | searchTerms | expectation + ${"Verbatim false, Filter for null"} | ${false} | ${'EQ'} | ${null} | ${'$top=10'} + ${"Verbatim true, Filter for null"} | ${true} | ${'EQ'} | ${null} | ${'$top=10&$filter=(gender EQ null)'} + ${"Verbatim false, Empty string"} | ${false} | ${'EQ'} | ${''} | ${'$top=10'} + ${"Verbatim true, Empty string"} | ${true} | ${'EQ'} | ${''} | ${'$top=10&$filter=(gender EQ \"\")'} + ${"Verbatim false, Empty list"} | ${false} | ${'IN'} | ${[]} | ${'$top=10'} + ${"Verbatim true, Empty list"} | ${true} | ${'IN'} | ${[]} | ${'$top=10&$filter=(gender IN [])'} + ${"Verbatim false, Filter for null (in list)"} | ${false} | ${'IN'} | ${[null]} | ${'$top=10'} + ${"Verbatim true, Filter for null (in list)"} | ${true} | ${'IN'} | ${[null]} | ${'$top=10&$filter=(gender IN [null])'} + ${"Verbatim false, Filter for empty string (in list)"} | ${false} | ${'IN'} | ${['']} | ${'$top=10'} + ${"Verbatim true, Filter for empty string (in list)"} | ${true} | ${'IN'} | ${['']} | ${'$top=10&$filter=(gender IN [\"\"])'} + ${"Verbatim false, Filter for female"} | ${false} | ${'IN'} | ${['female']} | ${'$top=10&$filter=(gender eq \'female\')'} + ${"Verbatim true, Filter for female"} | ${true} | ${'IN'} | ${['female']} | ${'$top=10&$filter=(gender IN [\"female\"])'} + ${"Verbatim false, Filter for female/male"} | ${false} | ${'IN'} | ${['female', 'male']} | ${'$top=10&$filter=(Gender eq \'female\' or Gender eq \'male\')'} + ${"Verbatim true, Filter for female/male"} | ${true} | ${'IN'} | ${['female', 'male']} | ${'$top=10&$filter=(gender IN [\"female\",\"male\"])'} + `(`$description`, ({ description, verbatim, operator, searchTerms, expectation }) => { + + const mockColumn = { id: 'gender', field: 'gender' } as Column; + let mockColumnFilters: ColumnFilters; + + beforeEach(() => { + mockColumnFilters = { + gender: { columnId: 'gender', columnDef: mockColumn, searchTerms, operator, type: FieldType.string, verbatimSearchTerms: verbatim }, + } as ColumnFilters; + + service.init(serviceOptions, paginationOptions, gridStub); + service.updateFilters(mockColumnFilters, false); + }); + + test(`buildQuery output matches ${expectation}`, () => { + const query = service.buildQuery(); + expect(query).toBe(expectation); + }); + }); + }); + }); + describe('presets', () => { afterEach(() => { jest.clearAllMocks(); diff --git a/packages/odata/src/services/grid-odata.service.ts b/packages/odata/src/services/grid-odata.service.ts index 8c99ab84c..e1efdb230 100644 --- a/packages/odata/src/services/grid-odata.service.ts +++ b/packages/odata/src/services/grid-odata.service.ts @@ -330,6 +330,11 @@ export class GridOdataService implements BackendService { throw new Error(`GridOData filter could not find the field name to query the search, your column definition must include a valid "field" or "name" (optionally you can also use the "queryfield").`); } + if (columnFilter.verbatimSearchTerms) { + searchByArray.push(`${fieldName} ${columnFilter.operator} ${JSON.stringify(columnFilter.searchTerms)}`.trim()); + continue; + } + fieldSearchValue = (fieldSearchValue === undefined || fieldSearchValue === null) ? '' : `${fieldSearchValue}`; // make sure it's a string // run regex to find possible filter operators unless the user disabled the feature From f64e5a9838f9e16e7015445a4cb86fe5a31e4a36 Mon Sep 17 00:00:00 2001 From: Ronald Van Ryswyk Date: Fri, 3 Nov 2023 16:47:29 +1030 Subject: [PATCH 09/14] spelling error --- .../odata/src/services/__tests__/grid-odata.service.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/odata/src/services/__tests__/grid-odata.service.spec.ts b/packages/odata/src/services/__tests__/grid-odata.service.spec.ts index 85614357c..4cb78b0a4 100644 --- a/packages/odata/src/services/__tests__/grid-odata.service.spec.ts +++ b/packages/odata/src/services/__tests__/grid-odata.service.spec.ts @@ -1548,7 +1548,7 @@ describe('GridOdataService', () => { ${"Verbatim true, Filter for empty string (in list)"} | ${true} | ${'IN'} | ${['']} | ${'$top=10&$filter=(gender IN [\"\"])'} ${"Verbatim false, Filter for female"} | ${false} | ${'IN'} | ${['female']} | ${'$top=10&$filter=(gender eq \'female\')'} ${"Verbatim true, Filter for female"} | ${true} | ${'IN'} | ${['female']} | ${'$top=10&$filter=(gender IN [\"female\"])'} - ${"Verbatim false, Filter for female/male"} | ${false} | ${'IN'} | ${['female', 'male']} | ${'$top=10&$filter=(Gender eq \'female\' or Gender eq \'male\')'} + ${"Verbatim false, Filter for female/male"} | ${false} | ${'IN'} | ${['female', 'male']} | ${'$top=10&$filter=(gender eq \'female\' or Gender eq \'male\')'} ${"Verbatim true, Filter for female/male"} | ${true} | ${'IN'} | ${['female', 'male']} | ${'$top=10&$filter=(gender IN [\"female\",\"male\"])'} `(`$description`, ({ description, verbatim, operator, searchTerms, expectation }) => { From ad2a4c1e40b5f9724ba958dcd20fce770e5f1e59 Mon Sep 17 00:00:00 2001 From: Ronald Van Ryswyk Date: Fri, 3 Nov 2023 17:06:36 +1030 Subject: [PATCH 10/14] spelling --- .../odata/src/services/__tests__/grid-odata.service.spec.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/odata/src/services/__tests__/grid-odata.service.spec.ts b/packages/odata/src/services/__tests__/grid-odata.service.spec.ts index 4cb78b0a4..7b35c3d00 100644 --- a/packages/odata/src/services/__tests__/grid-odata.service.spec.ts +++ b/packages/odata/src/services/__tests__/grid-odata.service.spec.ts @@ -1546,9 +1546,9 @@ describe('GridOdataService', () => { ${"Verbatim true, Filter for null (in list)"} | ${true} | ${'IN'} | ${[null]} | ${'$top=10&$filter=(gender IN [null])'} ${"Verbatim false, Filter for empty string (in list)"} | ${false} | ${'IN'} | ${['']} | ${'$top=10'} ${"Verbatim true, Filter for empty string (in list)"} | ${true} | ${'IN'} | ${['']} | ${'$top=10&$filter=(gender IN [\"\"])'} - ${"Verbatim false, Filter for female"} | ${false} | ${'IN'} | ${['female']} | ${'$top=10&$filter=(gender eq \'female\')'} + ${"Verbatim false, Filter for female"} | ${false} | ${'IN'} | ${['female']} | ${'$top=10&$filter=(Gender eq \'female\')'} ${"Verbatim true, Filter for female"} | ${true} | ${'IN'} | ${['female']} | ${'$top=10&$filter=(gender IN [\"female\"])'} - ${"Verbatim false, Filter for female/male"} | ${false} | ${'IN'} | ${['female', 'male']} | ${'$top=10&$filter=(gender eq \'female\' or Gender eq \'male\')'} + ${"Verbatim false, Filter for female/male"} | ${false} | ${'IN'} | ${['female', 'male']} | ${'$top=10&$filter=(Gender eq \'female\' or Gender eq \'male\')'} ${"Verbatim true, Filter for female/male"} | ${true} | ${'IN'} | ${['female', 'male']} | ${'$top=10&$filter=(gender IN [\"female\",\"male\"])'} `(`$description`, ({ description, verbatim, operator, searchTerms, expectation }) => { From a1fcbe97a93bf6ee5533cb4f2f3da023c75b99f5 Mon Sep 17 00:00:00 2001 From: Ronald Van Ryswyk Date: Mon, 6 Nov 2023 12:07:41 +1030 Subject: [PATCH 11/14] put the option on the graphql service directly --- .../src/interfaces/graphqlServiceOption.interface.ts | 6 ++++++ packages/graphql/src/services/graphql.service.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/graphql/src/interfaces/graphqlServiceOption.interface.ts b/packages/graphql/src/interfaces/graphqlServiceOption.interface.ts index 9d2c92bbe..d36598b04 100644 --- a/packages/graphql/src/interfaces/graphqlServiceOption.interface.ts +++ b/packages/graphql/src/interfaces/graphqlServiceOption.interface.ts @@ -40,4 +40,10 @@ export interface GraphqlServiceOption extends BackendServiceOption { * ex.: { field: "name", operator: EQ, value: "John" } */ keepArgumentFieldDoubleQuotes?: boolean; + + /** + * When false, searchTerms may be manipulated to be functional with certain filters eg: string only filters. + * When true, JSON.stringify is used on the searchTerms and used in the query "as-is". It is then the responsibility of the developer to sanitise the `searchTerms` property if necessary. + */ + verbatimSearchTerms?: boolean; } diff --git a/packages/graphql/src/services/graphql.service.ts b/packages/graphql/src/services/graphql.service.ts index f453752c3..a479625af 100644 --- a/packages/graphql/src/services/graphql.service.ts +++ b/packages/graphql/src/services/graphql.service.ts @@ -407,7 +407,7 @@ export class GraphqlService implements BackendService { throw new Error(`GraphQL filter could not find the field name to query the search, your column definition must include a valid "field" or "name" (optionally you can also use the "queryfield").`); } - if (columnFilter.verbatimSearchTerms) { + if (this.options?.verbatimSearchTerms || columnFilter.verbatimSearchTerms) { searchByArray.push({ field: fieldName, operator: columnFilter.operator, value: JSON.stringify(columnFilter.searchTerms) }); continue; } From e0104f5de7d3d53a2eba526a37e3189f5331482a Mon Sep 17 00:00:00 2001 From: Ronald Van Ryswyk Date: Wed, 8 Nov 2023 13:20:44 +1030 Subject: [PATCH 12/14] Rename to `useVerbatimSearchTerms` --- packages/common/src/interfaces/currentFilter.interface.ts | 2 +- .../graphql/src/interfaces/graphqlServiceOption.interface.ts | 4 ++-- .../graphql/src/services/__tests__/graphql.service.spec.ts | 2 +- packages/graphql/src/services/graphql.service.ts | 2 +- .../odata/src/services/__tests__/grid-odata.service.spec.ts | 2 +- packages/odata/src/services/grid-odata.service.ts | 2 +- 6 files changed, 7 insertions(+), 7 deletions(-) diff --git a/packages/common/src/interfaces/currentFilter.interface.ts b/packages/common/src/interfaces/currentFilter.interface.ts index 1fff8fd92..2951a2aa4 100644 --- a/packages/common/src/interfaces/currentFilter.interface.ts +++ b/packages/common/src/interfaces/currentFilter.interface.ts @@ -21,5 +21,5 @@ export interface CurrentFilter { * When false, searchTerms may be manipulated to be functional with certain filters eg: string only filters. * When true, JSON.stringify is used on the searchTerms and used in the query "as-is". It is then the responsibility of the developer to sanitise the `searchTerms` property if necessary. */ - verbatimSearchTerms?: boolean; + useVerbatimSearchTerms?: boolean; } diff --git a/packages/graphql/src/interfaces/graphqlServiceOption.interface.ts b/packages/graphql/src/interfaces/graphqlServiceOption.interface.ts index d36598b04..af1162c1f 100644 --- a/packages/graphql/src/interfaces/graphqlServiceOption.interface.ts +++ b/packages/graphql/src/interfaces/graphqlServiceOption.interface.ts @@ -23,7 +23,7 @@ export interface GraphqlServiceOption extends BackendServiceOption { */ extraQueryArguments?: QueryArgument[]; - /** (NOT FULLY IMPLEMENTED) Is the GraphQL Server using cursors? */ + /** Is the GraphQL Server using cursors? */ isWithCursor?: boolean; /** What are the pagination options? ex.: (first, last, offset) */ @@ -45,5 +45,5 @@ export interface GraphqlServiceOption extends BackendServiceOption { * When false, searchTerms may be manipulated to be functional with certain filters eg: string only filters. * When true, JSON.stringify is used on the searchTerms and used in the query "as-is". It is then the responsibility of the developer to sanitise the `searchTerms` property if necessary. */ - verbatimSearchTerms?: boolean; + useVerbatimSearchTerms?: boolean; } diff --git a/packages/graphql/src/services/__tests__/graphql.service.spec.ts b/packages/graphql/src/services/__tests__/graphql.service.spec.ts index bcaa60bf1..7cc161528 100644 --- a/packages/graphql/src/services/__tests__/graphql.service.spec.ts +++ b/packages/graphql/src/services/__tests__/graphql.service.spec.ts @@ -1261,7 +1261,7 @@ describe('GraphqlService', () => { beforeEach(() => { mockColumnFilters = { - gender: { columnId: 'gender', columnDef: mockColumn, searchTerms, operator, type: FieldType.string, verbatimSearchTerms: verbatim }, + gender: { columnId: 'gender', columnDef: mockColumn, searchTerms, operator, type: FieldType.string, useVerbatimSearchTerms: verbatim }, } as ColumnFilters; service.init(serviceOptions, paginationOptions, gridStub); diff --git a/packages/graphql/src/services/graphql.service.ts b/packages/graphql/src/services/graphql.service.ts index a479625af..8dfabfd66 100644 --- a/packages/graphql/src/services/graphql.service.ts +++ b/packages/graphql/src/services/graphql.service.ts @@ -407,7 +407,7 @@ export class GraphqlService implements BackendService { throw new Error(`GraphQL filter could not find the field name to query the search, your column definition must include a valid "field" or "name" (optionally you can also use the "queryfield").`); } - if (this.options?.verbatimSearchTerms || columnFilter.verbatimSearchTerms) { + if (this.options?.useVerbatimSearchTerms || columnFilter.useVerbatimSearchTerms) { searchByArray.push({ field: fieldName, operator: columnFilter.operator, value: JSON.stringify(columnFilter.searchTerms) }); continue; } diff --git a/packages/odata/src/services/__tests__/grid-odata.service.spec.ts b/packages/odata/src/services/__tests__/grid-odata.service.spec.ts index 7b35c3d00..20d4072ae 100644 --- a/packages/odata/src/services/__tests__/grid-odata.service.spec.ts +++ b/packages/odata/src/services/__tests__/grid-odata.service.spec.ts @@ -1557,7 +1557,7 @@ describe('GridOdataService', () => { beforeEach(() => { mockColumnFilters = { - gender: { columnId: 'gender', columnDef: mockColumn, searchTerms, operator, type: FieldType.string, verbatimSearchTerms: verbatim }, + gender: { columnId: 'gender', columnDef: mockColumn, searchTerms, operator, type: FieldType.string, useVerbatimSearchTerms: verbatim }, } as ColumnFilters; service.init(serviceOptions, paginationOptions, gridStub); diff --git a/packages/odata/src/services/grid-odata.service.ts b/packages/odata/src/services/grid-odata.service.ts index e1efdb230..0f8454cbe 100644 --- a/packages/odata/src/services/grid-odata.service.ts +++ b/packages/odata/src/services/grid-odata.service.ts @@ -330,7 +330,7 @@ export class GridOdataService implements BackendService { throw new Error(`GridOData filter could not find the field name to query the search, your column definition must include a valid "field" or "name" (optionally you can also use the "queryfield").`); } - if (columnFilter.verbatimSearchTerms) { + if (columnFilter.useVerbatimSearchTerms) { searchByArray.push(`${fieldName} ${columnFilter.operator} ${JSON.stringify(columnFilter.searchTerms)}`.trim()); continue; } From 386953db778933435bfb3afb108707426e718094 Mon Sep 17 00:00:00 2001 From: Ronald Van Ryswyk Date: Wed, 8 Nov 2023 13:55:13 +1030 Subject: [PATCH 13/14] useVerbatimSearchTerms for odata service --- packages/odata/src/interfaces/odataOption.interface.ts | 6 ++++++ packages/odata/src/services/grid-odata.service.ts | 2 +- 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/packages/odata/src/interfaces/odataOption.interface.ts b/packages/odata/src/interfaces/odataOption.interface.ts index 69529f3e4..1e68f40c8 100644 --- a/packages/odata/src/interfaces/odataOption.interface.ts +++ b/packages/odata/src/interfaces/odataOption.interface.ts @@ -43,6 +43,12 @@ export interface OdataOption extends BackendServiceOption { /** OData (or any other) version number (the query string is different between versions) */ version?: number; + /** + * When false, searchTerms may be manipulated to be functional with certain filters eg: string only filters. + * When true, JSON.stringify is used on the searchTerms and used in the query "as-is". It is then the responsibility of the developer to sanitise the `searchTerms` property if necessary. + */ + useVerbatimSearchTerms?: boolean; + /** A callback which will extract and return the count from the data queried. Defaults to 'd.__count' for v2, '__count' for v3 and '@odata.count' for v4. */ countExtractor?: (response: any) => number; diff --git a/packages/odata/src/services/grid-odata.service.ts b/packages/odata/src/services/grid-odata.service.ts index 0f8454cbe..4635292e5 100644 --- a/packages/odata/src/services/grid-odata.service.ts +++ b/packages/odata/src/services/grid-odata.service.ts @@ -330,7 +330,7 @@ export class GridOdataService implements BackendService { throw new Error(`GridOData filter could not find the field name to query the search, your column definition must include a valid "field" or "name" (optionally you can also use the "queryfield").`); } - if (columnFilter.useVerbatimSearchTerms) { + if (this._odataService.options.useVerbatimSearchTerms || columnFilter.useVerbatimSearchTerms) { searchByArray.push(`${fieldName} ${columnFilter.operator} ${JSON.stringify(columnFilter.searchTerms)}`.trim()); continue; } From 9de580e5687199075609725b44eaff74fe289f99 Mon Sep 17 00:00:00 2001 From: Ronald Van Ryswyk Date: Thu, 9 Nov 2023 11:01:33 +1030 Subject: [PATCH 14/14] slight rename --- packages/common/src/interfaces/currentFilter.interface.ts | 2 +- packages/graphql/src/services/__tests__/graphql.service.spec.ts | 2 +- packages/graphql/src/services/graphql.service.ts | 2 +- .../odata/src/services/__tests__/grid-odata.service.spec.ts | 2 +- packages/odata/src/services/grid-odata.service.ts | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/packages/common/src/interfaces/currentFilter.interface.ts b/packages/common/src/interfaces/currentFilter.interface.ts index 2951a2aa4..1fff8fd92 100644 --- a/packages/common/src/interfaces/currentFilter.interface.ts +++ b/packages/common/src/interfaces/currentFilter.interface.ts @@ -21,5 +21,5 @@ export interface CurrentFilter { * When false, searchTerms may be manipulated to be functional with certain filters eg: string only filters. * When true, JSON.stringify is used on the searchTerms and used in the query "as-is". It is then the responsibility of the developer to sanitise the `searchTerms` property if necessary. */ - useVerbatimSearchTerms?: boolean; + verbatimSearchTerms?: boolean; } diff --git a/packages/graphql/src/services/__tests__/graphql.service.spec.ts b/packages/graphql/src/services/__tests__/graphql.service.spec.ts index 7cc161528..bcaa60bf1 100644 --- a/packages/graphql/src/services/__tests__/graphql.service.spec.ts +++ b/packages/graphql/src/services/__tests__/graphql.service.spec.ts @@ -1261,7 +1261,7 @@ describe('GraphqlService', () => { beforeEach(() => { mockColumnFilters = { - gender: { columnId: 'gender', columnDef: mockColumn, searchTerms, operator, type: FieldType.string, useVerbatimSearchTerms: verbatim }, + gender: { columnId: 'gender', columnDef: mockColumn, searchTerms, operator, type: FieldType.string, verbatimSearchTerms: verbatim }, } as ColumnFilters; service.init(serviceOptions, paginationOptions, gridStub); diff --git a/packages/graphql/src/services/graphql.service.ts b/packages/graphql/src/services/graphql.service.ts index 8dfabfd66..f2bed1628 100644 --- a/packages/graphql/src/services/graphql.service.ts +++ b/packages/graphql/src/services/graphql.service.ts @@ -407,7 +407,7 @@ export class GraphqlService implements BackendService { throw new Error(`GraphQL filter could not find the field name to query the search, your column definition must include a valid "field" or "name" (optionally you can also use the "queryfield").`); } - if (this.options?.useVerbatimSearchTerms || columnFilter.useVerbatimSearchTerms) { + if (this.options?.useVerbatimSearchTerms || columnFilter.verbatimSearchTerms) { searchByArray.push({ field: fieldName, operator: columnFilter.operator, value: JSON.stringify(columnFilter.searchTerms) }); continue; } diff --git a/packages/odata/src/services/__tests__/grid-odata.service.spec.ts b/packages/odata/src/services/__tests__/grid-odata.service.spec.ts index 20d4072ae..7b35c3d00 100644 --- a/packages/odata/src/services/__tests__/grid-odata.service.spec.ts +++ b/packages/odata/src/services/__tests__/grid-odata.service.spec.ts @@ -1557,7 +1557,7 @@ describe('GridOdataService', () => { beforeEach(() => { mockColumnFilters = { - gender: { columnId: 'gender', columnDef: mockColumn, searchTerms, operator, type: FieldType.string, useVerbatimSearchTerms: verbatim }, + gender: { columnId: 'gender', columnDef: mockColumn, searchTerms, operator, type: FieldType.string, verbatimSearchTerms: verbatim }, } as ColumnFilters; service.init(serviceOptions, paginationOptions, gridStub); diff --git a/packages/odata/src/services/grid-odata.service.ts b/packages/odata/src/services/grid-odata.service.ts index 4635292e5..7daf03416 100644 --- a/packages/odata/src/services/grid-odata.service.ts +++ b/packages/odata/src/services/grid-odata.service.ts @@ -330,7 +330,7 @@ export class GridOdataService implements BackendService { throw new Error(`GridOData filter could not find the field name to query the search, your column definition must include a valid "field" or "name" (optionally you can also use the "queryfield").`); } - if (this._odataService.options.useVerbatimSearchTerms || columnFilter.useVerbatimSearchTerms) { + if (this._odataService.options.useVerbatimSearchTerms || columnFilter.verbatimSearchTerms) { searchByArray.push(`${fieldName} ${columnFilter.operator} ${JSON.stringify(columnFilter.searchTerms)}`.trim()); continue; }