Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(gatsby): context.nodeModel.runQuery should return [] instead of null #25885

Merged
merged 7 commits into from
Feb 24, 2021
Merged
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
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) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

iirc there were one or two other places where this happens (returning null vs returning an empty array) but maybe I already unified those into this check here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What do you want to update here @pvdz?

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