Skip to content

Commit 7320ec8

Browse files
committed
Use reobserve everywhere that setOptions is used
1 parent 084432f commit 7320ec8

12 files changed

+49
-49
lines changed

src/__tests__/ApolloClient.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -3206,12 +3206,12 @@ describe("ApolloClient", () => {
32063206
UnmaskedQuery | undefined
32073207
>();
32083208

3209-
const setOptionsResult = await observableQuery.setOptions({
3209+
const reobserveResult = await observableQuery.reobserve({
32103210
variables: { id: "2" },
32113211
});
32123212

3213-
expectTypeOf(setOptionsResult.data).toMatchTypeOf<Query | undefined>();
3214-
expectTypeOf(setOptionsResult.data).not.toMatchTypeOf<
3213+
expectTypeOf(reobserveResult.data).toMatchTypeOf<Query | undefined>();
3214+
expectTypeOf(reobserveResult.data).not.toMatchTypeOf<
32153215
UnmaskedQuery | undefined
32163216
>();
32173217

src/__tests__/client.ts

+8-8
Original file line numberDiff line numberDiff line change
@@ -1893,7 +1893,7 @@ describe("client", () => {
18931893
await expect(stream).toEmitMatchedValue({ data });
18941894

18951895
await expect(
1896-
obs.setOptions({ query, fetchPolicy: "standby" })
1896+
obs.reobserve({ query, fetchPolicy: "standby" })
18971897
// TODO: Update this behavior
18981898
).rejects.toThrow(new EmptyError());
18991899
// this write should be completely ignored by the standby query
@@ -1923,13 +1923,13 @@ describe("client", () => {
19231923
await expect(stream).toEmitMatchedValue({ data });
19241924

19251925
await expect(
1926-
obs.setOptions({ query, fetchPolicy: "standby" })
1926+
obs.reobserve({ query, fetchPolicy: "standby" })
19271927
// TODO: Update this behavior
19281928
).rejects.toThrow(new EmptyError());
19291929
// this write should be completely ignored by the standby query
19301930
client.writeQuery({ query, data: data2 });
19311931
setTimeout(() => {
1932-
void obs.setOptions({ query, fetchPolicy: "cache-first" });
1932+
void obs.reobserve({ query, fetchPolicy: "cache-first" });
19331933
}, 10);
19341934

19351935
await expect(stream).toEmitMatchedValue({ data: data2 });
@@ -3639,7 +3639,7 @@ describe("@connection", () => {
36393639
});
36403640
expect(fetchPolicyRecord).toEqual(["cache-first", "network-only"]);
36413641

3642-
const finalResult = await observable.setOptions({
3642+
const finalResult = await observable.reobserve({
36433643
// Allow delivery of loading:true result.
36443644
notifyOnNetworkStatusChange: true,
36453645
// Force a network request in addition to loading:true cache result.
@@ -5454,7 +5454,7 @@ describe("custom document transforms", () => {
54545454
});
54555455
});
54565456

5457-
it("re-runs custom document transforms when calling `setOptions`", async () => {
5457+
it("re-runs custom document transforms when calling `reobserve`", async () => {
54585458
const query = gql`
54595459
query TestQuery($id: ID!) {
54605460
product(id: $id) {
@@ -5550,7 +5550,7 @@ describe("custom document transforms", () => {
55505550

55515551
enabled = false;
55525552

5553-
const { data } = await observable.setOptions({ variables: { id: 2 } });
5553+
const { data } = await observable.reobserve({ variables: { id: 2 } });
55545554

55555555
expect(document!).toMatchDocument(disabledQuery);
55565556
expect(observable.options.query).toMatchDocument(query);
@@ -5570,7 +5570,7 @@ describe("custom document transforms", () => {
55705570
});
55715571
});
55725572

5573-
it("runs custom document transforms when passing a new query to `setOptions`", async () => {
5573+
it("runs custom document transforms when passing a new query to `reobserve`", async () => {
55745574
const query = gql`
55755575
query TestQuery($id: ID!) {
55765576
product(id: $id) {
@@ -5673,7 +5673,7 @@ describe("custom document transforms", () => {
56735673
expect(observable.query).toMatchDocument(transformedQuery);
56745674
});
56755675

5676-
const { data } = await observable.setOptions({ query: updatedQuery });
5676+
const { data } = await observable.reobserve({ query: updatedQuery });
56775677

56785678
expect(document!).toMatchDocument(transformedUpdatedQuery);
56795679
expect(observable.options.query).toMatchDocument(updatedQuery);

src/__tests__/dataMasking.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -1722,7 +1722,7 @@ describe("client.watchQuery", () => {
17221722
);
17231723
});
17241724

1725-
test("masks result of setOptions", async () => {
1725+
test("masks result of reobserve", async () => {
17261726
type UserFieldsFragment = {
17271727
age: number;
17281728
} & { " $fragmentName"?: "UserFieldsFragment" };
@@ -1803,7 +1803,7 @@ describe("client.watchQuery", () => {
18031803
});
18041804
}
18051805

1806-
const result = await observable.setOptions({ variables: { id: 2 } });
1806+
const result = await observable.reobserve({ variables: { id: 2 } });
18071807

18081808
expect(result?.data).toEqual({
18091809
user: {

src/core/ObservableQuery.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -802,7 +802,7 @@ Did you mean to call refetch(variables) instead of refetch({ variables })?`,
802802
// requests to be triggered only if the cache result is incomplete. To
803803
// that end, the options.nextFetchPolicy option provides an easy way to
804804
// update options.fetchPolicy after the initial network request, without
805-
// having to call observableQuery.setOptions.
805+
// having to call observableQuery.reobserve.
806806
options.fetchPolicy = options.nextFetchPolicy(fetchPolicy, {
807807
reason,
808808
options,
@@ -1166,7 +1166,7 @@ export function reobserveCacheFirst<TData, TVars extends OperationVariables>(
11661166
const { fetchPolicy, nextFetchPolicy } = obsQuery.options;
11671167

11681168
if (fetchPolicy === "cache-and-network" || fetchPolicy === "network-only") {
1169-
return obsQuery.setOptions({
1169+
return obsQuery.reobserve({
11701170
fetchPolicy: "cache-first",
11711171
// Use a temporary nextFetchPolicy function that replaces itself with the
11721172
// previous nextFetchPolicy value and returns the original fetchPolicy.
@@ -1189,7 +1189,7 @@ export function reobserveCacheFirst<TData, TVars extends OperationVariables>(
11891189
});
11901190
}
11911191

1192-
return obsQuery.rerun();
1192+
return obsQuery.reobserve();
11931193
}
11941194

11951195
export function logMissingFieldErrors(

src/core/__tests__/ApolloClient/general.test.ts

+4-4
Original file line numberDiff line numberDiff line change
@@ -546,7 +546,7 @@ describe("ApolloClient", () => {
546546

547547
// Kick off another request while the other is still pending
548548
await wait(10);
549-
void observableQuery.setOptions({ variables: { offset: 20 } });
549+
void observableQuery.reobserve({ variables: { offset: 20 } });
550550

551551
expect(onRequestSubscribe).toHaveBeenCalledTimes(2);
552552

@@ -618,7 +618,7 @@ describe("ApolloClient", () => {
618618

619619
// Kick off another request while the other is still pending
620620
await wait(10);
621-
void observableQuery.setOptions({ variables: { id: 2 } });
621+
void observableQuery.reobserve({ variables: { id: 2 } });
622622

623623
await expect(stream).toEmitApolloQueryResult({
624624
data: {
@@ -3114,7 +3114,7 @@ describe("ApolloClient", () => {
31143114
// fetchQueryByPolicy, but it should just read from cache and not
31153115
// update "queryInfo.lastRequestId". For more information, see
31163116
// https://github.com/apollographql/apollo-client/pull/7956#issue-610298427
3117-
await observable.setOptions({
3117+
await observable.reobserve({
31183118
...queryOptions,
31193119
fetchPolicy: "cache-first",
31203120
});
@@ -6345,7 +6345,7 @@ describe("ApolloClient", () => {
63456345

63466346
onQueryUpdated(obsQuery) {
63476347
expect(obsQuery.options.query).toBe(query);
6348-
return obsQuery.setOptions({
6348+
return obsQuery.reobserve({
63496349
fetchPolicy: "network-only",
63506350
context: {
63516351
...obsQuery.options.context,

src/core/__tests__/ObservableQuery.ts

+18-18
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ describe("ObservableQuery", () => {
9090
]);
9191
const wrappedError = new CombinedGraphQLErrors([error]);
9292

93-
describe("setOptions", () => {
93+
describe("reobserve", () => {
9494
describe("to change pollInterval", () => {
9595
it("starts polling if goes from 0 -> something", async () => {
9696
const client = new ApolloClient({
@@ -126,7 +126,7 @@ describe("ObservableQuery", () => {
126126
partial: false,
127127
});
128128

129-
await observable.setOptions({ query, pollInterval: 10 });
129+
await observable.reobserve({ query, pollInterval: 10 });
130130

131131
await expect(stream).toEmitApolloQueryResult({
132132
data: dataTwo,
@@ -174,7 +174,7 @@ describe("ObservableQuery", () => {
174174
partial: false,
175175
});
176176

177-
await observable.setOptions({ query, pollInterval: 0 });
177+
await observable.reobserve({ query, pollInterval: 0 });
178178

179179
await expect(stream).not.toEmitAnything();
180180
});
@@ -214,7 +214,7 @@ describe("ObservableQuery", () => {
214214
partial: false,
215215
});
216216

217-
await observable.setOptions({ query, pollInterval: 10 });
217+
await observable.reobserve({ query, pollInterval: 10 });
218218

219219
await expect(stream).toEmitApolloQueryResult({
220220
data: dataTwo,
@@ -413,7 +413,7 @@ describe("ObservableQuery", () => {
413413
partial: false,
414414
});
415415

416-
await observable.setOptions({
416+
await observable.reobserve({
417417
variables: variables2,
418418
notifyOnNetworkStatusChange: true,
419419
});
@@ -433,7 +433,7 @@ describe("ObservableQuery", () => {
433433
});
434434

435435
// go back to first set of variables
436-
const current = await observable.setOptions({ variables });
436+
const current = await observable.reobserve({ variables });
437437
expect(current).toEqualApolloQueryResult({
438438
data,
439439
loading: false,
@@ -533,7 +533,7 @@ describe("ObservableQuery", () => {
533533
partial: false,
534534
});
535535

536-
await observable.setOptions({ fetchPolicy: "network-only" });
536+
await observable.reobserve({ fetchPolicy: "network-only" });
537537

538538
await expect(stream).toEmitApolloQueryResult({
539539
data: dataTwo,
@@ -591,7 +591,7 @@ describe("ObservableQuery", () => {
591591

592592
expect(timesFired).toBe(1);
593593

594-
await observable.setOptions({ fetchPolicy: "cache-only" });
594+
await observable.reobserve({ fetchPolicy: "cache-only" });
595595
await client.resetStore();
596596

597597
await expect(stream).toEmitApolloQueryResult({
@@ -654,7 +654,7 @@ describe("ObservableQuery", () => {
654654
});
655655
expect(timesFired).toBe(0);
656656

657-
await observable.setOptions({ fetchPolicy: "cache-first" });
657+
await observable.reobserve({ fetchPolicy: "cache-first" });
658658

659659
await expect(stream).toEmitApolloQueryResult({
660660
data,
@@ -714,7 +714,7 @@ describe("ObservableQuery", () => {
714714
expect(timesFired).toBe(1);
715715

716716
await expect(
717-
observable.setOptions({ query, fetchPolicy: "standby" })
717+
observable.reobserve({ query, fetchPolicy: "standby" })
718718
).rejects.toThrow(new EmptyError());
719719

720720
// make sure the query didn't get fired again.
@@ -774,7 +774,7 @@ describe("ObservableQuery", () => {
774774
expect(timesFired).toBe(1);
775775

776776
await expect(
777-
observable.setOptions({ query, fetchPolicy: "standby" })
777+
observable.reobserve({ query, fetchPolicy: "standby" })
778778
// TODO: Dertermine how we want to handle this. We likely should swallow
779779
// the error since standby currently does not emit a value but completes
780780
// instead.
@@ -809,7 +809,7 @@ describe("ObservableQuery", () => {
809809
partial: false,
810810
});
811811

812-
const res = await observable.setOptions({
812+
const res = await observable.reobserve({
813813
fetchPolicy: "cache-and-network",
814814
});
815815

@@ -1711,7 +1711,7 @@ describe("ObservableQuery", () => {
17111711
expect(observable.options.fetchPolicy).toBe("cache-first");
17121712

17131713
{
1714-
const result = await observable.setOptions({ variables: variables1 });
1714+
const result = await observable.reobserve({ variables: variables1 });
17151715

17161716
expect(result).toEqualApolloQueryResult({
17171717
data,
@@ -1739,7 +1739,7 @@ describe("ObservableQuery", () => {
17391739
expect(observable.options.fetchPolicy).toBe("cache-first");
17401740

17411741
{
1742-
const result = await observable.setOptions({ variables: variables2 });
1742+
const result = await observable.reobserve({ variables: variables2 });
17431743

17441744
expect(result).toEqualApolloQueryResult({
17451745
data: data2,
@@ -3481,7 +3481,7 @@ describe("ObservableQuery", () => {
34813481
expect(observable.query).toBe(result);
34823482
});
34833483

3484-
it("is updated with transformed query when `setOptions` changes the query", async () => {
3484+
it("is updated with transformed query when `reobserve` changes the query", async () => {
34853485
const query = gql`
34863486
query {
34873487
currentUser {
@@ -3514,7 +3514,7 @@ describe("ObservableQuery", () => {
35143514
}
35153515
`);
35163516

3517-
await observable.setOptions({ query: updatedQuery });
3517+
await observable.reobserve({ query: updatedQuery });
35183518

35193519
expect(observable.query).toMatchDocument(gql`
35203520
query {
@@ -3897,9 +3897,9 @@ test("handles changing variables in rapid succession before other request is com
38973897
});
38983898
});
38993899

3900-
void observable.setOptions({ variables: { department: "HR" } });
3900+
void observable.reobserve({ variables: { department: "HR" } });
39013901
await wait(10);
3902-
void observable.setOptions({ variables: { department: null } });
3902+
void observable.reobserve({ variables: { department: null } });
39033903

39043904
// Wait for request to finish
39053905
await wait(50);

src/core/__tests__/fetchPolicies.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -965,7 +965,7 @@ describe("nextFetchPolicy", () => {
965965
expect(observable.options.fetchPolicy).toBe("cache-first");
966966

967967
{
968-
const result = await observable.setOptions({
968+
const result = await observable.reobserve({
969969
variables: {
970970
refetching: false,
971971
},
@@ -1115,7 +1115,7 @@ describe("nextFetchPolicy", () => {
11151115
expect(observable.options.fetchPolicy).toBe("cache-first");
11161116

11171117
{
1118-
const result = await observable.setOptions({
1118+
const result = await observable.reobserve({
11191119
variables: {
11201120
refetching: false,
11211121
},
@@ -1285,7 +1285,7 @@ describe("nextFetchPolicy", () => {
12851285
expect(observable.options.fetchPolicy).toBe("cache-first");
12861286

12871287
{
1288-
const result = await observable.setOptions({
1288+
const result = await observable.reobserve({
12891289
variables: {
12901290
refetching: false,
12911291
},

src/react/hooks/__tests__/useMutation.test.tsx

+1-1
Original file line numberDiff line numberDiff line change
@@ -1959,7 +1959,7 @@ describe("useMutation Hook", () => {
19591959
void createTodo({
19601960
variables,
19611961
async onQueryUpdated(obsQuery, diff) {
1962-
const result = await obsQuery.rerun();
1962+
const result = await obsQuery.reobserve();
19631963
finishedReobserving = true;
19641964
resolveOnUpdate({ obsQuery, diff, result });
19651965
return result;

src/react/hooks/__tests__/useQuery.test.tsx

+4-4
Original file line numberDiff line numberDiff line change
@@ -1755,7 +1755,7 @@ describe("useQuery Hook", () => {
17551755
checkObservableQueries(1);
17561756

17571757
await expect(
1758-
getCurrentSnapshot().observable.rerun()
1758+
getCurrentSnapshot().observable.reobserve()
17591759
).resolves.toEqualApolloQueryResult({
17601760
data: { linkCount: 2 },
17611761
loading: false,
@@ -4926,7 +4926,7 @@ describe("useQuery Hook", () => {
49264926
// Intentionally use rerun here as opposed to refetch to
49274927
// ensure we check against reported cache results with cache-first
49284928
// and notifyOnNetworkStatusChange
4929-
void useQueryResult.observable.rerun();
4929+
void useQueryResult.observable.reobserve();
49304930
}}
49314931
>
49324932
Reload 1st query
@@ -7297,7 +7297,7 @@ describe("useQuery Hook", () => {
72977297

72987298
const reasons: string[] = [];
72997299

7300-
const result = await getCurrentSnapshot().observable.setOptions({
7300+
const result = await getCurrentSnapshot().observable.reobserve({
73017301
variables: {
73027302
newVar: true,
73037303
},
@@ -8156,7 +8156,7 @@ describe("useQuery Hook", () => {
81568156
variables: {},
81578157
});
81588158

8159-
const result = await getCurrentSnapshot().observable.rerun();
8159+
const result = await getCurrentSnapshot().observable.reobserve();
81608160

81618161
expect(result).toEqualApolloQueryResult({
81628162
data: { a: "aaa", b: 2 },

0 commit comments

Comments
 (0)