Skip to content

fix: implement cursor pagination with JSON body (body_json)#1693

Open
sergibeltran wants to merge 1 commit into
grafana:mainfrom
sergibeltran:fix/cursor-pagination-body-json
Open

fix: implement cursor pagination with JSON body (body_json)#1693
sergibeltran wants to merge 1 commit into
grafana:mainfrom
sergibeltran:fix/cursor-pagination-body-json

Conversation

@sergibeltran

Copy link
Copy Markdown

Problem

When paginating a POST API with cursor pagination where the nextPageToken cursor must be sent inside the JSON request body, Infinity always returned the first page. The body_json pagination param type was declared in the models but never implemented — the cursor was appended as a query parameter instead of being injected into the body, so every request was identical.

Changes

  • Implement the body_json pagination param type in ApplyPaginationItemToQuery: the cursor key/value is merged into the request JSON body (guarded so a non-JSON body is left untouched rather than overwritten).
  • Expose the "Body JSON" option in the pagination param type dropdown in the query editor (it was commented out).
  • Handle the final page gracefully: many cursor APIs omit the cursor field on the last page, which previously caused error while extracting the cursor value and failed the whole query. This is now treated as "no more pages".

Testing

  • Added unit tests for body_json injection (empty body, existing body, overwrite existing key, non-JSON body left untouched).
  • go test ./..., go vet, yarn typecheck, yarn lint, yarn test:ci and yarn spellcheck all pass.
  • Verified end-to-end against a real POST API (Jira /rest/api/3/search/jql) paginating 3500+ records via nextPageToken in the JSON body.

Cursor pagination for POST APIs that require the next page token inside
the JSON body always returned the first page because the body_json
pagination param type was declared but never implemented. This implements
it (the cursor value is injected into the request JSON body), exposes the
option in the query editor, and stops cursor pagination from erroring when
the final page omits the cursor field.

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@sergibeltran sergibeltran requested a review from a team as a code owner June 2, 2026 16:11
@cla-assistant

cla-assistant Bot commented Jun 2, 2026

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@cla-assistant

cla-assistant Bot commented Jun 2, 2026

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

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.

1 participant