Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,7 @@ describe('Agents needs-input badge and shared live count', () => {
'updates to %i from the shared cache while Home has focus',
async count => {
const queryClient = makeTestQueryClient();
await queryClient.fetchQuery({
await queryClient.query({
queryKey: key(),
queryFn: makeQueryFn(),
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,13 @@ describe.each([
organizationId: 'org_123',
});
const other = trpc.securityAgent.getConfig.queryOptions();
void queryClient.prefetchQuery(other);
void (async () => {
try {
await queryClient.query(other);
} catch {
// Offline: the fetch stays paused for the retry path.
}
})();
queryClient.setQueryData(configKey, configData);
const root = await mount('org_123', Screen);
const error = host(root, 'PlatformErrorScreen')[0];
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/components/todos/todo-lists-screen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export function TodoListsScreen({ segmentControl }: Readonly<{ segmentControl: R
void (async () => {
// The count covers finished to-dos too, which `openCount` leaves out.
const items = await queryClient
.fetchQuery(trpc.todos.items.list.queryOptions({ listId: list.id }))
.query(trpc.todos.items.list.queryOptions({ listId: list.id }))
.catch(() => null);
const deleteList = () => {
void Haptics.notificationAsync(Haptics.NotificationFeedbackType.Success);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ describe('ActiveSessionsLiveSync — manual refresh', () => {
sync.attach();

let settled = false;
const fetchSpy = vi.spyOn(qc, 'fetchQuery');
const fetchSpy = vi.spyOn(qc, 'query');
const pending = (async () => {
const result = await refreshActiveSessionsNow(QUERY_KEY);
settled = true;
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/src/lib/active-sessions-live-sync.test-helpers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,9 @@ export function makeFakeQueryClient(
const seed = qc.setQueryData.bind(qc);
seed(QUERY_KEY, initial);
let pendingFetch: Deferred<CachedActiveSessionsData> | null = null;
const fetch = qc.fetchQuery.bind(qc);
const fetch = qc.query.bind(qc);
const cancel = qc.cancelQueries.bind(qc);
const fetchSpy = vi.spyOn(qc, 'fetchQuery').mockImplementation(async options => {
const fetchSpy = vi.spyOn(qc, 'query').mockImplementation(async options => {
const queryFn = options.queryFn;
if (typeof queryFn !== 'function') {
throw new TypeError('Expected a query function');
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/lib/active-sessions-live-sync.ts
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,7 @@ export class ActiveSessionsLiveSync {
try {
await queryClient.cancelQueries({ queryKey, exact: true });
if (this.isCurrentAttachment(attachmentEpoch) && refresh.isCurrent()) {
const fetchPromise = queryClient.fetchQuery({
const fetchPromise = queryClient.query({
queryKey,
queryFn: fenceActiveSessionsQuery(queryFn, () =>
this.isCurrentAttachment(attachmentEpoch)
Expand Down
12 changes: 7 additions & 5 deletions apps/mobile/src/lib/agent-session-cache.ts
Original file line number Diff line number Diff line change
Expand Up @@ -51,11 +51,13 @@ export const SESSION_TRANSCRIPT_STALE_TIME_MS = 60_000;
* fetching on the critical path.
*/
export async function prefetchSessionTranscript(
queryClient: Pick<QueryClient, 'prefetchQuery'>,
queryClient: Pick<QueryClient, 'query'>,
options: { queryKey: readonly unknown[] }
): Promise<void> {
await queryClient.prefetchQuery({
...options,
staleTime: SESSION_TRANSCRIPT_STALE_TIME_MS,
});
await queryClient
.query({
...options,
staleTime: SESSION_TRANSCRIPT_STALE_TIME_MS,
})
.catch(() => undefined);
}
2 changes: 1 addition & 1 deletion apps/mobile/src/lib/credits/use-store-credit-products.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export function useStoreCreditProducts(options: StoreCreditProductsOptions) {
const loadedProducts = await loadStoreCreditProducts({
fetchStoreProducts: options.fetchStoreProducts,
loadBackendProducts: async () => {
const backendResponse = await queryClient.fetchQuery(
const backendResponse = await queryClient.query(
trpc.credits.getMobileStoreProducts.queryOptions()
);
return backendResponse;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,7 +250,7 @@ describe('live query presentation and refresh contracts', () => {
it.each(['cancel', 'sign-out'])(
'rejects a fallback result after %s without publishing late data',
async boundary => {
await client.fetchQuery({ queryKey: QUERY_KEY, queryFn: () => cached });
await client.query({ queryKey: QUERY_KEY, queryFn: () => cached });
await render();
const network = deferred<CachedActiveSessionsData>();
state.request.mockReturnValue(network.promise);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ describe('useRouteForegroundRefresh key matching with a real QueryClient', () =>
it('invalidates a tRPC-shaped query key with the nested prefix form', async () => {
const queryClient = new QueryClient();
const queryFn = vi.fn().mockResolvedValue('sentinel');
await queryClient.prefetchQuery({ queryKey: [['user', 'getMe']], queryFn });
await queryClient.query({ queryKey: [['user', 'getMe']], queryFn });

await renderProbeWithProvider(queryClient, [[['user']]]);

Expand All @@ -246,7 +246,7 @@ describe('useRouteForegroundRefresh key matching with a real QueryClient', () =>
it('does not invalidate a tRPC-shaped query key with the flat prefix form', async () => {
const queryClient = new QueryClient();
const queryFn = vi.fn().mockResolvedValue('sentinel');
await queryClient.prefetchQuery({ queryKey: [['user', 'getMe']], queryFn });
await queryClient.query({ queryKey: [['user', 'getMe']], queryFn });

await renderProbeWithProvider(queryClient, [['user']]);

Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/lib/hooks/use-security-agent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ export function useRetrySecurityAgentSettings(scope: string) {
// Cancel first, then bypass NetInfo for this deliberate attempt only.
await queryClient.cancelQueries({ queryKey, exact: true });
try {
await queryClient.fetchQuery({
await queryClient.query({
...options,
queryKey,
networkMode: 'always',
Expand Down
4 changes: 2 additions & 2 deletions apps/mobile/src/lib/hooks/use-session-mutations.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -116,12 +116,12 @@ describe('useSessionMutations account publication', () => {

it('retitles and rolls back both caches without accepting manual writes or clearing a fetch failure', async () => {
const query = client.getQueryCache().find({ queryKey: QUERY_KEY, exact: true });
await client.fetchQuery({
await client.query({
queryKey: QUERY_KEY,
queryFn: () => ({ sessions: [makeCached({ id: 's1', title: 'Old' })] }),
});
await expect(
client.fetchQuery({
client.query({
queryKey: QUERY_KEY,
queryFn: () => {
throw new Error('offline');
Expand Down
1 change: 1 addition & 0 deletions apps/mobile/src/lib/persist/test-fixtures.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export function makePersistedClient(data: unknown, buster = ''): PersistedClient
{
queryHash: hashKey(GET_ME_QUERY_KEY),
queryKey: GET_ME_QUERY_KEY,
dehydratedAt: Date.now(),
state: {
data,
dataUpdateCount: 0,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,7 @@ export function usePrDiffContextLoader(args: {
const target = contextScopeForItem(scope, item.ref, { owner, repo, headSha });
void (async () => {
try {
const result = await queryClient.fetchQuery(
const result = await queryClient.query(
buildPrFileLinesQueryOptions(trpc, target.scope, {
ref: target.ref,
path: item.filePath,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ export function useCheckGitHubConnection() {

return useMutation({
mutationFn: async () => {
const authorization = await queryClient.fetchQuery({
const authorization = await queryClient.query({
...trpc.githubApps.getUserAuthorization.queryOptions(),
staleTime: 0,
});
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,18 @@ export function useCheckProviderConnection() {
}
// The two providers answer with different status shapes, so each arm
// fetches its own options — a union of the two queryOptions types is
// not assignable to a single fetchQuery call.
// not assignable to a single query call.
const status =
input.platform === 'gitlab'
? await queryClient.fetchQuery({
? await queryClient.query({
...(input.organizationId
? trpc.organizations.reviewAgent.getGitLabStatus.queryOptions({
organizationId: input.organizationId,
})
: trpc.personalReviewAgent.getGitLabStatus.queryOptions()),
staleTime: 0,
})
: await queryClient.fetchQuery({
: await queryClient.query({
...trpc.organizations.reviewAgent.getBitbucketReadiness.queryOptions({
organizationId: input.organizationId ?? '',
}),
Expand Down
30 changes: 15 additions & 15 deletions apps/mobile/src/lib/query-client.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ describe('query retry policy', () => {
let attempts = 0;

await expect(
queryClient.fetchQuery({
queryClient.query({
queryKey: ['session', 'retry-policy', code],
retryDelay: 0,
queryFn: () => {
Expand Down Expand Up @@ -90,7 +90,7 @@ describe('permission-denied query removal', () => {
});

await expect(
queryClient.fetchQuery({
queryClient.query({
queryKey: org1Key,
staleTime: 0,
queryFn: () => {
Expand Down Expand Up @@ -123,7 +123,7 @@ describe('permission-denied query removal', () => {
});

await expect(
queryClient.fetchQuery({
queryClient.query({
queryKey: key,
staleTime: 0,
queryFn: () => {
Expand Down Expand Up @@ -188,7 +188,7 @@ describe('permission-denied query removal', () => {
});

await expect(
queryClient.fetchQuery({
queryClient.query({
queryKey: key,
staleTime: 0,
queryFn: () => {
Expand All @@ -214,7 +214,7 @@ describe('accepted active-session outcomes', () => {
const query = client.getQueryCache().find({ queryKey: QUERY_KEY, exact: true });
query?.setState({ status: 'success', dataUpdatedAt: Date.now() - 1 });
expect(getActiveSessionsQueryMetadata(query)).toBe(absent);
await client.fetchQuery({ queryKey: QUERY_KEY, queryFn: () => emptyResult, staleTime: 0 });
await client.query({ queryKey: QUERY_KEY, queryFn: () => emptyResult, staleTime: 0 });
const accepted = getActiveSessionsQueryMetadata(query);
expect(accepted.acceptedRevision).toBe(1);
client.setQueryData(QUERY_KEY, emptyResult);
Expand Down Expand Up @@ -250,7 +250,7 @@ describe('accepted active-session outcomes', () => {
expect(failed.acceptedRevision).toBe(0);
client.setQueryData(QUERY_KEY, { sessions: [{ id: 'live', title: 'socket' }] });
const recovery = deferred<typeof emptyResult>();
const retry = client.fetchQuery({
const retry = client.query({
queryKey: QUERY_KEY,
queryFn: async () => {
const result = await recovery.promise;
Expand All @@ -262,7 +262,7 @@ describe('accepted active-session outcomes', () => {
await retry;
expect(getActiveSessionsQueryMetadata(query)).toBe(failed);
recovery.resolve(emptyResult);
await client.fetchQuery({ queryKey: QUERY_KEY, queryFn: () => emptyResult });
await client.query({ queryKey: QUERY_KEY, queryFn: () => emptyResult });
expect(getActiveSessionsQueryMetadata(query)).toEqual({
acceptedRevision: 1,
terminalError: null,
Expand All @@ -275,7 +275,7 @@ describe('accepted active-session outcomes', () => {
const client = makeClient();
const result = deferred<typeof emptyResult>();
let attempts = 0;
const pending = client.fetchQuery({
const pending = client.query({
queryKey: QUERY_KEY,
retry: 1,
retryDelay: 0,
Expand All @@ -302,7 +302,7 @@ describe('accepted active-session outcomes', () => {
'preserves provenance across remounts but resets it after %s',
async removal => {
const client = makeClient();
await client.fetchQuery({ queryKey: QUERY_KEY, queryFn: () => emptyResult });
await client.query({ queryKey: QUERY_KEY, queryFn: () => emptyResult });
const query = client.getQueryCache().find({ queryKey: QUERY_KEY, exact: true });
const accepted = getActiveSessionsQueryMetadata(query);
const observer = new QueryObserver(client, { queryKey: QUERY_KEY, staleTime: Infinity });
Expand All @@ -325,7 +325,7 @@ describe('accepted active-session outcomes', () => {
const recreated = client.getQueryCache().find({ queryKey: QUERY_KEY, exact: true });
expect(recreated).not.toBe(query);
expect(getActiveSessionsQueryMetadata(recreated).acceptedRevision).toBe(0);
await client.fetchQuery({ queryKey: QUERY_KEY, queryFn: () => emptyResult });
await client.query({ queryKey: QUERY_KEY, queryFn: () => emptyResult });
expect(getActiveSessionsQueryMetadata(recreated).acceptedRevision).toBe(1);
expect(published).toEqual([0]);
}
Expand All @@ -352,17 +352,17 @@ describe('accepted active-session outcomes', () => {
subscribeActiveSessionsQueryMetadata(otherQuery, () => {
otherPublished.push(getActiveSessionsQueryMetadata(otherQuery).acceptedRevision);
});
await client.fetchQuery({ queryKey: otherKey, queryFn: () => emptyResult });
await client.query({ queryKey: otherKey, queryFn: () => emptyResult });
expect(
getActiveSessionsQueryMetadata(client.getQueryCache().find({ queryKey: otherKey }))
.acceptedRevision
).toBe(0);
expect(published).toEqual([]);
await client.fetchQuery({ queryKey: QUERY_KEY, queryFn: () => emptyResult });
await client.query({ queryKey: QUERY_KEY, queryFn: () => emptyResult });
expect(published).toEqual([1]);
client.setQueryData(QUERY_KEY, emptyResult);
expect(published).toEqual([1]);
await client.fetchQuery({ queryKey: QUERY_KEY, queryFn: () => emptyResult });
await client.query({ queryKey: QUERY_KEY, queryFn: () => emptyResult });
expect(published).toEqual([1, 2]);
expect(otherPublished).toEqual([]);
expect(getActiveSessionsQueryMetadata(otherQuery).acceptedRevision).toBe(0);
Expand All @@ -383,7 +383,7 @@ describe('app error reporting', () => {

const generic = new Error('generic query failure');
await expect(
queryClient.fetchQuery({
queryClient.query({
queryKey: ['session', 'generic'],
queryFn: () => {
throw generic;
Expand All @@ -404,7 +404,7 @@ describe('app error reporting', () => {
data: { code: 'INTERNAL_SERVER_ERROR' },
});
await expect(
queryClient.fetchQuery({
queryClient.query({
queryKey: ['session', 'trpc'],
queryFn: () => {
throw trpcError;
Expand Down
3 changes: 2 additions & 1 deletion apps/mobile/src/lib/settings/bindings.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,13 @@ export const NOTIFICATION_PREFERENCES_QUERY_KEY = [
export function readNotificationPreferences(): Effect.Effect<NotificationPreferences, ToolFailure> {
return Effect.tryPromise({
try: async () => {
const preferences = await queryClient.ensureQueryData({
const preferences = await queryClient.query({
queryKey: NOTIFICATION_PREFERENCES_QUERY_KEY,
queryFn: async () => {
const result = await trpcClient.user.getNotificationPreferences.query();
return result;
},
staleTime: 'static',
});
return preferences;
},
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/lib/settings/registry.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ vi.mock('@/lib/trpc', () => ({

const queryClientMock = vi.hoisted(() => ({
getQueryData: vi.fn(),
ensureQueryData: vi.fn(async ({ queryFn }: { queryFn: () => Promise<unknown> }) => {
query: vi.fn(async ({ queryFn }: { queryFn: () => Promise<unknown> }) => {
const result = await queryFn();
return result;
}),
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/lib/startup-prefetch.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ export function prefetchCurrentUser(): void {
try {
const token = await preloadedAuthToken;
if (token != null) {
await queryClient.prefetchQuery(trpcOptions.user.getMe.queryOptions());
await queryClient.query(trpcOptions.user.getMe.queryOptions()).catch(() => undefined);
}
} catch {
// A rejected preload (keychain unavailable at process start) must not
Expand Down
2 changes: 1 addition & 1 deletion apps/mobile/src/lib/use-github-repos-refresh.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export function useGitHubReposRefresh({
async (isReturnTriggered: boolean) => {
setIsRefreshingRepos(true);
try {
const fresh = await queryClient.fetchQuery({
const fresh = await queryClient.query({
...(organizationId
? trpc.organizations.cloudAgentNext.listGitHubRepositories.queryOptions({
organizationId,
Expand Down
Loading
Loading