Macro is a unified workspace for teams: email, chat, docs, tasks, agents, calls, and CRM — @-linked together with shared AI memory.
TypeScript agentaiai-agentsall-in-onecrmcrm-systememaillinearmcpmessagingnotesnotionofficerustslackslack-alternativestartupstartup-toolstypescriptworkspace
fix(graphql-cache): stop a dropped link repair stalling the mutation queue (#9771)
teo9f85146b418f
diff --git a/apps/web/src/lib/graphql-cache/exchange/normalized-cache-exchange.test.ts b/apps/web/src/lib/graphql-cache/exchange/normalized-cache-exchange.test.tsindex dbedc1c1c0..353af84c78 100644--- a/apps/web/src/lib/graphql-cache/exchange/normalized-cache-exchange.test.ts+++ b/apps/web/src/lib/graphql-cache/exchange/normalized-cache-exchange.test.ts@@ -607,6 +607,12 @@ function harness(query: vi.fn((_query, _variables, _context) => ({toPromise: () => Promise.resolve({ data: {} }),})),+ createRequestOperation: vi.fn((kind, request, context) =>+ makeOperation(kind, request, context)+ ),+ executeRequestOperation: vi.fn((_operation) => ({+ toPromise: () => Promise.resolve({ data: {} }),+ })),mutation: vi.fn((query, variables, context) => ({toPromise: () => {const request = createRequest(query, variables);@@ -5479,13 +5485,19 @@ describe('normalizedCacheExchange', () => {const { ops, client, results, forwarded } = harness(host, undefined, {onCacheError,});- vi.mocked(client.query).mockReturnValue({+ vi.mocked(client.executeRequestOperation).mockReturnValue({toPromise: () => read.promise,} as never);ops.next(makeMutationOp(1, optimistic));await vi.advanceTimersByTimeAsync(0);expect(host.commits).toHaveLength(1);- expect(client.query).toHaveBeenCalledOnce();+ expect(client.query).not.toHaveBeenCalled();+ expect(client.executeRequestOperation).toHaveBeenCalledOnce();+ // urql drops a query whose key has a dispatch outstanding.+ const [repair] = vi.mocked(client.executeRequestOperation).mock+ .calls[0];+ expect(repair.key).toBeLessThan(0);+ expect(repair.key).not.toBe(createRequest(QUERY, {}).key);if (stage === 'persistence') {read.resolve({...queryResult(makeOp(2, 'network-only')),diff --git a/apps/web/src/lib/graphql-cache/exchange/normalized-cache-exchange.ts b/apps/web/src/lib/graphql-cache/exchange/normalized-cache-exchange.tsindex 9b617bc2d3..04fd922216 100644--- a/apps/web/src/lib/graphql-cache/exchange/normalized-cache-exchange.ts+++ b/apps/web/src/lib/graphql-cache/exchange/normalized-cache-exchange.ts@@ -41,6 +41,7 @@ import { type Span, Telemetry } from '@macro-inc/observability';import {type Client,CombinedError,+ createRequest,type Exchange,makeOperation,type Operation,@@ -119,6 +120,35 @@ const QUERY_MUTATION_VERSION_CONTEXT_KEY ='normalizedCacheQueryMutationVersion';/** Marks dependency-pushed reads as latency-sensitive worker work. */const AFFECTED_READ_CONTEXT_KEY = 'normalizedCacheAffectedRead';++// Below every hashed operation key, so a link repair shares none of them.+let lastLinkRepairKey = -(2 ** 40);++/**+ * A link repair gets its own operation key, because the mutation queue waits for+ * it. urql drops a query whose key has a dispatch outstanding, and an affected+ * reread this exchange fences never reports back, so on a shared key the repair+ * was never sent and held the whole queue until its timeout. Other revalidations+ * aren't waited on, and share the mounted reader's key and scope.+ */+function revalidationQuery(+ client: Client,+ document: DocumentNode,+ variables: Record<string, unknown>,+ isLinkRepair: boolean+) {+ if (!isLinkRepair) {+ return client.query(document, variables, { requestPolicy: 'network-only' });+ }+ lastLinkRepairKey -= 1;+ return client.executeRequestOperation(+ client.createRequestOperation(+ 'query',+ { ...createRequest(document, variables), key: lastLinkRepairKey },+ { requestPolicy: 'network-only' }+ )+ );+}/** Prevents a replacement-registration cache read from forwarding the API again. */const REPLACEMENT_REGISTRATION_ONLY_CONTEXT_KEY ='normalizedCacheReplacementRegistrationOnly';@@ -953,11 +983,12 @@ export function normalizedCacheExchange(}))return;- const result = await client- .query(document, variables as Record<string, unknown>, {- requestPolicy: 'network-only',- })- .toPromise();+ const result = await revalidationQuery(+ client,+ document,+ variables as Record<string, unknown>,+ revalidation.onlyOnLinkFailure === true+ ).toPromise();if (result.error)reportError(result.error, mutation ?? result.operation);const metadata = normalizedCacheResultMetadata(result);