-
-
Notifications
You must be signed in to change notification settings - Fork 3.5k
ref: rename queryFn to streamFn in streamedQuery #9606
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
Conversation
this avoids the weirdly double-nested queryFn naming
WalkthroughRenames the public streaming option from Changes
Sequence Diagram(s)(Skipped — changes are a public option rename only; control flow is unchanged.) Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes Possibly related PRs
Poem
✨ Finishing Touches
🧪 Generate unit tests
🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
SupportNeed help? Create a ticket on our support page for assistance with any issues or questions. CodeRabbit Commands (Invoked using PR/Issue comments)Type Other keywords and placeholders
CodeRabbit Configuration File (
|
View your CI Pipeline Execution ↗ for commit dd12c6c
☁️ Nx Cloud last updated this comment at |
Sizes for commit dd12c6c:
|
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
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
packages/query-core/src/streamedQuery.ts (1)
9-9
: Fix JSDoc: @param name still says queryFn.Update the param tag to match the new API.
- * @param queryFn - The function that returns an AsyncIterable to stream data from. + * @param streamFn - The function that returns an AsyncIterable to stream data from.
🧹 Nitpick comments (1)
packages/query-core/src/__tests__/streamedQuery.test.tsx (1)
519-519
: Add a small coverage boost: streamFn returning a Promise.Your types allow Promise; add a test to lock this in.
+++ a/packages/query-core/src/__tests__/streamedQuery.test.tsx @@ describe('streamedQuery', () => { + test('should accept streamFn that returns a Promise<AsyncIterable>', async () => { + const key = queryKey() + const observer = new QueryObserver(queryClient, { + queryKey: key, + queryFn: streamedQuery({ + streamFn: async () => Promise.resolve(createAsyncNumberGenerator(2)), + }), + }) + const unsubscribe = observer.subscribe(vi.fn()) + await vi.advanceTimersByTimeAsync(100) + expect(observer.getCurrentResult()).toMatchObject({ + status: 'success', + fetchStatus: 'idle', + data: [0, 1], + }) + unsubscribe() + }) })
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
packages/query-core/src/__tests__/streamedQuery.test.tsx
(9 hunks)packages/query-core/src/streamedQuery.ts
(2 hunks)
⏰ 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). (2)
- GitHub Check: Preview
- GitHub Check: Test
🔇 Additional comments (2)
packages/query-core/src/streamedQuery.ts (1)
23-23
: API rename verified — no remainingqueryFn
usage; callers must switch tostreamFn
. Breaking change—update release notes/changelog accordingly.packages/query-core/src/__tests__/streamedQuery.test.tsx (1)
37-37
: Tests updated to use streamFn: consistent and correct.All call sites now pass streamFn to streamedQuery while keeping QueryObserver’s queryFn as-is. Semantics preserved.
Also applies to: 81-81, 136-136, 190-192, 246-248, 303-305, 358-364, 399-401, 444-447
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #9606 +/- ##
===========================================
+ Coverage 45.26% 59.37% +14.10%
===========================================
Files 208 137 -71
Lines 8340 5580 -2760
Branches 1894 1510 -384
===========================================
- Hits 3775 3313 -462
+ Misses 4118 1963 -2155
+ Partials 447 304 -143 🚀 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: 1
🧹 Nitpick comments (2)
examples/react/chat/src/chat.ts (1)
11-24
: Optional: honor AbortSignal to avoid running timers after abort/unmount.
Hook into the QueryFunctionContext’s signal so the generator exits early and avoids dangling timeouts.Apply within the current diff hunk:
- streamFn: () => chatAnswer(question), + streamFn: (ctx) => chatAnswer(question, ctx.signal),Then adjust the helper (outside this hunk):
function chatAnswer(_question: string, signal?: AbortSignal) { return { async *[Symbol.asyncIterator]() { const answer = answers[Math.floor(Math.random() * answers.length)] let index = 0 while (index < answer.length) { // bail out early on abort if (signal?.aborted) return await new Promise((resolve) => setTimeout(resolve, 100 + Math.random() * 300)) if (signal?.aborted) return yield answer[index++] } }, } }docs/reference/streamedQuery.md (1)
25-27
: Tighten wording for streamFn description.
Minor grammar/style tweak.-- `streamFn: (context: QueryFunctionContext) => Promise<AsyncIterable<TData>>` - **Required** - - The function that returns a Promise of an AsyncIterable with data to stream in. + - A function that returns a Promise that resolves to an AsyncIterable of chunks to stream.
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (2)
docs/reference/streamedQuery.md
(2 hunks)examples/react/chat/src/chat.ts
(1 hunks)
🧰 Additional context used
🪛 LanguageTool
docs/reference/streamedQuery.md
[grammar] ~27-~27: There might be a mistake here.
Context: ...an AsyncIterable with data to stream in. - Receives a [QueryFunctionContext](../../...
(QB_NEW_EN)
⏰ 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). (2)
- GitHub Check: Preview
- GitHub Check: Test
🔇 Additional comments (2)
examples/react/chat/src/chat.ts (1)
29-31
: Rename wired correctly — streamFn is passed to streamedQuery as intended.docs/reference/streamedQuery.md (1)
15-17
: Example updated correctly to streamFn.
Matches the new API surface.
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: 1
♻️ Duplicate comments (1)
docs/reference/streamedQuery.md (1)
29-29
: Resolved: closing quote added to refetchMode union.The unterminated string literal is fixed.
🧹 Nitpick comments (2)
docs/reference/streamedQuery.md (2)
27-27
: Tighten wording for clarity (LT flagged).Current phrasing is a bit clunky; suggest:
- - The function that returns a Promise of an AsyncIterable with data to stream in. + - Returns a Promise that resolves to an AsyncIterable of chunks to stream.
41-45
: Clarify initialValue line to avoid implying invalid TS syntax and conflicting defaults.As written,
initialValue?: TData = TQueryFnData
reads like a type default and also conflicts with “Defaults to an empty array.” Recommend splitting semantics and stating the default plainly.- - `initialValue?: TData = TQueryFnData` + - `initialValue?: TData` - Optional - - Defines the initial data to be used while the first chunk is being fetched. + - Defines the initial data to use while the first chunk is being fetched. - It is mandatory when custom `reducer` is provided. - - Defaults to an empty array. + - Default: an empty array (unless specified).
📜 Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro
💡 Knowledge Base configuration:
- MCP integration is disabled by default for public repositories
- Jira integration is disabled by default for public repositories
- Linear integration is disabled by default for public repositories
You can enable these sources in your CodeRabbit configuration.
📒 Files selected for processing (3)
docs/reference/streamedQuery.md
(2 hunks)packages/query-core/src/__tests__/streamedQuery.test.tsx
(9 hunks)packages/query-core/src/streamedQuery.ts
(3 hunks)
🚧 Files skipped from review as they are similar to previous changes (2)
- packages/query-core/src/streamedQuery.ts
- packages/query-core/src/tests/streamedQuery.test.tsx
🧰 Additional context used
🪛 LanguageTool
docs/reference/streamedQuery.md
[grammar] ~27-~27: There might be a mistake here.
Context: ...an AsyncIterable with data to stream in. - Receives a [QueryFunctionContext](../../...
(QB_NEW_EN)
⏰ 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). (1)
- GitHub Check: Test
🔇 Additional comments (1)
docs/reference/streamedQuery.md (1)
16-16
: Example updated to streamFn — looks correct.The rename in the usage snippet is consistent and accurate.
**Options** | ||
|
||
- `queryFn: (context: QueryFunctionContext) => Promise<AsyncIterable<TData>>` | ||
- `streamFn: (context: QueryFunctionContext) => Promise<AsyncIterable<TData>>` |
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.
Type parameter mismatch: streamFn should yield TQueryFnData, not TData.
This conflicts with the reducer signature using TQueryFnData
for chunks.
Apply this diff:
- - `streamFn: (context: QueryFunctionContext) => Promise<AsyncIterable<TData>>`
+ - `streamFn: (context: QueryFunctionContext) => Promise<AsyncIterable<TQueryFnData>>`
📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
- `streamFn: (context: QueryFunctionContext) => Promise<AsyncIterable<TData>>` | |
- `streamFn: (context: QueryFunctionContext) => Promise<AsyncIterable<TQueryFnData>>` |
🤖 Prompt for AI Agents
In docs/reference/streamedQuery.md around line 25, the documented type for
streamFn uses TData but it should yield TQueryFnData to match the reducer
signature; update the signature from `streamFn: (context: QueryFunctionContext)
=> Promise<AsyncIterable<TData>>` to `streamFn: (context: QueryFunctionContext)
=> Promise<AsyncIterable<TQueryFnData>>` (or the equivalent doc representation)
so the type parameter for streamed chunks aligns with the reducer's
TQueryFnData.
this avoids the weirdly double-nested queryFn naming
Summary by CodeRabbit
Refactor
Documentation
Tests
Examples