Skip to content

feat: add skipToken support for conditional query execution#13

Open
antomorel wants to merge 1 commit into
mainfrom
feat/add-skip-token
Open

feat: add skipToken support for conditional query execution#13
antomorel wants to merge 1 commit into
mainfrom
feat/add-skip-token

Conversation

@antomorel
Copy link
Copy Markdown
Collaborator

Summary

  • Re-export skipToken from @tanstack/react-query for convenience
  • All hooks (useEffectQuery, useInfiniteEffectQuery, useEffectQueries) now accept skipToken as queryFn
  • toQueryOptions and effectQueryOptions support skipToken for use with useQuery directly
  • When using skipToken, the runtime option is not required (typed as never)

This enables the idiomatic TanStack Query pattern for conditional queries:

const { data } = useEffectQuery({
  queryKey: ["user", userId],
  queryFn: userId ? () => Effect.succeed({ id: userId }) : skipToken,
});

Changes

  • Updated type definitions to support discriminated unions for SkipToken vs Effect queryFn
  • Added skipToken handling in all hook implementations
  • Comprehensive test coverage for all skipToken scenarios

Copilot AI review requested due to automatic review settings May 24, 2026 13:12
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR adds first-class skipToken support to the Effect-based React Query hooks/utilities so callers can idiomatically skip conditional queries using TanStack Query’s skipToken, while also re-exporting skipToken from this package.

Changes:

  • Re-export skipToken from @tanstack/react-query via the library entrypoint.
  • Extend hook/option types and hook implementations to accept skipToken as a queryFn.
  • Add tests covering skip/conditional-skip behavior and type-level constraints.

Reviewed changes

Copilot reviewed 11 out of 11 changed files in this pull request and generated 13 comments.

Show a summary per file
File Description
src/index.ts Re-exports skipToken from TanStack Query.
src/types.ts Updates public option/result types to allow skipToken as a queryFn.
src/useEffectQuery.ts Adds runtime handling for skipToken when calling useQuery.
src/useInfiniteEffectQuery.ts Adds runtime handling for skipToken when calling useInfiniteQuery (including getNextPageParam handling).
src/useEffectQueries.ts Adds per-query skipToken handling when mapping to useQueries inputs.
src/toQueryOptions.ts Adds skipToken support when converting Effect query options to React Query options.
test/useEffectQuery.test.ts Adds skipToken behavior + type-level tests for useEffectQuery.
test/useInfiniteEffectQuery.test.ts Adds skipToken behavior + type-level tests for useInfiniteEffectQuery.
test/useEffectQueries.test.ts Adds skipToken behavior + type-level tests for useEffectQueries.
test/effectQueryOptions.test.ts Adds skipToken tests for effectQueryOptions.
.changeset/add-skip-token.md Declares a minor release and documents the new skipToken feature.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/types.ts
Comment thread src/types.ts
Comment thread src/types.ts
Comment thread src/useEffectQuery.ts Outdated
Comment thread src/useInfiniteEffectQuery.ts Outdated
Comment thread test/useInfiniteEffectQuery.test.ts
Comment thread src/types.ts Outdated
Comment thread src/types.ts Outdated
Comment thread src/types.ts
Comment thread src/types.ts
@antomorel antomorel self-assigned this May 24, 2026
@antomorel antomorel requested a review from fondation451 May 24, 2026 13:18
@antomorel antomorel force-pushed the feat/add-skip-token branch from f5ed401 to cb46299 Compare May 24, 2026 13:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 11 out of 11 changed files in this pull request and generated 3 comments.

Comment thread src/useEffectQueries.ts
Comment on lines 12 to 19
type EffectQueryOptionsBase = {
queryKey: QueryKey;
queryFn: (...args: any[]) => Effect.Effect<any, any, any>;
runtime?: Runtime.Runtime<any> | ManagedRuntime.ManagedRuntime<any, any> | undefined;
queryFn: ((...args: any[]) => Effect.Effect<any, any, any>) | SkipToken;
runtime?:
| Runtime.Runtime<any>
| ManagedRuntime.ManagedRuntime<any, any>
| undefined;
};
Comment thread src/useEffectQueries.ts
Comment on lines 95 to 98
const result = useQueries({
queries: transformedQueries,
queries: transformedQueries as any,
combine: options.combine as (result: Array<any>) => TCombinedResult,
});
Comment thread src/toQueryOptions.ts
Comment on lines +65 to +70
if (queryFn === skipToken) {
return {
...restOptions,
queryFn: skipToken,
};
}
Copy link
Copy Markdown

@fondation451 fondation451 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice :)

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.

3 participants