Skip to content

feat(tanstack-query): define base options and interceptors via contract meta#1705

Open
dinwwwh wants to merge 12 commits into
middleapi:mainfrom
dinwwwh:claude/tanstack-query-meta-plugin-edfe5e
Open

feat(tanstack-query): define base options and interceptors via contract meta#1705
dinwwwh wants to merge 12 commits into
middleapi:mainfrom
dinwwwh:claude/tanstack-query-meta-plugin-edfe5e

Conversation

@dinwwwh

@dinwwwh dinwwwh commented Jul 21, 2026

Copy link
Copy Markdown
Member

Summary

Define base TanStack Query options and interceptors directly on a procedure contract via tanstackQuery, and apply them automatically with the new ContractOptionsUtilsPlugin.

export const contract = {
  planet: {
    find: oc
      .input(z.object({ id: z.number() }))
      .meta(tanstackQuery({
        queryOptions: {
          staleTime: 60 * 1000,
        },
      })),
  },
}

const orpc = createTanstackQueryUtils(client, {
  plugins: [new ContractOptionsUtilsPlugin(contract)],
})
  • tanstackQuery infers input, output, and error types from the contract, supports all procedure utils options (keys, options, interceptors), and merges when applied multiple times
  • ContractOptionsUtilsPlugin applies meta options as the base layer: utils level options override them and utils interceptors run after meta interceptors
  • Merging is consistent across all layers: interceptors concatenate, plain option objects spread-merge, and function modifiers compose
  • getTanstackQueryMeta reads the stored options for custom integrations
  • Docs cover the plugin, the reference-only nature of contract types, and passing runtime values such as router utils through mutation meta

@vercel

vercel Bot commented Jul 21, 2026

Copy link
Copy Markdown

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
orpc Ready Ready Preview, Comment Jul 23, 2026 2:56pm

@pkg-pr-new

pkg-pr-new Bot commented Jul 21, 2026

Copy link
Copy Markdown
More templates

@orpc/ai-sdk

npm i https://pkg.pr.new/middleapi/orpc/@orpc/ai-sdk@1705

@orpc/arktype

npm i https://pkg.pr.new/middleapi/orpc/@orpc/arktype@1705

@orpc/bun

npm i https://pkg.pr.new/middleapi/orpc/@orpc/bun@1705

@orpc/client

npm i https://pkg.pr.new/middleapi/orpc/@orpc/client@1705

@orpc/cloudflare

npm i https://pkg.pr.new/middleapi/orpc/@orpc/cloudflare@1705

@orpc/contract

npm i https://pkg.pr.new/middleapi/orpc/@orpc/contract@1705

@orpc/experimental-effect

npm i https://pkg.pr.new/middleapi/orpc/@orpc/experimental-effect@1705

@orpc/evlog

npm i https://pkg.pr.new/middleapi/orpc/@orpc/evlog@1705

@orpc/json-schema

npm i https://pkg.pr.new/middleapi/orpc/@orpc/json-schema@1705

@orpc/nest

npm i https://pkg.pr.new/middleapi/orpc/@orpc/nest@1705

@orpc/next

npm i https://pkg.pr.new/middleapi/orpc/@orpc/next@1705

@orpc/openapi

npm i https://pkg.pr.new/middleapi/orpc/@orpc/openapi@1705

@orpc/opentelemetry

npm i https://pkg.pr.new/middleapi/orpc/@orpc/opentelemetry@1705

@orpc/pinia-colada

npm i https://pkg.pr.new/middleapi/orpc/@orpc/pinia-colada@1705

@orpc/pino

npm i https://pkg.pr.new/middleapi/orpc/@orpc/pino@1705

@orpc/publisher

npm i https://pkg.pr.new/middleapi/orpc/@orpc/publisher@1705

@orpc/ratelimit

npm i https://pkg.pr.new/middleapi/orpc/@orpc/ratelimit@1705

@orpc/server

npm i https://pkg.pr.new/middleapi/orpc/@orpc/server@1705

@orpc/shared

npm i https://pkg.pr.new/middleapi/orpc/@orpc/shared@1705

@orpc/tanstack-query

npm i https://pkg.pr.new/middleapi/orpc/@orpc/tanstack-query@1705

@orpc/trpc

npm i https://pkg.pr.new/middleapi/orpc/@orpc/trpc@1705

@orpc/valibot

npm i https://pkg.pr.new/middleapi/orpc/@orpc/valibot@1705

@orpc/zod

npm i https://pkg.pr.new/middleapi/orpc/@orpc/zod@1705

commit: 4f0bbc8

@codecov

