MCPcopy Index your code
hub / github.com/TanStack/db / queryCollectionOptions

Function queryCollectionOptions

packages/query-db-collection/src/query.ts:565–1950  ·  view source on GitHub ↗
(
  config: QueryCollectionConfig<
    Record<string, unknown>,
    (context: QueryFunctionContext<any>) => any
  >,
)

Source from the content-addressed store, hash-verified

563}
564
565export function queryCollectionOptions(
566 config: QueryCollectionConfig<
567 Record<string, unknown>,
568 (context: QueryFunctionContext<any>) => any
569 >,
570): CollectionConfig<
571 Record<string, unknown>,
572 string | number,
573 never,
574 QueryCollectionUtils
575> & {
576 utils: QueryCollectionUtils
577} {
578 const {
579 queryKey,
580 queryFn,
581 select,
582 queryClient,
583 enabled,
584 refetchInterval,
585 retry,
586 retryDelay,
587 staleTime,
588 gcTime,
589 persistedGcTime,
590 getKey,
591 onInsert,
592 onUpdate,
593 onDelete,
594 meta,
595 ...baseCollectionConfig
596 } = config
597
598 // Default to eager sync mode if not provided
599 const syncMode = baseCollectionConfig.syncMode ?? `eager`
600
601 // Compute the base query key once for cache lookups.
602 // All derived keys (from on-demand predicates or function-based queryKey) must
603 // share this prefix so that queryCache.findAll({ queryKey: baseKey }) can find them.
604 const baseKey: QueryKey =
605 typeof queryKey === `function`
606 ? (queryKey({}) as unknown as QueryKey)
607 : (queryKey as unknown as QueryKey)
608
609 /**
610 * Validates that a derived query key extends the base key prefix.
611 * TanStack Query uses prefix matching in findAll(), so all keys for this collection
612 * must start with baseKey for stale cache updates to work correctly.
613 */
614 const validateQueryKeyPrefix = (key: QueryKey): void => {
615 if (typeof queryKey !== `function`) return
616 const isValidPrefix =
617 key.length >= baseKey.length &&
618 baseKey.every((segment, i) => deepEquals(segment, key[i]))
619 if (!isValidPrefix) {
620 console.warn(
621 `[QueryCollection] queryKey function must return keys that extend the base key prefix. ` +
622 `Base: ${JSON.stringify(baseKey)}, Got: ${JSON.stringify(key)}. ` +

Callers 11

query.test.tsFile · 0.90
query.test-d.tsFile · 0.90
query.e2e.test.tsFile · 0.90
collections.tsFile · 0.90
collections.tsFile · 0.90
todos.tsFile · 0.90
todos.tsFile · 0.90
collections.tsFile · 0.90
createTodosFunction · 0.90

Calls 3

createWriteUtilsFunction · 0.90
queryKeyFunction · 0.85
refetchFunction · 0.85

Tested by 1