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

Function updateInfiniteCache

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

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected