Skip to content
This repository has been archived by the owner on Sep 3, 2021. It is now read-only.

Adds case insensitive filter #449

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions src/augment/input-values.js
Original file line number Diff line number Diff line change
Expand Up @@ -408,6 +408,7 @@ const buildPropertyFilters = ({
'in',
'not_in',
'contains',
'contains_i',
'not_contains',
'starts_with',
'not_starts_with',
Expand Down
30 changes: 27 additions & 3 deletions src/translate.js
Original file line number Diff line number Diff line change
Expand Up @@ -2447,9 +2447,12 @@ const translateFilterArgument = ({
innerSchemaType = schema.getType(typeName);
}
// build path for parameter data for current filter field
const parameterPath = `${
parentParamPath ? parentParamPath : filterParam
}.${fieldName}`;
const parameterPath = buildParamaterPathExpression({
parentParamPath,
filterParam,
fieldName,
filterOperationType
});
// short-circuit evaluation: predicate used to skip a field
// if processing a list of objects that possibly contain different arguments
const nullFieldPredicate = decideNullSkippingPredicate({
Expand Down Expand Up @@ -2504,6 +2507,7 @@ const parseFilterArgumentName = fieldName => {
'_in',
'_not_in',
'_contains',
'_contains_i',
'_not_contains',
'_starts_with',
'_not_starts_with',
Expand Down Expand Up @@ -2555,6 +2559,24 @@ const parseFilterArgumentName = fieldName => {
};
};

const buildParamaterPathExpression = ({
parentParamPath,
filterParam,
fieldName,
filterOperationType
}) => {
// build path for parameter data for current filter field
const parameterPath = `${
parentParamPath ? parentParamPath : filterParam
}.${fieldName}`;
// may need to call expression on path value depending on filter type
if (filterOperationType.slice(-2) === '_i') {
// case insensitive
return `toLower(${parameterPath})`;
}
return parameterPath;
};

const translateScalarFilter = ({
isListFilterArgument,
filterOperationField,
Expand Down Expand Up @@ -2638,6 +2660,8 @@ const buildOperatorExpression = ({
return `NOT ${propertyPath} IN`;
case 'contains':
return `${propertyPath} CONTAINS`;
case 'contains_i':
return `toLower(${propertyPath}) CONTAINS`;
case 'not_contains':
return `NOT ${propertyPath} CONTAINS`;
case 'starts_with':
Expand Down
9 changes: 7 additions & 2 deletions test/helpers/testSchema.js
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ export const testSchema = `
releases: [DateTime]
customField: String @neo4j_ignore
}

extend type Movie {
currentUserId(strArg: String): String
@cypher(
Expand Down Expand Up @@ -112,6 +112,7 @@ export const testSchema = `
userId_in: [ID!]
userId_not_in: [ID!]
userId_contains: ID
userId_contains_i: ID
userId_not_contains: ID
userId_starts_with: ID
userId_not_starts_with: ID
Expand All @@ -122,6 +123,7 @@ export const testSchema = `
name_in: [String!]
name_not_in: [String!]
name_contains: String
name_contains_i: String
name_not_contains: String
name_starts_with: String
name_not_starts_with: String
Expand Down Expand Up @@ -403,6 +405,7 @@ export const testSchema = `
id_in: [ID!]
id_not_in: [ID!]
id_contains: ID
id_contains_i: ID
id_not_contains: ID
id_starts_with: ID
id_not_starts_with: ID
Expand All @@ -413,6 +416,7 @@ export const testSchema = `
type_in: [String!]
type_not_in: [String!]
type_contains: String
type_contains_i: String
type_not_contains: String
type_starts_with: String
type_not_starts_with: String
Expand All @@ -423,6 +427,7 @@ export const testSchema = `
make_in: [String!]
make_not_in: [String!]
make_contains: String
make_contains_i: String
make_not_contains: String
make_starts_with: String
make_not_starts_with: String
Expand Down Expand Up @@ -529,7 +534,7 @@ export const testSchema = `
query: QueryA
subscription: SubscriptionC
}

extend schema {
mutation: Mutation
}
Expand Down
Loading