Skip to content

feat(vue): add mode: "optional" overload for queries with Option input#748

Merged
patroza merged 3 commits into
mainfrom
copilot/add-overload-for-query
May 11, 2026
Merged

feat(vue): add mode: "optional" overload for queries with Option input#748
patroza merged 3 commits into
mainfrom
copilot/add-overload-for-query

Conversation

Copy link
Copy Markdown
Contributor

Copilot AI commented May 11, 2026

Queries had no ergonomic way to conditionally enable/disable based on an optional input value — callers had to manually thread enabled and unwrap the value themselves.

Changes

  • New mode: "optional" overload on useQuery_ and useQueryarg must be a WatchSource<Option<I>> (thunk, ref, or computed); enabled is excluded from options
  • Available on API client helpers — the overload is exposed on the outer useQuery type, so it works directly via client.X.query(...) helpers
  • Auto-computed enabled — derives computed(() => Option.isSome(...)) and passes it to tanstack; query is disabled when None, enabled when Some
  • Auto-unwrapped inputOption.getOrUndefined used as the query input value; safe because tanstack only calls queryFn when enabled is true

Example

const selectedId = computed(() =>
  someRef.value ? Option.some(someRef.value) : Option.none()
)

const [result, data] = client.getItemQuery(selectedId, { mode: "optional" })
// query is disabled when selectedId is None, runs with unwrapped value when Some

@patroza
Copy link
Copy Markdown
Member

patroza commented May 11, 2026

@copilot Make available for the query helpers on api clients

Copy link
Copy Markdown
Contributor Author

Copilot AI commented May 11, 2026

@copilot Make available for the query helpers on api clients

Done in ec01f61 — added the mode: "optional" overload to the outer useQuery type signature (which backs client.X.query). Now you can do:

const selectedId = computed(() => someRef.value ? Option.some(someRef.value) : Option.none())
const [result, data] = client.getItemQuery(selectedId, { mode: "optional" })

Copilot AI requested a review from patroza May 11, 2026 15:36
@patroza patroza merged commit 1e4c989 into main May 11, 2026
3 checks passed
@patroza patroza deleted the copilot/add-overload-for-query branch May 11, 2026 15:46
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.

2 participants