MCPcopy Create free account
hub / github.com/dailydotdev/apps / updateInfiniteCache

Function updateInfiniteCache

packages/shared/src/lib/query.ts:348–382  ·  view source on GitHub ↗
({
  client,
  prop,
  queryKey,
  page,
  edge,
  entity,
}: UpdateInfiniteCacheProps<TEntity, TKey, TData>)

Source from the content-addressed store, hash-verified

346}
347
348export const updateInfiniteCache = <
349 TEntity extends HasConnection<TEntity>,
350 TKey extends keyof TEntity = keyof TEntity,
351 TData extends ConnectionNode<NonNullable<TEntity[TKey]>> = ConnectionNode<
352 NonNullable<TEntity[TKey]>
353 >,
354 TReturn extends InfiniteData<TEntity> = InfiniteData<TEntity>,
355>({
356 client,
357 prop,
358 queryKey,
359 page,
360 edge,
361 entity,
362}: UpdateInfiniteCacheProps<TEntity, TKey, TData>): TReturn | undefined => {
363 return client.setQueryData<TReturn>(queryKey, (data) => {
364 if (!data) {
365 return data;
366 }
367
368 const updated = structuredClone(data);
369 const pageData = updated.pages[page];
370 const connection = pageData?.[prop] as Connection<TData> | undefined;
371 const targetEdge = connection?.edges?.[edge];
372
373 if (!pageData || !connection || !targetEdge) {
374 return data;
375 }
376
377 const item = targetEdge.node as EmptyObjectLiteral;
378 targetEdge.node = { ...item, ...entity } as TData;
379
380 return updated;
381 });
382};
383
384export const mutationSuccessSubscribers: Map<
385 string,

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected