Open History to see the last commit
1---
2id: QueryCollectionConfig
3title: QueryCollectionConfig
4---
5
6# Interface: QueryCollectionConfig\<T, TQueryFn, TError, TQueryKey, TKey, TSchema, TQueryData\>
7
8Defined in: [packages/query-db-collection/src/query.ts:60](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L60)
9
10Configuration options for creating a Query Collection
11
12## Extends
13
14- `BaseCollectionConfig`\<`T`, `TKey`, `TSchema`\>
15
16## Type Parameters
17
18### T
19
20`T` *extends* `object` = `object`
21
22The explicit type of items stored in the collection
23
24### TQueryFn
25
26`TQueryFn` *extends* (`context`) => `any` = (`context`) => `any`
27
28The queryFn type
29
30### TError
31
32`TError` = `unknown`
33
34The type of errors that can occur during queries
35
36### TQueryKey
37
38`TQueryKey` *extends* `QueryKey` = `QueryKey`
39
40The type of the query key
41
42### TKey
43
44`TKey` *extends* `string` \| `number` = `string` \| `number`
45
46The type of the item keys
47
48### TSchema
49
50`TSchema` *extends* `StandardSchemaV1` = `never`
51
52The schema type for validation
53
54### TQueryData
55
56`TQueryData` = `Awaited`\<`ReturnType`\<`TQueryFn`\>\>
57
58## Properties
59
60### enabled?
61
62```ts
63optional enabled: Enabled<TQueryData, TError, TQueryData, TQueryKey>;
64```
65
66Defined in: [packages/query-db-collection/src/query.ts:86](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L86)
67
68Whether the query should automatically run (default: true)
69
70***
71
72### meta?
73
74```ts
75optional meta: Record<string, unknown>;
76```
77
78Defined in: [packages/query-db-collection/src/query.ts:142](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L142)
79
80Metadata to pass to the query.
81Available in queryFn via context.meta
82
83#### Example
84
85```ts
86// Using meta for error context
87queryFn: async (context) => {
88 try {
89 return await api.getTodos(userId)
90 } catch (error) {
91 // Use meta for better error messages
92 throw new Error(
93 context.meta?.errorMessage || 'Failed to load todos'
94 )
95 }
96},
97meta: {
98 errorMessage: `Failed to load todos for user ${userId}`
99}
100```
101
102***
103
104### queryClient
105
106```ts
107queryClient: QueryClient;
108```
109
110Defined in: [packages/query-db-collection/src/query.ts:82](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L82)
111
112The TanStack Query client instance
113
114***
115
116### queryFn
117
118```ts
119queryFn: TQueryFn extends (context) => any[] | Promise<any[]> ? (context) => T[] | Promise<T[]> : TQueryFn;
120```
121
122Defined in: [packages/query-db-collection/src/query.ts:74](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L74)
123
124Function that fetches data from the server. Must return the complete collection state
125
126***
127
128### queryKey
129
130```ts
131queryKey: TQueryKey | TQueryKeyBuilder<TQueryKey>;
132```
133
134Defined in: [packages/query-db-collection/src/query.ts:72](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L72)
135
136The query key used by TanStack Query to identify this query
137
138***
139
140### refetchInterval?
141
142```ts
143optional refetchInterval: number | false | (query) => number | false | undefined;
144```
145
146Defined in: [packages/query-db-collection/src/query.ts:93](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L93)
147
148***
149
150### retry?
151
152```ts
153optional retry: RetryValue<TError>;
154```
155
156Defined in: [packages/query-db-collection/src/query.ts:100](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L100)
157
158***
159
160### retryDelay?
161
162```ts
163optional retryDelay: RetryDelayValue<TError>;
164```
165
166Defined in: [packages/query-db-collection/src/query.ts:107](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L107)
167
168***
169
170### select()?
171
172```ts
173optional select: (data) => T[];
174```
175
176Defined in: [packages/query-db-collection/src/query.ts:80](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L80)
177
178#### Parameters
179
180##### data
181
182`TQueryData`
183
184#### Returns
185
186`T`[]
187
188***
189
190### staleTime?
191
192```ts
193optional staleTime: StaleTimeFunction<TQueryData, TError, TQueryData, TQueryKey>;
194```
195
196Defined in: [packages/query-db-collection/src/query.ts:114](https://github.com/TanStack/db/blob/main/packages/query-db-collection/src/query.ts#L114)