Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: Graphql verbatim search terms #1174

Merged
2 changes: 1 addition & 1 deletion packages/common/src/interfaces/currentFilter.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Copy link
Owner

@ghiscoding ghiscoding Nov 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

oh I think I didn't explain well, I wanted to keep this one as verbatimSearchTerms because this one here is not a flag but a prop, so can you rename it back to verbatimSearchTerms?

}
Original file line number Diff line number Diff line change
Expand Up @@ -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) */
Expand All @@ -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;
ghiscoding marked this conversation as resolved.
Show resolved Hide resolved
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/graphql/src/services/graphql.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
6 changes: 6 additions & 0 deletions packages/odata/src/interfaces/odataOption.interface.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion packages/odata/src/services/grid-odata.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 (this._odataService.options.useVerbatimSearchTerms || columnFilter.useVerbatimSearchTerms) {
searchByArray.push(`${fieldName} ${columnFilter.operator} ${JSON.stringify(columnFilter.searchTerms)}`.trim());
continue;
}
Expand Down