(
self: { id: string; options?: ClientForOptions; disableQueryInvalidation?: boolean },
options: MutationOptionsBase | undefined,
queryInvalidator: QueryInvalidator<RInvalidator>
)
| 345 | writeDependencies: [...writeDependencies] |
| 346 | }), |
| 347 | // refetch + AWAIT every live query registered under these keys, so by the time the |
| 348 | // mutation resolves the affected queries are fresh. |
| 349 | Effect.gen(function*() { |
| 350 | if (softKeys.length > 0) { |
| 351 | yield* (queryInvalidator.invalidateSoft?.(softKeys) ?? Effect.void).pipe( |
| 352 | Effect.catchCause((cause) => |
| 353 | reportRuntimeError(cause, { invalidation: "soft", keys: softKeys }).pipe(Effect.asVoid) |
| 354 | ), |
| 355 | Effect.forkDetach({ startImmediately: true }) |
| 356 | ) |
| 357 | } |
| 358 | if (awaitKeys.length > 0) { |
| 359 | yield* queryInvalidator.invalidateAndAwait(awaitKeys) |
| 360 | } |
| 361 | }) |
| 362 | ) |
| 363 | .pipe( |
| 364 | Effect.tap(Effect.sleep(0.1)), // allow for refs to update etc |
| 365 | Effect.withSpan("client.query.invalidation", {}, { captureStackTrace: false }) |
| 366 | ) |
| 367 | }) |
| 368 | |
| 369 | return invalidateCache |
| 370 | } |
| 371 | |
| 372 | export const invalidateQueries = <RInvalidator>( |
| 373 | self: { id: string; options?: ClientForOptions; disableQueryInvalidation?: boolean }, |
| 374 | options: MutationOptionsBase | undefined, |
| 375 | queryInvalidator: QueryInvalidator<RInvalidator> |
| 376 | ) => { |
| 377 | const invalidateCache = buildInvalidateCache(self, options?.queryInvalidation, queryInvalidator) |
| 378 | |
| 379 | const select = options?.select |
| 380 | |
| 381 | const handle = <A, E, R>(eff: Effect.Effect<A, E, R>, input?: unknown) => |
| 382 | Effect.gen(function*() { |
| 383 | const keysRef = yield* Ref.make<ReadonlyArray<InvalidationKey>>([]) |
| 384 | const readsRef = yield* Ref.make(DataDependencies.empty()) |
| 385 | const writesRef = yield* Ref.make(DataDependencies.empty()) |
| 386 | const dependencyRecorder = DataDependencies.makeDataDependencyRecorder(readsRef, writesRef) |
| 387 | const result = yield* eff.pipe( |
| 388 | Effect.provideService(InvalidationKeysFromServer, makeInvalidationKeysService(keysRef)), |
| 389 | Effect.provideService(DataDependencies.DataDependencyRecorder, dependencyRecorder), |
| 390 | Effect.onExit((exit) => |
| 391 | Effect.gen(function*() { |
searching dependent graphs…