@trpc/react-query 10.0.0-rc.6 → 10.0.0-rc.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/ssg/index.js CHANGED
@@ -4,7 +4,7 @@ Object.defineProperty(exports, '__esModule', { value: true });
4
4
 
5
5
  var reactQuery = require('@tanstack/react-query');
6
6
  var server = require('@trpc/server');
7
- var getArrayQueryKey = require('../getArrayQueryKey-5ab807a3.js');
7
+ var getArrayQueryKey = require('../getArrayQueryKey-24927615.js');
8
8
  var shared = require('@trpc/server/shared');
9
9
  require('@trpc/client');
10
10
  require('react');
@@ -18,7 +18,7 @@ var queryClient = require('../queryClient-358a9a75.js');
18
18
  const queryClient$1 = queryClient.getQueryClient(opts);
19
19
  const serialize = transformer ? ('input' in transformer ? transformer.input : transformer).serialize : (obj)=>obj;
20
20
  const prefetchQuery = async (...pathAndInput)=>{
21
- return queryClient$1.prefetchQuery(getArrayQueryKey.getArrayQueryKey(pathAndInput), ()=>{
21
+ return queryClient$1.prefetchQuery(getArrayQueryKey.getArrayQueryKey(pathAndInput, 'query'), ()=>{
22
22
  return server.callProcedure({
23
23
  procedures: router._def.procedures,
24
24
  path: pathAndInput[0],
@@ -29,7 +29,7 @@ var queryClient = require('../queryClient-358a9a75.js');
29
29
  });
30
30
  };
31
31
  const prefetchInfiniteQuery = async (...pathAndInput)=>{
32
- return queryClient$1.prefetchInfiniteQuery(getArrayQueryKey.getArrayQueryKey(pathAndInput), ()=>{
32
+ return queryClient$1.prefetchInfiniteQuery(getArrayQueryKey.getArrayQueryKey(pathAndInput, 'infinite'), ()=>{
33
33
  return server.callProcedure({
34
34
  procedures: router._def.procedures,
35
35
  path: pathAndInput[0],
@@ -40,7 +40,7 @@ var queryClient = require('../queryClient-358a9a75.js');
40
40
  });
41
41
  };
42
42
  const fetchQuery = async (...pathAndInput)=>{
43
- return queryClient$1.fetchQuery(getArrayQueryKey.getArrayQueryKey(pathAndInput), ()=>{
43
+ return queryClient$1.fetchQuery(getArrayQueryKey.getArrayQueryKey(pathAndInput, 'query'), ()=>{
44
44
  return server.callProcedure({
45
45
  procedures: router._def.procedures,
46
46
  path: pathAndInput[0],
@@ -51,7 +51,7 @@ var queryClient = require('../queryClient-358a9a75.js');
51
51
  });
52
52
  };
53
53
  const fetchInfiniteQuery = async (...pathAndInput)=>{
54
- return queryClient$1.fetchInfiniteQuery(getArrayQueryKey.getArrayQueryKey(pathAndInput), ()=>{
54
+ return queryClient$1.fetchInfiniteQuery(getArrayQueryKey.getArrayQueryKey(pathAndInput, 'infinite'), ()=>{
55
55
  return server.callProcedure({
56
56
  procedures: router._def.procedures,
57
57
  path: pathAndInput[0],
@@ -1,6 +1,6 @@
1
1
  import { dehydrate } from '@tanstack/react-query';
2
2
  import { callProcedure } from '@trpc/server';
3
- import { g as getArrayQueryKey } from '../getArrayQueryKey-e56d8d64.mjs';
3
+ import { g as getArrayQueryKey } from '../getArrayQueryKey-c6f6badf.mjs';
4
4
  import { createFlatProxy, createRecursiveProxy } from '@trpc/server/shared';
5
5
  import '@trpc/client';
6
6
  import 'react';
@@ -14,7 +14,7 @@ import { g as getQueryClient } from '../queryClient-4d766c0c.mjs';
14
14
  const queryClient = getQueryClient(opts);
15
15
  const serialize = transformer ? ('input' in transformer ? transformer.input : transformer).serialize : (obj)=>obj;
16
16
  const prefetchQuery = async (...pathAndInput)=>{
17
- return queryClient.prefetchQuery(getArrayQueryKey(pathAndInput), ()=>{
17
+ return queryClient.prefetchQuery(getArrayQueryKey(pathAndInput, 'query'), ()=>{
18
18
  return callProcedure({
19
19
  procedures: router._def.procedures,
20
20
  path: pathAndInput[0],
@@ -25,7 +25,7 @@ import { g as getQueryClient } from '../queryClient-4d766c0c.mjs';
25
25
  });
26
26
  };
27
27
  const prefetchInfiniteQuery = async (...pathAndInput)=>{
28
- return queryClient.prefetchInfiniteQuery(getArrayQueryKey(pathAndInput), ()=>{
28
+ return queryClient.prefetchInfiniteQuery(getArrayQueryKey(pathAndInput, 'infinite'), ()=>{
29
29
  return callProcedure({
30
30
  procedures: router._def.procedures,
31
31
  path: pathAndInput[0],
@@ -36,7 +36,7 @@ import { g as getQueryClient } from '../queryClient-4d766c0c.mjs';
36
36
  });
37
37
  };
38
38
  const fetchQuery = async (...pathAndInput)=>{
39
- return queryClient.fetchQuery(getArrayQueryKey(pathAndInput), ()=>{
39
+ return queryClient.fetchQuery(getArrayQueryKey(pathAndInput, 'query'), ()=>{
40
40
  return callProcedure({
41
41
  procedures: router._def.procedures,
42
42
  path: pathAndInput[0],
@@ -47,7 +47,7 @@ import { g as getQueryClient } from '../queryClient-4d766c0c.mjs';
47
47
  });
48
48
  };
49
49
  const fetchInfiniteQuery = async (...pathAndInput)=>{
50
- return queryClient.fetchInfiniteQuery(getArrayQueryKey(pathAndInput), ()=>{
50
+ return queryClient.fetchInfiniteQuery(getArrayQueryKey(pathAndInput, 'infinite'), ()=>{
51
51
  return callProcedure({
52
52
  procedures: router._def.procedures,
53
53
  path: pathAndInput[0],
@@ -1 +1 @@
1
- {"version":3,"file":"ssg.d.ts","sourceRoot":"","sources":["../../src/ssg/ssg.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,YAAY,EAEb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,SAAS,EACT,4BAA4B,EAG5B,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,gCAAgC,EAAkB,MAAM,WAAW,CAAC;AAE7E,UAAU,2BAA2B,CAAC,OAAO,SAAS,SAAS;IAC7D,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACjC,WAAW,CAAC,EAAE,4BAA4B,CAAC;CAC5C;AACD,oBAAY,uBAAuB,CAAC,OAAO,SAAS,SAAS,IAC3D,2BAA2B,CAAC,OAAO,CAAC,GAAG,gCAAgC,CAAC;AAE1E;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC;;;;;uBAuF9B,gBAAgB,KAMrB,eAAe;;EAcnB"}
1
+ {"version":3,"file":"ssg.d.ts","sourceRoot":"","sources":["../../src/ssg/ssg.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,gBAAgB,EAChB,eAAe,EACf,YAAY,EAEb,MAAM,uBAAuB,CAAC;AAC/B,OAAO,EACL,SAAS,EACT,4BAA4B,EAG5B,oBAAoB,EACpB,kBAAkB,EACnB,MAAM,cAAc,CAAC;AAEtB,OAAO,EAAE,gCAAgC,EAAkB,MAAM,WAAW,CAAC;AAE7E,UAAU,2BAA2B,CAAC,OAAO,SAAS,SAAS;IAC7D,MAAM,EAAE,OAAO,CAAC;IAChB,GAAG,EAAE,kBAAkB,CAAC,OAAO,CAAC,CAAC;IACjC,WAAW,CAAC,EAAE,4BAA4B,CAAC;CAC5C;AACD,oBAAY,uBAAuB,CAAC,OAAO,SAAS,SAAS,IAC3D,2BAA2B,CAAC,OAAO,CAAC,GAAG,gCAAgC,CAAC;AAE1E;;;GAGG;AACH,wBAAgB,gBAAgB,CAAC,OAAO,SAAS,SAAS,EACxD,IAAI,EAAE,uBAAuB,CAAC,OAAO,CAAC;;;;;uBA6F9B,gBAAgB,KAMrB,eAAe;;EAcnB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trpc/react-query",
3
- "version": "10.0.0-rc.6",
3
+ "version": "10.0.0-rc.8",
4
4
  "description": "tRPC React lib",
5
5
  "author": "KATT",
6
6
  "license": "MIT",
@@ -54,19 +54,19 @@
54
54
  },
55
55
  "peerDependencies": {
56
56
  "@tanstack/react-query": "^4.3.8",
57
- "@trpc/client": "10.0.0-rc.6",
58
- "@trpc/server": "10.0.0-rc.6",
57
+ "@trpc/client": "10.0.0-rc.8",
58
+ "@trpc/server": "10.0.0-rc.8",
59
59
  "react": ">=16.8.0",
60
60
  "react-dom": ">=16.8.0"
61
61
  },
62
62
  "devDependencies": {
63
63
  "@tanstack/react-query": "^4.3.8",
64
- "@trpc/client": "10.0.0-rc.6",
65
- "@trpc/server": "10.0.0-rc.6",
64
+ "@trpc/client": "10.0.0-rc.8",
65
+ "@trpc/server": "10.0.0-rc.8",
66
66
  "@types/express": "^4.17.12",
67
67
  "@types/node": "^18.7.20",
68
68
  "express": "^4.17.1",
69
- "next": "^12.3.1",
69
+ "next": "^13.0.0",
70
70
  "react": "^18.2.0",
71
71
  "react-dom": "^18.2.0",
72
72
  "rollup": "^2.79.1",
@@ -76,5 +76,5 @@
76
76
  "publishConfig": {
77
77
  "access": "public"
78
78
  },
79
- "gitHead": "9ec752b68e28a45e0278fdc13c5318bc7403eb74"
79
+ "gitHead": "5b8ff0d8d49251aa8c287e9d68641810cd9964e2"
80
80
  }
@@ -1,3 +1,4 @@
1
+ import { InfiniteData } from '@tanstack/react-query';
1
2
  import { TRPCClientErrorLike } from '@trpc/client';
2
3
  import {
3
4
  AnyMutationProcedure,
@@ -24,10 +25,12 @@ import {
24
25
  UseDehydratedState,
25
26
  UseTRPCInfiniteQueryOptions,
26
27
  UseTRPCInfiniteQueryResult,
28
+ UseTRPCInfiniteQuerySuccessResult,
27
29
  UseTRPCMutationOptions,
28
30
  UseTRPCMutationResult,
29
31
  UseTRPCQueryOptions,
30
32
  UseTRPCQueryResult,
33
+ UseTRPCQuerySuccessResult,
31
34
  UseTRPCSubscriptionOptions,
32
35
  createHooksInternal,
33
36
  } from './shared/hooks/createHooksInternal';
@@ -38,6 +41,7 @@ import { CreateTRPCReactOptions } from './shared/types';
38
41
  */
39
42
  export type DecorateProcedure<
40
43
  TProcedure extends AnyProcedure,
44
+ TFlags,
41
45
  TPath extends string,
42
46
  > = TProcedure extends AnyQueryProcedure
43
47
  ? {
@@ -71,8 +75,55 @@ export type DecorateProcedure<
71
75
  TData,
72
76
  TRPCClientErrorLike<TProcedure>
73
77
  >;
74
- }
75
- : {})
78
+ } & (TFlags extends 'ExperimentalSuspense'
79
+ ? {
80
+ useSuspenseInfiniteQuery: <
81
+ _TQueryFnData = inferProcedureOutput<TProcedure>,
82
+ TData = inferProcedureOutput<TProcedure>,
83
+ >(
84
+ input: Omit<inferProcedureInput<TProcedure>, 'cursor'>,
85
+ opts?: Omit<
86
+ UseTRPCInfiniteQueryOptions<
87
+ TPath,
88
+ inferProcedureInput<TProcedure>,
89
+ TData,
90
+ TRPCClientErrorLike<TProcedure>
91
+ >,
92
+ 'enabled' | 'suspense'
93
+ >,
94
+ ) => [
95
+ InfiniteData<TData>,
96
+ UseTRPCInfiniteQuerySuccessResult<
97
+ TData,
98
+ TRPCClientErrorLike<TProcedure>
99
+ >,
100
+ ];
101
+ }
102
+ : {})
103
+ : {}) &
104
+ (TFlags extends 'ExperimentalSuspense'
105
+ ? {
106
+ useSuspenseQuery: <
107
+ TQueryFnData = inferProcedureOutput<TProcedure>,
108
+ TData = inferProcedureOutput<TProcedure>,
109
+ >(
110
+ input: inferProcedureInput<TProcedure>,
111
+ opts?: Omit<
112
+ UseTRPCQueryOptions<
113
+ TPath,
114
+ inferProcedureInput<TProcedure>,
115
+ TQueryFnData,
116
+ TData,
117
+ TRPCClientErrorLike<TProcedure>
118
+ >,
119
+ 'enabled' | 'suspense'
120
+ >,
121
+ ) => [
122
+ TData,
123
+ UseTRPCQuerySuccessResult<TData, TRPCClientErrorLike<TProcedure>>,
124
+ ];
125
+ }
126
+ : {})
76
127
  : TProcedure extends AnyMutationProcedure
77
128
  ? {
78
129
  useMutation: <TContext = unknown>(
@@ -106,24 +157,26 @@ export type DecorateProcedure<
106
157
  */
107
158
  export type DecoratedProcedureRecord<
108
159
  TProcedures extends ProcedureRouterRecord,
160
+ TFlags,
109
161
  TPath extends string = '',
110
162
  > = {
111
163
  [TKey in keyof TProcedures]: TProcedures[TKey] extends AnyRouter
112
164
  ? DecoratedProcedureRecord<
113
165
  TProcedures[TKey]['_def']['record'],
166
+ TFlags,
114
167
  `${TPath}${TKey & string}.`
115
168
  >
116
169
  : TProcedures[TKey] extends AnyProcedure
117
- ? DecorateProcedure<TProcedures[TKey], `${TPath}${TKey & string}`>
170
+ ? DecorateProcedure<TProcedures[TKey], TFlags, `${TPath}${TKey & string}`>
118
171
  : never;
119
172
  };
120
173
 
121
- export type CreateTRPCReact<TRouter extends AnyRouter, TSSRContext> = {
174
+ export type CreateTRPCReact<TRouter extends AnyRouter, TSSRContext, TFlags> = {
122
175
  useContext(): CreateReactUtilsProxy<TRouter, TSSRContext>;
123
176
  Provider: TRPCProvider<TRouter, TSSRContext>;
124
177
  createClient: CreateClient<TRouter>;
125
178
  useDehydratedState: UseDehydratedState<TRouter>;
126
- } & DecoratedProcedureRecord<TRouter['_def']['record']>;
179
+ } & DecoratedProcedureRecord<TRouter['_def']['record'], TFlags>;
127
180
 
128
181
  /**
129
182
  * @internal
@@ -131,8 +184,9 @@ export type CreateTRPCReact<TRouter extends AnyRouter, TSSRContext> = {
131
184
  export function createHooksInternalProxy<
132
185
  TRouter extends AnyRouter,
133
186
  TSSRContext = unknown,
187
+ TFlags = null,
134
188
  >(trpc: CreateReactQueryHooks<TRouter, TSSRContext>) {
135
- type CreateHooksInternalProxy = CreateTRPCReact<TRouter, TSSRContext>;
189
+ type CreateHooksInternalProxy = CreateTRPCReact<TRouter, TSSRContext, TFlags>;
136
190
 
137
191
  return createFlatProxy<CreateHooksInternalProxy>((key) => {
138
192
  if (key === 'useContext') {
@@ -156,9 +210,10 @@ export function createHooksInternalProxy<
156
210
  export function createTRPCReact<
157
211
  TRouter extends AnyRouter,
158
212
  TSSRContext = unknown,
213
+ TFlags = null,
159
214
  >(opts?: CreateTRPCReactOptions<TRouter>) {
160
215
  const hooks = createHooksInternal<TRouter, TSSRContext>(opts);
161
- const proxy = createHooksInternalProxy<TRouter, TSSRContext>(hooks);
216
+ const proxy = createHooksInternalProxy<TRouter, TSSRContext, TFlags>(hooks);
162
217
 
163
218
  return proxy;
164
219
  }
@@ -1,41 +1,76 @@
1
1
  import { getArrayQueryKey } from './getArrayQueryKey';
2
2
 
3
3
  test('getArrayQueryKey', () => {
4
- expect(getArrayQueryKey('foo')).toMatchInlineSnapshot(`
4
+ expect(getArrayQueryKey('foo', 'query')).toMatchInlineSnapshot(`
5
5
  Array [
6
6
  Array [
7
7
  "foo",
8
8
  ],
9
+ Object {
10
+ "type": "query",
11
+ },
9
12
  ]
10
13
  `);
11
- expect(getArrayQueryKey(['foo'])).toMatchInlineSnapshot(`
14
+ expect(getArrayQueryKey(['foo'], 'query')).toMatchInlineSnapshot(`
12
15
  Array [
13
16
  Array [
14
17
  "foo",
15
18
  ],
19
+ Object {
20
+ "type": "query",
21
+ },
16
22
  ]
17
23
  `);
18
- expect(getArrayQueryKey(['foo', 'bar'])).toMatchInlineSnapshot(`
24
+ expect(getArrayQueryKey('foo', 'infinite')).toMatchInlineSnapshot(`
19
25
  Array [
20
26
  Array [
21
27
  "foo",
22
28
  ],
23
- "bar",
29
+ Object {
30
+ "type": "infinite",
31
+ },
24
32
  ]
25
33
  `);
26
- expect(getArrayQueryKey([undefined, 'bar'])).toMatchInlineSnapshot(`
34
+ expect(getArrayQueryKey(['foo'], 'infinite')).toMatchInlineSnapshot(`
35
+ Array [
36
+ Array [
37
+ "foo",
38
+ ],
39
+ Object {
40
+ "type": "infinite",
41
+ },
42
+ ]
43
+ `);
44
+ expect(getArrayQueryKey(['foo', 'bar'], 'query')).toMatchInlineSnapshot(`
45
+ Array [
46
+ Array [
47
+ "foo",
48
+ ],
49
+ Object {
50
+ "input": "bar",
51
+ "type": "query",
52
+ },
53
+ ]
54
+ `);
55
+ expect(getArrayQueryKey([undefined, 'bar'], 'query')).toMatchInlineSnapshot(`
27
56
  Array [
28
57
  Array [],
29
- "bar",
58
+ Object {
59
+ "input": "bar",
60
+ "type": "query",
61
+ },
30
62
  ]
31
63
  `);
32
- expect(getArrayQueryKey(['post.byId', '1'])).toMatchInlineSnapshot(`
64
+ expect(getArrayQueryKey(['post.byId', '1'], 'query')).toMatchInlineSnapshot(`
33
65
  Array [
34
66
  Array [
35
67
  "post",
36
68
  "byId",
37
69
  ],
38
- "1",
70
+ Object {
71
+ "input": "1",
72
+ "type": "query",
73
+ },
39
74
  ]
40
75
  `);
41
76
  });
@@ -1,3 +1,5 @@
1
+ export type QueryType = 'query' | 'infinite' | 'any';
2
+
1
3
  /**
2
4
  * To allow easy interactions with groups of related queries, such as
3
5
  * invalidating all queries of a router, we use an array as the path when
@@ -7,12 +9,22 @@
7
9
  */
8
10
  export function getArrayQueryKey(
9
11
  queryKey: string | [string] | [string, ...unknown[]] | unknown[],
10
- ): [string[]] | [string[], ...unknown[]] | [] {
12
+ type: QueryType,
13
+ ): [string[], { input?: unknown; type?: Exclude<QueryType, 'any'> }] {
11
14
  const queryKeyArrayed = Array.isArray(queryKey) ? queryKey : [queryKey];
12
- const [path, ...input] = queryKeyArrayed;
15
+ const [path, input] = queryKeyArrayed;
13
16
 
14
17
  const arrayPath =
15
18
  typeof path !== 'string' || path === '' ? [] : path.split('.');
16
19
 
17
- return [arrayPath, ...input];
20
+ // Construct a query key that is easy to destructure and flexible for
21
+ // partial selecting etc.
22
+ // https://github.com/trpc/trpc/issues/3128
23
+ return [
24
+ arrayPath,
25
+ {
26
+ ...(input && { input: input }),
27
+ ...(type && type !== 'any' && { type: type }),
28
+ },
29
+ ];
18
30
  }
package/src/interop.ts CHANGED
@@ -13,13 +13,14 @@ import {
13
13
  export function createReactQueryHooks<
14
14
  TRouter extends AnyRouter,
15
15
  TSSRContext = unknown,
16
+ TFlags = null,
16
17
  >(
17
18
  opts?: CreateTRPCReactOptions<TRouter>,
18
19
  ): CreateReactQueryHooks<TRouter, TSSRContext> & {
19
- proxy: CreateTRPCReact<TRouter, TSSRContext>;
20
+ proxy: CreateTRPCReact<TRouter, TSSRContext, TFlags>;
20
21
  } {
21
22
  const trpc = createHooksInternal<TRouter, TSSRContext>(opts);
22
- const proxy = createHooksInternalProxy<TRouter, TSSRContext>(trpc);
23
+ const proxy = createHooksInternalProxy<TRouter, TSSRContext, TFlags>(trpc);
23
24
 
24
25
  return {
25
26
  ...trpc,
@@ -1,7 +1,9 @@
1
1
  /* eslint-disable @typescript-eslint/no-non-null-assertion */
2
2
  import {
3
3
  DehydratedState,
4
+ InfiniteQueryObserverSuccessResult,
4
5
  QueryClient,
6
+ QueryObserverSuccessResult,
5
7
  UseInfiniteQueryOptions,
6
8
  UseInfiniteQueryResult,
7
9
  UseMutationOptions,
@@ -45,7 +47,7 @@ import {
45
47
  TRPCContextProps,
46
48
  TRPCContextState,
47
49
  } from '../../internals/context';
48
- import { getArrayQueryKey } from '../../internals/getArrayQueryKey';
50
+ import { QueryType, getArrayQueryKey } from '../../internals/getArrayQueryKey';
49
51
  import { CreateTRPCReactOptions, UseMutationOverride } from '../types';
50
52
 
51
53
  export type OutputWithCursor<TData, TCursor = any> = {
@@ -157,6 +159,11 @@ interface TRPCHookResult {
157
159
  export type UseTRPCQueryResult<TData, TError> = UseQueryResult<TData, TError> &
158
160
  TRPCHookResult;
159
161
 
162
+ /**
163
+ * @internal
164
+ */
165
+ export type UseTRPCQuerySuccessResult<TData, TError> =
166
+ QueryObserverSuccessResult<TData, TError> & TRPCHookResult;
160
167
  /**
161
168
  * @internal
162
169
  */
@@ -166,6 +173,12 @@ export type UseTRPCInfiniteQueryResult<TData, TError> = UseInfiniteQueryResult<
166
173
  > &
167
174
  TRPCHookResult;
168
175
 
176
+ /**
177
+ * @internal
178
+ */
179
+ export type UseTRPCInfiniteQuerySuccessResult<TData, TError> =
180
+ InfiniteQueryObserverSuccessResult<TData, TError> & TRPCHookResult;
181
+
169
182
  /**
170
183
  * @internal
171
184
  */
@@ -233,7 +246,7 @@ export function createHooksInternal<
233
246
  fetchQuery: useCallback(
234
247
  (pathAndInput, opts) => {
235
248
  return queryClient.fetchQuery(
236
- getArrayQueryKey(pathAndInput),
249
+ getArrayQueryKey(pathAndInput, 'query'),
237
250
  () =>
238
251
  (client as any).query(...getClientArgs(pathAndInput, opts)),
239
252
  opts,
@@ -244,7 +257,7 @@ export function createHooksInternal<
244
257
  fetchInfiniteQuery: useCallback(
245
258
  (pathAndInput, opts) => {
246
259
  return queryClient.fetchInfiniteQuery(
247
- getArrayQueryKey(pathAndInput),
260
+ getArrayQueryKey(pathAndInput, 'infinite'),
248
261
  ({ pageParam }) => {
249
262
  const [path, input] = pathAndInput;
250
263
  const actualInput = { ...(input as any), cursor: pageParam };
@@ -260,7 +273,7 @@ export function createHooksInternal<
260
273
  prefetchQuery: useCallback(
261
274
  (pathAndInput, opts) => {
262
275
  return queryClient.prefetchQuery(
263
- getArrayQueryKey(pathAndInput),
276
+ getArrayQueryKey(pathAndInput, 'query'),
264
277
  () =>
265
278
  (client as any).query(...getClientArgs(pathAndInput, opts)),
266
279
  opts,
@@ -271,7 +284,7 @@ export function createHooksInternal<
271
284
  prefetchInfiniteQuery: useCallback(
272
285
  (pathAndInput, opts) => {
273
286
  return queryClient.prefetchInfiniteQuery(
274
- getArrayQueryKey(pathAndInput),
287
+ getArrayQueryKey(pathAndInput, 'infinite'),
275
288
  ({ pageParam }) => {
276
289
  const [path, input] = pathAndInput;
277
290
  const actualInput = { ...(input as any), cursor: pageParam };
@@ -288,7 +301,7 @@ export function createHooksInternal<
288
301
  (...args: any[]) => {
289
302
  const [queryKey, ...rest] = args;
290
303
  return queryClient.invalidateQueries(
291
- getArrayQueryKey(queryKey),
304
+ getArrayQueryKey(queryKey, 'any'),
292
305
  ...rest,
293
306
  );
294
307
  },
@@ -299,7 +312,7 @@ export function createHooksInternal<
299
312
  const [queryKey, ...rest] = args;
300
313
 
301
314
  return queryClient.refetchQueries(
302
- getArrayQueryKey(queryKey),
315
+ getArrayQueryKey(queryKey, 'any'),
303
316
  ...rest,
304
317
  );
305
318
  },
@@ -307,7 +320,9 @@ export function createHooksInternal<
307
320
  ),
308
321
  cancelQuery: useCallback(
309
322
  (pathAndInput) => {
310
- return queryClient.cancelQueries(getArrayQueryKey(pathAndInput));
323
+ return queryClient.cancelQueries(
324
+ getArrayQueryKey(pathAndInput, 'any'),
325
+ );
311
326
  },
312
327
  [queryClient],
313
328
  ),
@@ -315,7 +330,7 @@ export function createHooksInternal<
315
330
  (...args) => {
316
331
  const [queryKey, ...rest] = args;
317
332
  return queryClient.setQueryData(
318
- getArrayQueryKey(queryKey),
333
+ getArrayQueryKey(queryKey, 'query'),
319
334
  ...rest,
320
335
  );
321
336
  },
@@ -326,7 +341,7 @@ export function createHooksInternal<
326
341
  const [queryKey, ...rest] = args;
327
342
 
328
343
  return queryClient.getQueryData(
329
- getArrayQueryKey(queryKey),
344
+ getArrayQueryKey(queryKey, 'query'),
330
345
  ...rest,
331
346
  );
332
347
  },
@@ -337,7 +352,7 @@ export function createHooksInternal<
337
352
  const [queryKey, ...rest] = args;
338
353
 
339
354
  return queryClient.setQueryData(
340
- getArrayQueryKey(queryKey),
355
+ getArrayQueryKey(queryKey, 'infinite'),
341
356
  ...rest,
342
357
  );
343
358
  },
@@ -348,7 +363,7 @@ export function createHooksInternal<
348
363
  const [queryKey, ...rest] = args;
349
364
 
350
365
  return queryClient.getQueryData(
351
- getArrayQueryKey(queryKey),
366
+ getArrayQueryKey(queryKey, 'infinite'),
352
367
  ...rest,
353
368
  );
354
369
  },
@@ -371,12 +386,16 @@ export function createHooksInternal<
371
386
  */
372
387
  function useSSRQueryOptionsIfNeeded<
373
388
  TOptions extends { retryOnMount?: boolean } | undefined,
374
- >(pathAndInput: unknown[], opts: TOptions): TOptions {
389
+ >(
390
+ pathAndInput: unknown[],
391
+ type: Exclude<QueryType, 'any'>,
392
+ opts: TOptions,
393
+ ): TOptions {
375
394
  const { queryClient, ssrState } = useContext();
376
395
  return ssrState &&
377
396
  ssrState !== 'mounted' &&
378
- queryClient.getQueryCache().find(getArrayQueryKey(pathAndInput))?.state
379
- .status === 'error'
397
+ queryClient.getQueryCache().find(getArrayQueryKey(pathAndInput, type))
398
+ ?.state.status === 'error'
380
399
  ? {
381
400
  retryOnMount: false,
382
401
  ...opts,
@@ -406,16 +425,16 @@ export function createHooksInternal<
406
425
  ssrState === 'prepass' &&
407
426
  opts?.trpc?.ssr !== false &&
408
427
  opts?.enabled !== false &&
409
- !queryClient.getQueryCache().find(getArrayQueryKey(pathAndInput))
428
+ !queryClient.getQueryCache().find(getArrayQueryKey(pathAndInput, 'query'))
410
429
  ) {
411
430
  void prefetchQuery(pathAndInput as any, opts as any);
412
431
  }
413
- const ssrOpts = useSSRQueryOptionsIfNeeded(pathAndInput, opts);
432
+ const ssrOpts = useSSRQueryOptionsIfNeeded(pathAndInput, 'query', opts);
414
433
  // request option should take priority over global
415
434
  const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? abortOnUnmount;
416
435
 
417
436
  const hook = __useQuery(
418
- getArrayQueryKey(pathAndInput) as any,
437
+ getArrayQueryKey(pathAndInput, 'query') as any,
419
438
  (queryFunctionContext) => {
420
439
  const actualOpts = {
421
440
  ...ssrOpts,
@@ -575,18 +594,20 @@ export function createHooksInternal<
575
594
  ssrState === 'prepass' &&
576
595
  opts?.trpc?.ssr !== false &&
577
596
  opts?.enabled !== false &&
578
- !queryClient.getQueryCache().find(getArrayQueryKey(pathAndInput))
597
+ !queryClient
598
+ .getQueryCache()
599
+ .find(getArrayQueryKey(pathAndInput, 'infinite'))
579
600
  ) {
580
601
  void prefetchInfiniteQuery(pathAndInput as any, opts as any);
581
602
  }
582
603
 
583
- const ssrOpts = useSSRQueryOptionsIfNeeded(pathAndInput, opts);
604
+ const ssrOpts = useSSRQueryOptionsIfNeeded(pathAndInput, 'infinite', opts);
584
605
 
585
606
  // request option should take priority over global
586
607
  const shouldAbortOnUnmount = opts?.trpc?.abortOnUnmount ?? abortOnUnmount;
587
608
 
588
609
  const hook = __useInfiniteQuery(
589
- getArrayQueryKey(pathAndInput) as any,
610
+ getArrayQueryKey(pathAndInput, 'infinite') as any,
590
611
  (queryFunctionContext) => {
591
612
  const actualOpts = {
592
613
  ...ssrOpts,
@@ -28,6 +28,17 @@ export function createReactProxyDecoration<
28
28
  const [input, ...rest] = args;
29
29
 
30
30
  const queryKey = getQueryKey(path, input);
31
+ if (lastArg.startsWith('useSuspense')) {
32
+ const opts = rest[0] || {};
33
+ const fn =
34
+ lastArg === 'useSuspenseQuery' ? 'useQuery' : 'useInfiniteQuery';
35
+ const result = (hooks as any)[fn](queryKey, {
36
+ ...opts,
37
+ suspense: true,
38
+ enabled: true,
39
+ });
40
+ return [result.data, result];
41
+ }
31
42
  return (hooks as any)[lastArg](queryKey, ...rest);
32
43
  });
33
44
  }