Skip to content

Commit

Permalink
fix(GraphQL): filter <> is Not_Contains instead of Not_Equal (#…
Browse files Browse the repository at this point in the history
…1571)

- while investigating for issue #1569, I found that the GraphQL `<>` was set to be the equivalent of `!=` but this is in fact false, the `<>` is meant to represent `Not_Contains` while `!=` is meant to represent `Not_Equals` and they both work differently since `<>` is for a substring but the `!=` is for the entire string
  • Loading branch information
ghiscoding committed Jun 13, 2024
1 parent 9837ef1 commit c6f1cf3
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 9 deletions.
14 changes: 7 additions & 7 deletions packages/common/src/services/__tests__/utilities.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -747,16 +747,14 @@ describe('Service/Utilies', () => {
expect(output2).toBe(expectation);
});

it('should return OperatoryType associated to "<>", "!=", "neq" or "NEQ"', () => {
it('should return OperatoryType associated to "!=", "neq" or "NEQ"', () => {
const expectation = OperatorType.notEqual;

const output1 = mapOperatorType('<>');
const output2 = mapOperatorType('!=');
const output3 = mapOperatorType('NE');
const output1 = mapOperatorType('!=');
const output2 = mapOperatorType('NE');

expect(output1).toBe(expectation);
expect(output2).toBe(expectation);
expect(output3).toBe(expectation);
});

it('should return OperatoryType associated to "*", "a*", ".*", "startsWith"', () => {
Expand Down Expand Up @@ -814,11 +812,13 @@ describe('Service/Utilies', () => {
it('should return OperatoryType associated to "not_contains", "Not_Contains", "notContains"', () => {
const expectation = OperatorType.notContains;

const output1 = mapOperatorType('Not_Contains');
const output2 = mapOperatorType('NOT_CONTAINS');
const output1 = mapOperatorType('<>');
const output2 = mapOperatorType('Not_Contains');
const output3 = mapOperatorType('NOT_CONTAINS');

expect(output1).toBe(expectation);
expect(output2).toBe(expectation);
expect(output3).toBe(expectation);
});

it('should return default OperatoryType associated to contains', () => {
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/services/utilities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ export function mapOperatorType(operator: OperatorType | OperatorString): Operat
case 'GE':
map = OperatorType.greaterThanOrEqual;
break;
case '<>':
case '!=':
case 'NE':
map = OperatorType.notEqual;
Expand All @@ -451,6 +450,7 @@ export function mapOperatorType(operator: OperatorType | OperatorString): Operat
case 'NOT_IN':
map = OperatorType.notIn;
break;
case '<>':
case 'Not_Contains':
case 'NOT_CONTAINS':
map = OperatorType.notContains;
Expand Down
18 changes: 17 additions & 1 deletion packages/graphql/src/services/__tests__/graphql.service.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -758,7 +758,23 @@ describe('GraphqlService', () => {
expect(removeSpaces(query)).toBe(removeSpaces(expectation));
});

it('should return a query with multiple filters when the filters object has multiple search and they are passed as a filter trigger by a filter event and is of type ColumnFilters', () => {
it('should return a query with multiple filters when the filters object has multiple search with Equal & "<>" and they are passed as a filter trigger by a filter event and is of type ColumnFilters', () => {
const expectation = `query{users(first:10, offset:0, filterBy:[{field:gender, operator:EQ, value:"female"}, {field:company, operator:Not_Contains, value:"abc"}]) { totalCount,nodes{ id,company,gender,name } }}`;
const mockColumnGender = { id: 'gender', field: 'gender' } as Column;
const mockColumnCompany = { id: 'company', field: 'company' } as Column;
const mockColumnFilters = {
gender: { columnId: 'gender', columnDef: mockColumnGender, searchTerms: ['female'], operator: 'EQ', type: FieldType.string, },
company: { columnId: 'company', columnDef: mockColumnCompany, searchTerms: ['abc'], operator: '<>', type: FieldType.string, },
} as ColumnFilters;

service.init(serviceOptions, paginationOptions, gridStub);
service.updateFilters(mockColumnFilters, false);
const query = service.buildQuery();

expect(removeSpaces(query)).toBe(removeSpaces(expectation));
});

it('should return a query with multiple filters when the filters object has multiple search with Equal & Not Contains and they are passed as a filter trigger by a filter event and is of type ColumnFilters', () => {
const expectation = `query{users(first:10, offset:0, filterBy:[{field:gender, operator:EQ, value:"female"}, {field:company, operator:Not_Contains, value:"abc"}]) { totalCount,nodes{ id,company,gender,name } }}`;
const mockColumnGender = { id: 'gender', field: 'gender' } as Column;
const mockColumnCompany = { id: 'company', field: 'company' } as Column;
Expand Down

0 comments on commit c6f1cf3

Please sign in to comment.