Skip to content

fix: comment cursor throws on COMMENT_PARENT orderby pagination#3964

Merged
jasonbahl merged 2 commits into
mainfrom
fix/3068-comment-cursor-orderby-parent
Jun 24, 2026
Merged

fix: comment cursor throws on COMMENT_PARENT orderby pagination#3964
jasonbahl merged 2 commits into
mainfrom
fix/3068-comment-cursor-orderby-parent

Conversation

@jasonbahl

Copy link
Copy Markdown
Collaborator

What

Fixes #3068.

CommentObjectCursor::get_where() builds a fallback cursor-compare field when no orderby has populated the query builder. That fallback array used the key 'by' instead of the 'value' key that AbstractCursor::compare_with_cursor_fields() (and its validator validate_cursor_compare_field()) require.

This surfaces when every comment in the connection shares the same comment_parent, which is the common case of top-level comments where comment_parent is 0. Ordering by COMMENT_PARENT then adds no comparison field (0 is treated as empty), so the cursor falls back to comparing by comment_date. The malformed fallback field failed validation and threw an InvariantViolation on any page past the first.

Fix

One-line change: use the expected 'value' key so the comment_date fallback comparison is applied correctly.

Test

Adds a regression test in CommentConnectionQueriesTest that paginates a comment connection ordered by COMMENT_PARENT past the first page using the cursor, and asserts no error is returned and that the second page does not repeat first-page nodes. The test fails before the fix (the after query returns an errors array) and passes after.

@vercel

vercel Bot commented Jun 19, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

1 Skipped Deployment
Project Deployment Actions Updated (UTC)
wpgraphql-com Skipped Skipped Jun 19, 2026 2:31am

@codecov

codecov Bot commented Jun 19, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 83.6%. Comparing base (5f0d74b) to head (0f0f569).
⚠️ Report is 1 commits behind head on main.

Additional details and impacted files

Impacted file tree graph

@@           Coverage Diff           @@
##              main   #3964   +/-   ##
=======================================
  Coverage     83.6%   83.6%           
  Complexity    5330    5330           
=======================================
  Files          286     286           
  Lines        22866   22866           
=======================================
+ Hits         19106   19111    +5     
+ Misses        3760    3755    -5     
Flag Coverage Δ
wp-graphql-acf-wpunit-twentytwentyfive-single 77.5% <ø> (ø)
wp-graphql-wpunit-twentytwentyfive-single 84.6% <100.0%> (+<0.1%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Files with missing lines Coverage Δ
...wp-graphql/src/Data/Cursor/CommentObjectCursor.php 80.0% <100.0%> (+10.0%) ⬆️
🚀 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.

The CommentObjectCursor fallback compare field used the array key 'by'
instead of 'value'. When all comments share a comment_parent (top-level
comments, where comment_parent is 0), the orderby comparison adds no
field and the cursor falls back to comparing by comment_date. The
malformed fallback field failed the cursor compare validator, throwing
an InvariantViolation on any page past the first.

Use the expected 'value' key so the comment_date fallback comparison is
applied correctly.

Adds a regression test that paginates a comment connection ordered by
COMMENT_PARENT past the first page and asserts no error is returned.

Closes #3068
@jasonbahl jasonbahl force-pushed the fix/3068-comment-cursor-orderby-parent branch from 46e5772 to 64bf5a1 Compare June 19, 2026 02:31
@jasonbahl jasonbahl merged commit 902d872 into main Jun 24, 2026
62 checks passed
@jasonbahl jasonbahl deleted the fix/3068-comment-cursor-orderby-parent branch June 24, 2026 20:19
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.

Comment pagination fails due to wrong $field key in AbstractCursor

1 participant