Skip to content

Commit 684ac0e

Browse files
kartikchovladar
andauthored
fix(gatsby): context.nodeModel.runQuery should return [] instead of null (#25885)
* Update context.nodeModel.runQuery to return [] * Update run-fast-filters.ts Co-authored-by: Vladimir Razuvaev <[email protected]> * Update tests to expect [] * fix test Co-authored-by: Vladimir Razuvaev <[email protected]>
1 parent b49c5ed commit 684ac0e

File tree

3 files changed

+8
-11
lines changed

3 files changed

+8
-11
lines changed

packages/gatsby/src/redux/__tests__/run-fast-filters.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,7 @@ describe(`fast filter tests`, () => {
187187

188188
// `id-1` node is not of queried type, so results should be empty
189189
expect(resultSingular).toEqual([])
190-
expect(resultMany).toEqual(null)
190+
expect(resultMany).toEqual([])
191191
})
192192

193193
it(`non-eq operator`, async () => {
@@ -353,7 +353,7 @@ describe(`fast filter tests`, () => {
353353
filtersCache: new Map(),
354354
})
355355

356-
expect(resultMany).toBe(null)
356+
expect(resultMany).toEqual([])
357357
})
358358

359359
it(`elemMatch on array of objects`, async () => {

packages/gatsby/src/redux/run-fast-filters.ts

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -417,10 +417,7 @@ function convertAndApplyFastFilters(
417417
stats.totalSiftHits++
418418
}
419419

420-
if (firstOnly) {
421-
return []
422-
}
423-
return null
420+
return []
424421
}
425422

426423
function filterToStats(

packages/gatsby/src/schema/__tests__/run-query.js

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ describe(`Filter fields`, () => {
473473
})
474474

475475
// Note: no coercion, so [8]=='8' is true but the comparison is strict
476-
expect(result).toEqual(null)
476+
expect(result).toEqual([])
477477
})
478478
})
479479

@@ -769,7 +769,7 @@ describe(`Filter fields`, () => {
769769

770770
// Nothing is lt null so zero nodes should match
771771
// (Note: this is different from `lte`, which does return nulls here!)
772-
expect(result).toEqual(null)
772+
expect(result).toEqual([])
773773
expect(
774774
allNodes.filter(node => node.nil === needle).length
775775
).toBeGreaterThan(0) // They should _exist_...
@@ -972,7 +972,7 @@ describe(`Filter fields`, () => {
972972
// Nothing is gt null so zero nodes should match
973973
// (Note: this is different from `gte`, which does return nulls here!)
974974
expect(result?.length ?? 0).toEqual(new Set(result ?? []).size) // result should contain unique elements
975-
expect(result).toEqual(null)
975+
expect(result).toEqual([])
976976
expect(
977977
allNodes.filter(node => node.nil === needle).length
978978
).toBeGreaterThan(0) // They should _exist_...
@@ -1188,7 +1188,7 @@ describe(`Filter fields`, () => {
11881188
name: { regex: `/"/` },
11891189
})
11901190

1191-
expect(result).toEqual(null)
1191+
expect(result).toEqual([])
11921192
expect(allNodes.filter(node => node.name === `"`).length).toEqual(0)
11931193
})
11941194
})
@@ -1506,7 +1506,7 @@ describe(`Filter fields`, () => {
15061506
},
15071507
})
15081508

1509-
expect(result).toEqual(null)
1509+
expect(result).toEqual([])
15101510
})
15111511

15121512
it(`handles the elemMatch operator for array of objects (1)`, async () => {

0 commit comments

Comments
 (0)