Skip to content

refactor(base-data-service)!: require getNextPageParam and initialPageParam (align with TanStack) - #9872

Closed
cryptodev-2s wants to merge 3 commits into
fix/query-core-v5-base-data-servicefrom
refactor/base-data-service-strict-infinite-query
Closed

refactor(base-data-service)!: require getNextPageParam and initialPageParam (align with TanStack)#9872
cryptodev-2s wants to merge 3 commits into
fix/query-core-v5-base-data-servicefrom
refactor/base-data-service-strict-infinite-query

Conversation

@cryptodev-2s

Copy link
Copy Markdown
Contributor

Proposal (stacked on #9712)

Opening this for the team to decide. It makes BaseDataService.fetchInfiniteQuery align with @tanstack/query-core's own fetchInfiniteQuery by requiring getNextPageParam and initialPageParam (leaving getPreviousPageParam optional, for backward pagination).

Why

On #9712 we ended up with two example methods (getActivity with page-param callbacks, getActivityByCursor without) because the base method allows omitting the callbacks. That optionality is also what forced a no-op getNextPageParam fallback and some extra handling. Requiring the callbacks removes the callback-free path, so:

  • one getActivity example instead of two
  • the base method drops the no-op getNextPageParam fallback and the initialPageParam cast
  • it matches TanStack, which requires these for infinite queries

What changes

  • BaseDataService.fetchInfiniteQuery options: getNextPageParam and initialPageParam are now required.
  • ExampleDataService: collapsed to a single getActivity (callbacks, null first-page param, configurable staleTime).
  • MoneyAccountApiDataService.fetchHistory: now provides getNextPageParam (from next_cursor) and initialPageParam: null.

Cost to surface for the discussion

This is a breaking change to the base contract, and it pushes work onto consumers:

  1. Every infinite-query data service must now provide getNextPageParam + initialPageParam.
  2. getNextPageParam is only exercised on a multi-page stale refetch, so consumers also need a refetch test to keep 100% coverage. MoneyAccount needed a new "refetches all cached pages when stale" test here for exactly that reason.

If we're fine with that trade, this is the cleaner end state. If not, #9712 stands on its own with the two-method approach.

Verification

  • base-data-service: tests + coverage green
  • money-account: tests + coverage green (incl. the new refetch test)
  • builds clean

Changelog to follow once we agree on direction.

…eParam

Align `fetchInfiniteQuery` with `@tanstack/query-core`'s own contract: make
`getNextPageParam` and `initialPageParam` required (`getPreviousPageParam` stays
optional). This drops the no-op `getNextPageParam` fallback and the
`initialPageParam` cast from the base method, and removes the callback-free
usage entirely.

* Collapse `ExampleDataService.getActivity` and `getActivityByCursor` into a
  single `getActivity` (with callbacks, a `null` first-page param, a
  configurable `staleTime`).
* Update `MoneyAccountApiDataService.fetchHistory` to provide
  `getNextPageParam` (from `next_cursor`) and `initialPageParam: null`, with a
  test that refetches a stale multi-page query so the resolver is exercised.
@cryptodev-2s
cryptodev-2s force-pushed the refactor/base-data-service-strict-infinite-query branch from b5aa462 to bc5dd11 Compare August 14, 2026 00:02
@cryptodev-2s
cryptodev-2s deleted the refactor/base-data-service-strict-infinite-query branch August 14, 2026 18:24
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