Skip to content

Commit 8bf3013

Browse files
committed
Fix case insensitive IN operations
1 parent d6c1dda commit 8bf3013

File tree

2 files changed

+170
-60
lines changed

2 files changed

+170
-60
lines changed

packages/graphql/src/translate/queryAST/ast/filters/property-filters/PropertyFilter.ts

+7
Original file line numberDiff line numberDiff line change
@@ -154,6 +154,13 @@ export class PropertyFilter extends Filter {
154154
const coalesceProperty = coalesceValueIfNeeded(this.attribute, property);
155155

156156
if (this.caseInsensitive) {
157+
// Need to map all the items in the list to make case insensitive checks for lists
158+
if (operator === "IN") {
159+
const x = new Cypher.Variable();
160+
const lowercaseList = new Cypher.ListComprehension(x, param).map(Cypher.toLower(x));
161+
return Cypher.in(Cypher.toLower(coalesceProperty), lowercaseList);
162+
}
163+
157164
return createComparisonOperation({
158165
operator,
159166
property: Cypher.toLower(coalesceProperty),

packages/graphql/tests/integration/filtering/case-insensitive-string.int.test.ts

+163-60
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,8 @@ describe("Filtering case insensitive string", () => {
6767
filters: {
6868
String: {
6969
CASE_INSENSITIVE: true,
70+
GTE: true,
71+
MATCHES: true,
7072
},
7173
},
7274
},
@@ -77,19 +79,18 @@ describe("Filtering case insensitive string", () => {
7779
await testHelper.close();
7880
});
7981

80-
it("case insensitive eq", async () => {
82+
test("case insensitive gte", async () => {
8183
const query = /* GraphQL */ `
82-
query {
83-
${Movie.plural}(where: { title: { caseInsensitive: { eq: "the matrix" } } }) {
84-
title
85-
}
84+
query {
85+
${Movie.plural}(where: { title: { caseInsensitive: { gte: "The Matrix" } } }) {
86+
title
8687
}
87-
`;
88+
}
89+
`;
8890

8991
const result = await testHelper.executeGraphQL(query);
9092

9193
expect(result.errors).toBeUndefined();
92-
9394
expect(result.data).toEqual({
9495
[Movie.plural]: expect.toIncludeSameMembers([
9596
{
@@ -102,30 +103,131 @@ describe("Filtering case insensitive string", () => {
102103
});
103104
});
104105

105-
it("case insensitive eq on related type filter", async () => {
106+
test("case insensitive in", async () => {
106107
const query = /* GraphQL */ `
107-
query {
108-
${Person.plural}(where: { movies: { none: { title: { caseInsensitive: { eq: "the matrix" } } } } }) {
109-
name
110-
}
108+
query {
109+
${Movie.plural}(where: { title: { caseInsensitive: { in: ["the matrix", "THE LION KING"] } } }) {
110+
title
111111
}
112-
`;
112+
}
113+
`;
113114

114115
const result = await testHelper.executeGraphQL(query);
115116

116117
expect(result.errors).toBeUndefined();
118+
expect(result.data).toEqual({
119+
[Movie.plural]: expect.toIncludeSameMembers([
120+
{
121+
title: "The Matrix",
122+
},
123+
{
124+
title: "THE MATRIX",
125+
},
126+
{
127+
title: "The Lion King",
128+
},
129+
]),
130+
});
131+
});
117132

133+
test("case insensitive contains", async () => {
134+
const query = /* GraphQL */ `
135+
query {
136+
${Movie.plural}(where: { title: { caseInsensitive: { contains: "Matrix" } } }) {
137+
title
138+
}
139+
}
140+
`;
141+
142+
const result = await testHelper.executeGraphQL(query);
143+
144+
expect(result.errors).toBeUndefined();
118145
expect(result.data).toEqual({
119-
[Person.plural]: [
146+
[Movie.plural]: expect.toIncludeSameMembers([
120147
{
121-
name: "Arthur Dent",
148+
title: "The Matrix",
122149
},
123-
],
150+
{
151+
title: "THE MATRIX",
152+
},
153+
]),
124154
});
125155
});
126156

127-
it("case insensitive eq in connection", async () => {
157+
test("case insensitive endsWith", async () => {
128158
const query = /* GraphQL */ `
159+
query {
160+
${Movie.plural}(where: { title: { caseInsensitive: { endsWith: "RIX" } } }) {
161+
title
162+
}
163+
}
164+
`;
165+
166+
const result = await testHelper.executeGraphQL(query);
167+
168+
expect(result.errors).toBeUndefined();
169+
expect(result.data).toEqual({
170+
[Movie.plural]: expect.toIncludeSameMembers([
171+
{
172+
title: "The Matrix",
173+
},
174+
{
175+
title: "THE MATRIX",
176+
},
177+
]),
178+
});
179+
});
180+
181+
describe("eq", () => {
182+
test("case insensitive eq", async () => {
183+
const query = /* GraphQL */ `
184+
query {
185+
${Movie.plural}(where: { title: { caseInsensitive: { eq: "the matrix" } } }) {
186+
title
187+
}
188+
}
189+
`;
190+
191+
const result = await testHelper.executeGraphQL(query);
192+
193+
expect(result.errors).toBeUndefined();
194+
195+
expect(result.data).toEqual({
196+
[Movie.plural]: expect.toIncludeSameMembers([
197+
{
198+
title: "The Matrix",
199+
},
200+
{
201+
title: "THE MATRIX",
202+
},
203+
]),
204+
});
205+
});
206+
207+
test("case insensitive eq on related type filter", async () => {
208+
const query = /* GraphQL */ `
209+
query {
210+
${Person.plural}(where: { movies: { none: { title: { caseInsensitive: { eq: "the matrix" } } } } }) {
211+
name
212+
}
213+
}
214+
`;
215+
216+
const result = await testHelper.executeGraphQL(query);
217+
218+
expect(result.errors).toBeUndefined();
219+
220+
expect(result.data).toEqual({
221+
[Person.plural]: [
222+
{
223+
name: "Arthur Dent",
224+
},
225+
],
226+
});
227+
});
228+
229+
test("case insensitive eq in connection", async () => {
230+
const query = /* GraphQL */ `
129231
query {
130232
${Movie.operations.connection}(where: { title: { caseInsensitive: { eq: "the matrix" } } }) {
131233
edges {
@@ -137,30 +239,30 @@ describe("Filtering case insensitive string", () => {
137239
}
138240
`;
139241

140-
const result = await testHelper.executeGraphQL(query);
242+
const result = await testHelper.executeGraphQL(query);
141243

142-
expect(result.errors).toBeUndefined();
244+
expect(result.errors).toBeUndefined();
143245

144-
expect(result.data).toEqual({
145-
[Movie.operations.connection]: {
146-
edges: expect.toIncludeSameMembers([
147-
{
148-
node: {
149-
title: "The Matrix",
246+
expect(result.data).toEqual({
247+
[Movie.operations.connection]: {
248+
edges: expect.toIncludeSameMembers([
249+
{
250+
node: {
251+
title: "The Matrix",
252+
},
150253
},
151-
},
152-
{
153-
node: {
154-
title: "THE MATRIX",
254+
{
255+
node: {
256+
title: "THE MATRIX",
257+
},
155258
},
156-
},
157-
]),
158-
},
259+
]),
260+
},
261+
});
159262
});
160-
});
161263

162-
it("case insensitive eq on related node filter in connection", async () => {
163-
const query = /* GraphQL */ `
264+
test("case insensitive eq on related node filter in connection", async () => {
265+
const query = /* GraphQL */ `
164266
query {
165267
${Person.operations.connection}(where: { moviesConnection: { none: { node: { title: { caseInsensitive: { eq: "the matrix" } } } } } }) {
166268
edges {
@@ -172,25 +274,25 @@ describe("Filtering case insensitive string", () => {
172274
}
173275
`;
174276

175-
const result = await testHelper.executeGraphQL(query);
277+
const result = await testHelper.executeGraphQL(query);
176278

177-
expect(result.errors).toBeUndefined();
279+
expect(result.errors).toBeUndefined();
178280

179-
expect(result.data).toEqual({
180-
[Person.operations.connection]: {
181-
edges: [
182-
{
183-
node: {
184-
name: "Arthur Dent",
281+
expect(result.data).toEqual({
282+
[Person.operations.connection]: {
283+
edges: [
284+
{
285+
node: {
286+
name: "Arthur Dent",
287+
},
185288
},
186-
},
187-
],
188-
},
289+
],
290+
},
291+
});
189292
});
190-
});
191293

192-
it("case insensitive eq on related edge filter in connection", async () => {
193-
const query = /* GraphQL */ `
294+
test("case insensitive eq on related edge filter in connection", async () => {
295+
const query = /* GraphQL */ `
194296
query {
195297
${Person.operations.connection}(where: { moviesConnection: { none: { edge: { character: { caseInsensitive: { eq: "NEO" } } } } } }) {
196298
edges {
@@ -202,20 +304,21 @@ describe("Filtering case insensitive string", () => {
202304
}
203305
`;
204306

205-
const result = await testHelper.executeGraphQL(query);
307+
const result = await testHelper.executeGraphQL(query);
206308

207-
expect(result.errors).toBeUndefined();
309+
expect(result.errors).toBeUndefined();
208310

209-
expect(result.data).toEqual({
210-
[Person.operations.connection]: {
211-
edges: [
212-
{
213-
node: {
214-
name: "Arthur Dent",
311+
expect(result.data).toEqual({
312+
[Person.operations.connection]: {
313+
edges: [
314+
{
315+
node: {
316+
name: "Arthur Dent",
317+
},
215318
},
216-
},
217-
],
218-
},
319+
],
320+
},
321+
});
219322
});
220323
});
221324
});

0 commit comments

Comments
 (0)