-
-
Notifications
You must be signed in to change notification settings - Fork 600
fix: Parse.Query.findAll returns empty array calling withCount
#2854
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
base: alpha
Are you sure you want to change the base?
Conversation
|
🚀 Thanks for opening this pull request! |
📝 WalkthroughWalkthroughUpdates handling of count-wrapped query responses: Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Suggested reviewers
🚥 Pre-merge checks | ✅ 3 | ❌ 2❌ Failed checks (1 warning, 1 inconclusive)
✅ Passed checks (3 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
✅ Snyk checks have passed. No issues have been found so far.
💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## alpha #2854 +/- ##
=======================================
Coverage 99.88% 99.88%
=======================================
Files 64 64
Lines 6222 6227 +5
Branches 1473 1475 +2
=======================================
+ Hits 6215 6220 +5
Misses 7 7 ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
🧹 Nitpick comments (3)
src/EventuallyQueue.ts (1)
345-353: Prefer unwrappingfind’s union result instead ofany
query.findnow returnsT[] | { results: T[]; count: number }, butresultsis typed asanyand used asresults[0]. That works today (nowithCount/jsonhere) but hides type issues if this ever changes.You can keep this future‑proof and typed without
any:Suggested unwrapping
- const results: any = await query.find({ sessionToken }); - if (results.length > 0) { - return EventuallyQueue.sendQueueCallback(results[0], queueObject); - } + const response = await query.find({ sessionToken }); + const results = Array.isArray(response) ? response : response.results || []; + if (results.length > 0) { + return EventuallyQueue.sendQueueCallback(results[0], queueObject); + }types/ParseQuery.d.ts (1)
228-231: Updatedfind/findAlltypings correctly model count-wrapped resultsThe new union return types for
findandfindAllalign with the runtime behavior whenwithCountis used and with the implementation insrc/ParseQuery.ts. This is a reasonable breaking typing change and matches the tests’ expectations.If you want to reduce duplication later, you could alias the wrapped shape (e.g.,
type FindWithCountResult<T> = { results: T[]; count: number }) and reuse it here, but that’s purely cosmetic.Also applies to: 247-250
types/tests.ts (1)
907-932: Minor mismatch betweenFieldTypeandnotGeopointExclude target
FieldTypenow includesParse.GeoPoint(notParse.GeoPoint[]), butnotGeopointis defined asExclude<FieldType, Parse.GeoPoint[]>. This still makes the$ExpectErrorcall behave as intended, but the type is misleading.You can tighten this to reflect the actual union:
Optional cleanup
- notGeopoint: Exclude<FieldType, Parse.GeoPoint[]>, + notGeopoint: Exclude<FieldType, Parse.GeoPoint>,
📜 Review details
Configuration used: Organization UI
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (5)
integration/test/ParseQueryTest.jssrc/EventuallyQueue.tssrc/ParseQuery.tstypes/ParseQuery.d.tstypes/tests.ts
🧰 Additional context used
🧬 Code graph analysis (2)
src/EventuallyQueue.ts (1)
src/ParseRelation.ts (1)
query(120-141)
integration/test/ParseQueryTest.js (2)
src/ParseRelation.ts (1)
query(120-141)src/ParseQuery.ts (1)
count(765-780)
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (3)
- GitHub Check: build (Node 24, 24.1.0)
- GitHub Check: build (Node 20, 20.19.0)
- GitHub Check: build (Node 22, 22.12.0)
🔇 Additional comments (7)
types/tests.ts (1)
2048-2053: Type test expectations forfind/findAllmatch new union returnThe updated
$ExpectTypeannotations forqueryUntyped.find(),queryUntyped.findAll(), andqueryTyped.find()correctly capture the newT[] | { results: T[]; count: number }return type shape and keep the typings in sync withParseQuery.d.tsand the implementation.Also applies to: 2063-2064
src/ParseQuery.ts (3)
678-721:findunion return type is consistent with runtime behaviorThe updated
findsignature (Promise<T[] | { results: T[]; count: number }>), plus the conditional{ results, count }wrapping whenresponse.countis present, matches how the method already behaves (including offline queries via_handleOfflineQuery). No issues spotted here.
739-748:findAllcorrectly returns{ results, count }whenwithCountis enabledThe new
findAllimplementation:
- Uses
eachBatchto load all pages.- Aggregates all objects into a single
resultsarray.- When
_countis true (fromwithCount(true)), returns{ results, count: results.length }; otherwise returnsresultsdirectly.This satisfies the desired behavior for
findAll+withCountwithout coupling to server-sidecount, and preserves existingjsonbehavior.
936-944: Unwrapping{ results, count }ineachBatchfixes the pagination bugThe new unwrapping:
const [response] = await Promise.all([query.find(findOptions), ...]); let results: any = response; if (results.results) { results = results.results; }ensures that
resultsis always an array before.lengthis used for pagination. This removes the previous failure mode wherewithCount(true)causedresultsto be an object andresults.lengthwasundefined, short-circuitingfindAllwith an empty result.integration/test/ParseQueryTest.js (3)
55-63: Raw JSON tests now exercise bothfindandfindAllUsing
let results = await query.find({ json: true });followed byresults = await query.findAll({ json: true });and asserting onresults[0]validates that both methods return raw JSON whenjson: trueandwithCountis not used. This aligns with the implementation and helps guard the json-path behavior after the union-type changes.
110-127: NewfindAll+withCounttest directly covers the original bug
it('can do findAll query with count', ...)exercises:
- Creating multiple matching objects.
- Calling
query.withCount(true);- Using
const { results, count } = await query.findAll();and asserts both
results.lengthandcountare 4. This is exactly the scenario that was previously returning an empty array due to the pagination bug, so this test is a solid regression guard.
2419-2429:explain(false)test confirms explicit disable of explain modeThe
it('can query with explain false', ...)case verifies that callingquery.explain(false);restores normalfind()behavior (array of 3 objects, not an explain plan). This matches theexplain(explain = true)implementation and ensures toggling the flag works as intended.
Pull Request
Issue
Closes: #2621
Approach
withCountSummary by CodeRabbit
New Features
Tests
Type Updates
✏️ Tip: You can customize this high-level summary in your review settings.