Skip to content

Conversation

@dplewis
Copy link
Member

@dplewis dplewis commented Jan 7, 2026

Pull Request

Issue

Closes: #2621

Approach

  • Allow findAll to work properly with withCount
  • Improve typings
  • Fix flaky test

Summary by CodeRabbit

  • New Features

    • find() and findAll() can return results with optional count metadata to simplify paginated responses.
  • Tests

    • Added coverage for raw-JSON query results, count-aware batch pagination, explain-option behavior, and adjusted live-query test timing/cleanup.
  • Type Updates

    • Expanded field type support to include boolean, Date, File, GeoPoint, arrays, and object types for richer schema testing.

✏️ Tip: You can customize this high-level summary in your review settings.

@parse-github-assistant
Copy link

parse-github-assistant bot commented Jan 7, 2026

🚀 Thanks for opening this pull request!

@coderabbitai
Copy link

coderabbitai bot commented Jan 7, 2026

📝 Walkthrough

Walkthrough

Updates handling of count-wrapped query responses: find/findAll now accept and return either plain result arrays or { results, count }, add response-unwrapping and batching fixes, expand related type definitions, and add tests for raw JSON, findAll with count, and explain(false).

Changes

Cohort / File(s) Summary
Query runtime & signatures
src/ParseQuery.ts
find and findAll now return `Promise<T[]
Type declarations
types/ParseQuery.d.ts, types/tests.ts
Broadened find/findAll return types to include { results, count }; expanded FieldType union and updated test typings to match new return shape.
Tests
integration/test/ParseQueryTest.js, src/__tests__/ParseQuery-test.js, integration/test/ParseLiveQueryTest.js, integration/test/ParseQueryTest.js
Added/updated tests for raw JSON retrieval ({ json: true }), findAll with withCount(true), explain(false), and adjusted LiveQuery test cleanup timing.
Minor typing / annotations
src/EventuallyQueue.ts
Added explicit any annotation for results in byHash to satisfy TypeScript inference.
Test typings adjustments
types/tests.ts
Updated expectations for untyped/typed query find() and findAll() to accept union return form.

Estimated code review effort

🎯 3 (Moderate) | ⏱️ ~20 minutes

Suggested reviewers

  • mtrezza
  • kinetifex
🚥 Pre-merge checks | ✅ 3 | ❌ 2
❌ Failed checks (1 warning, 1 inconclusive)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
Out of Scope Changes check ❓ Inconclusive Most changes directly address the withCount+findAll issue. Minor out-of-scope changes include: (1) FieldType expansion in types/tests.ts (testing utility, not core issue), (2) removal of delay/unsubscribe in ParseLiveQueryTest.js (unrelated test cleanup), (3) EventuallyQueue.ts type annotation (minor improvement). The type expansion in types/tests.ts and test cleanup in ParseLiveQueryTest.js appear tangential to the primary issue; clarify if these changes are necessary or should be submitted separately.
✅ Passed checks (3 passed)
Check name Status Explanation
Title check ✅ Passed The title clearly describes the main fix: resolving an issue where Parse.Query.findAll returns an empty array when withCount is called, which directly aligns with the primary change across the codebase.
Linked Issues check ✅ Passed The PR successfully addresses issue #2621 by: (1) modifying find/findAll return types to support count wrapping [types/ParseQuery.d.ts, src/ParseQuery.ts], (2) implementing logic to unwrap count responses in batch pagination [src/ParseQuery.ts], (3) adding comprehensive tests for findAll with count [src/tests/ParseQuery-test.js, integration/test/ParseQueryTest.js].
Description check ✅ Passed The pull request description follows the required template and includes all essential components: a linked issue, a clear approach section describing the changes, and task checkboxes indicating the types of modifications made.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing touches
  • 📝 Generate docstrings
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@parseplatformorg
Copy link
Contributor

parseplatformorg commented Jan 7, 2026

Snyk checks have passed. No issues have been found so far.

Status Scanner Critical High Medium Low Total (0)
Open Source Security 0 0 0 0 0 issues

💻 Catch issues earlier using the plugins for VS Code, JetBrains IDEs, Visual Studio, and Eclipse.

@codecov
Copy link

codecov bot commented Jan 7, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 99.88%. Comparing base (cf2ef13) to head (a880e85).

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.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

Copy link

@coderabbitai coderabbitai bot left a 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 unwrapping find’s union result instead of any

query.find now returns T[] | { results: T[]; count: number }, but results is typed as any and used as results[0]. That works today (no withCount / json here) 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: Updated find / findAll typings correctly model count-wrapped results

The new union return types for find and findAll align with the runtime behavior when withCount is used and with the implementation in src/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 between FieldType and notGeopoint Exclude target

FieldType now includes Parse.GeoPoint (not Parse.GeoPoint[]), but notGeopoint is defined as Exclude<FieldType, Parse.GeoPoint[]>. This still makes the $ExpectError call 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

📥 Commits

Reviewing files that changed from the base of the PR and between cf2ef13 and 84c8526.

📒 Files selected for processing (5)
  • integration/test/ParseQueryTest.js
  • src/EventuallyQueue.ts
  • src/ParseQuery.ts
  • types/ParseQuery.d.ts
  • types/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 for find / findAll match new union return

The updated $ExpectType annotations for queryUntyped.find(), queryUntyped.findAll(), and queryTyped.find() correctly capture the new T[] | { results: T[]; count: number } return type shape and keep the typings in sync with ParseQuery.d.ts and the implementation.

Also applies to: 2063-2064

src/ParseQuery.ts (3)

678-721: find union return type is consistent with runtime behavior

The updated find signature (Promise<T[] | { results: T[]; count: number }>), plus the conditional { results, count } wrapping when response.count is present, matches how the method already behaves (including offline queries via _handleOfflineQuery). No issues spotted here.


739-748: findAll correctly returns { results, count } when withCount is enabled

The new findAll implementation:

  • Uses eachBatch to load all pages.
  • Aggregates all objects into a single results array.
  • When _count is true (from withCount(true)), returns { results, count: results.length }; otherwise returns results directly.

This satisfies the desired behavior for findAll+withCount without coupling to server-side count, and preserves existing json behavior.


936-944: Unwrapping { results, count } in eachBatch fixes the pagination bug

The new unwrapping:

const [response] = await Promise.all([query.find(findOptions), ...]);
let results: any = response;
if (results.results) {
  results = results.results;
}

ensures that results is always an array before .length is used for pagination. This removes the previous failure mode where withCount(true) caused results to be an object and results.length was undefined, short-circuiting findAll with an empty result.

integration/test/ParseQueryTest.js (3)

55-63: Raw JSON tests now exercise both find and findAll

Using let results = await query.find({ json: true }); followed by results = await query.findAll({ json: true }); and asserting on results[0] validates that both methods return raw JSON when json: true and withCount is not used. This aligns with the implementation and helps guard the json-path behavior after the union-type changes.


110-127: New findAll + withCount test 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.length and count are 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 mode

The it('can query with explain false', ...) case verifies that calling query.explain(false); restores normal find() behavior (array of 3 objects, not an explain plan). This matches the explain(explain = true) implementation and ensures toggling the flag works as intended.

coderabbitai[bot]
coderabbitai bot previously approved these changes Jan 7, 2026
@dplewis dplewis requested a review from a team January 8, 2026 03:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

After calling withCount on Parse.Query, findAll returns empty array regardless of result

2 participants