Skip to content

Commit

Permalink
fix(gatsby): context.nodeModel.runQuery should return [] instead of n…
Browse files Browse the repository at this point in the history
…ull (#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]>
  • Loading branch information
kartikcho and vladar authored Feb 24, 2021
1 parent b49c5ed commit 684ac0e
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 11 deletions.
4 changes: 2 additions & 2 deletions packages/gatsby/src/redux/__tests__/run-fast-filters.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ describe(`fast filter tests`, () => {

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

it(`non-eq operator`, async () => {
Expand Down Expand Up @@ -353,7 +353,7 @@ describe(`fast filter tests`, () => {
filtersCache: new Map(),
})

expect(resultMany).toBe(null)
expect(resultMany).toEqual([])
})

it(`elemMatch on array of objects`, async () => {
Expand Down
5 changes: 1 addition & 4 deletions packages/gatsby/src/redux/run-fast-filters.ts
Original file line number Diff line number Diff line change
Expand Up @@ -417,10 +417,7 @@ function convertAndApplyFastFilters(
stats.totalSiftHits++
}

if (firstOnly) {
return []
}
return null
return []
}

function filterToStats(
Expand Down
10 changes: 5 additions & 5 deletions packages/gatsby/src/schema/__tests__/run-query.js
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,7 @@ describe(`Filter fields`, () => {
})

// Note: no coercion, so [8]=='8' is true but the comparison is strict
expect(result).toEqual(null)
expect(result).toEqual([])
})
})

Expand Down Expand Up @@ -769,7 +769,7 @@ describe(`Filter fields`, () => {

// Nothing is lt null so zero nodes should match
// (Note: this is different from `lte`, which does return nulls here!)
expect(result).toEqual(null)
expect(result).toEqual([])
expect(
allNodes.filter(node => node.nil === needle).length
).toBeGreaterThan(0) // They should _exist_...
Expand Down Expand Up @@ -972,7 +972,7 @@ describe(`Filter fields`, () => {
// Nothing is gt null so zero nodes should match
// (Note: this is different from `gte`, which does return nulls here!)
expect(result?.length ?? 0).toEqual(new Set(result ?? []).size) // result should contain unique elements
expect(result).toEqual(null)
expect(result).toEqual([])
expect(
allNodes.filter(node => node.nil === needle).length
).toBeGreaterThan(0) // They should _exist_...
Expand Down Expand Up @@ -1188,7 +1188,7 @@ describe(`Filter fields`, () => {
name: { regex: `/"/` },
})

expect(result).toEqual(null)
expect(result).toEqual([])
expect(allNodes.filter(node => node.name === `"`).length).toEqual(0)
})
})
Expand Down Expand Up @@ -1506,7 +1506,7 @@ describe(`Filter fields`, () => {
},
})

expect(result).toEqual(null)
expect(result).toEqual([])
})

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

0 comments on commit 684ac0e

Please sign in to comment.