codecov Bot commented Jul 21, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 96.66667% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
packages/tanstack-query/src/procedure-utils.ts 90.00% 1 Missing ⚠️

📢 Thoughts on this report? Let us know!

@codspeed-hq

codspeed-hq Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

✅ 18 untouched benchmarks


Comparing dinwwwh:claude/tanstack-query-meta-plugin-edfe5e (4f0bbc8) with main (fb2b8d2)

Open in CodSpeed

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ No critical issues — one minor API-surface note inline.

Reviewed changes — added tanstackQueryMeta, getTanstackQueryMeta, and ContractMetaPlugin so base TanStack Query options and interceptors can be defined on a procedure contract and applied automatically as the default layer under utils options.

  • packages/tanstack-query/src/meta.ts — introduces the tanstackQueryMeta contract meta plugin, getTanstackQueryMeta reader, and ContractMetaPlugin router utils plugin.
  • packages/tanstack-query/src/procedure-utils.ts — adds mergeProcedureUtilsOptions/mergeProcedureUtilsModifier so option modifiers spread-merge and interceptors concatenate across layers.
  • packages/tanstack-query/src/router-utils.ts — switches global/scoped per-procedure option merging to mergeProcedureUtilsOptions to keep semantics consistent.
  • packages/tanstack-query/src/index.ts — exports the new ./meta module and now also exports ./plugin.
  • Tests and docs — adds meta.test.ts/meta.test-d.ts, updates the router-utils.test.ts mock, and documents the contract meta plugin.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

Comment thread packages/tanstack-query/src/index.ts
@pullfrog

pullfrog Bot commented Jul 21, 2026

Copy link
Copy Markdown
Contributor

Heads-up: the inline suggestion in my review on packages/tanstack-query/src/index.ts was malformed — the suggested replacement included extra lines by mistake. Please ignore that suggestion entirely.

The actual feedback is just a nit: export * from './plugin' now also makes CompositeRouterUtilsPlugin public. If that class is meant to stay internal, consider scoping the export to RouterUtilsPlugin only or marking CompositeRouterUtilsPlugin as @internal. Everything else looks good to merge.

Pullfrog  | View workflow run | via Pullfrog | Using Kimi K2 (free via Pullfrog for OSS) | 𝕏

@dinwwwh
dinwwwh marked this pull request as draft July 21, 2026 12:07
…ery-meta-plugin-edfe5e

# Conflicts:
#	packages/tanstack-query/src/procedure-utils.ts
#	packages/tanstack-query/src/router-utils.test.ts
#	packages/tanstack-query/src/router-utils.ts
@dinwwwh dinwwwh changed the title feat(tanstack-query): contract meta for base query/mutation options feat(tanstack-query): define base options and interceptors via contract meta Jul 23, 2026
@dinwwwh
dinwwwh marked this pull request as ready for review July 23, 2026 14:56

@pullfrog pullfrog Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ One minor suggestion inline.

Reviewed changes — adds tanstackQuery for defining base TanStack Query options/interceptors on procedure contracts, and ContractOptionsUtilsPlugin for applying them automatically via the plugin system. Also refactors router-utils.ts to use a shared mergeProcedureUtilsOptions helper with consistent spread-merge composition semantics.

  • Add tanstackQuery contract meta plugin — stores ProcedureUtilsOptions under ~tanstack-query in procedure meta, supports multi-layer merging with interceptor concatenation and modifier composition.
  • Add ContractOptionsUtilsPlugin — walks the contract by path via getRouterContract and merges stored meta as the base layer under scoped/global utils options.
  • Refactor interceptor merging — extract mergeProcedureUtilsOptions and mergeProcedureUtilsModifier in procedure-utils.ts, use them in both tanstackQuery accumulation and router-utils.ts scoped-options merge.
  • Export RouterUtilsPlugin interface./plugin module is now part of the public API, enabling custom plugin implementations.
  • Tests and type tests — unit tests for storage, merging, function composition, router propagation, and end-to-end createRouterUtils flow. Type tests verify contract type inference.

Pullfrog  | Fix all ➔Fix 👍s ➔View workflow run | Using DeepSeek Pro (free via Pullfrog for OSS) | 𝕏

export * from './contract-utils'
export * from './key'
export * from './meta'
export * from './plugin'

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

ℹ️ export * from './plugin' now makes CompositeRouterUtilsPlugin part of the public API. It's an internal composition primitive that users shouldn't need to construct directly — they pass plain plugin arrays to createTanstackQueryUtils. Consider exporting only RouterUtilsPlugin explicitly or marking CompositeRouterUtilsPlugin with @internal in its JSDoc.

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