@apollo/client 4.1.0-alpha.3 → 4.1.0-alpha.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +38 -0
- package/__cjs/cache/core/types/common.cjs.map +1 -1
- package/__cjs/cache/core/types/common.d.cts +1 -1
- package/__cjs/cache/inmemory/fragmentRegistry.cjs +1 -1
- package/__cjs/cache/inmemory/fragmentRegistry.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +7 -3
- package/__cjs/core/ObservableQuery.cjs +8 -4
- package/__cjs/core/ObservableQuery.cjs.map +1 -1
- package/__cjs/core/ObservableQuery.d.cts +2 -2
- package/__cjs/core/QueryManager.cjs +1 -1
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/dev/setErrorMessageHandler.cjs.map +1 -1
- package/__cjs/dev/setErrorMessageHandler.d.cts +1 -1
- package/__cjs/link/schema/index.cjs +1 -1
- package/__cjs/link/schema/index.cjs.map +1 -1
- package/__cjs/link/schema/index.d.cts +1 -1
- package/__cjs/link/subscriptions/index.cjs +2 -1
- package/__cjs/link/subscriptions/index.cjs.map +1 -1
- package/__cjs/masking/maskDefinition.cjs +1 -1
- package/__cjs/masking/maskDefinition.cjs.map +1 -1
- package/__cjs/masking/types.d.cts +2 -1
- package/__cjs/react/hooks/internal/index.cjs +3 -1
- package/__cjs/react/hooks/internal/index.cjs.map +1 -1
- package/__cjs/react/hooks/internal/index.d.cts +1 -0
- package/__cjs/react/hooks/internal/useDeepMemo.cjs +2 -0
- package/__cjs/react/hooks/internal/useDeepMemo.cjs.map +1 -1
- package/__cjs/react/hooks/internal/useRenderGuard.cjs +1 -1
- package/__cjs/react/hooks/internal/useRenderGuard.cjs.map +1 -1
- package/__cjs/react/hooks/internal/useSuspenseHookCacheKey.cjs +28 -0
- package/__cjs/react/hooks/internal/useSuspenseHookCacheKey.cjs.map +1 -0
- package/__cjs/react/hooks/internal/useSuspenseHookCacheKey.d.cts +11 -0
- package/__cjs/react/hooks/useBackgroundQuery.cjs +3 -11
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useFragment.cjs +1 -3
- package/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.cjs +2 -0
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +3 -1
- package/__cjs/react/hooks/useQuery.cjs +1 -4
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +1 -1
- package/__cjs/react/hooks/useQueryRefHandlers.cjs +1 -3
- package/__cjs/react/hooks/useQueryRefHandlers.cjs.map +1 -1
- package/__cjs/react/hooks/useReactiveVar.cjs +2 -1
- package/__cjs/react/hooks/useReactiveVar.cjs.map +1 -1
- package/__cjs/react/hooks/useReactiveVar.d.cts +2 -1
- package/__cjs/react/hooks/useReadQuery.cjs +1 -3
- package/__cjs/react/hooks/useReadQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useReadQuery.d.cts +1 -1
- package/__cjs/react/hooks/useSubscription.cjs +1 -1
- package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseFragment.cjs +3 -4
- package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.cjs +6 -12
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +1 -1
- package/__cjs/react/hooks/useSyncExternalStore.cjs +1 -1
- package/__cjs/react/hooks/useSyncExternalStore.cjs.map +1 -1
- package/__cjs/react/internal/cache/QueryReference.cjs +1 -1
- package/__cjs/react/internal/cache/QueryReference.cjs.map +1 -1
- package/__cjs/react/internal/cache/QueryReference.d.cts +4 -0
- package/__cjs/react/ssr/useSSRQuery.cjs +1 -0
- package/__cjs/react/ssr/useSSRQuery.cjs.map +1 -1
- package/__cjs/react/types/types.documentation.d.cts +4 -16
- package/__cjs/testing/core/mocking/mockLink.cjs +2 -2
- package/__cjs/testing/core/mocking/mockLink.cjs.map +1 -1
- package/__cjs/testing/core/mocking/mockLink.d.cts +3 -1
- package/__cjs/utilities/internal/getMemoryInternals.cjs.map +1 -1
- package/__cjs/utilities/internal/types/DocumentationTypes.d.cts +1 -1
- package/__cjs/version.cjs +1 -1
- package/cache/core/types/common.d.ts +1 -1
- package/cache/core/types/common.js.map +1 -1
- package/cache/inmemory/fragmentRegistry.js +1 -1
- package/cache/inmemory/fragmentRegistry.js.map +1 -1
- package/core/ApolloClient.d.ts +7 -3
- package/core/ObservableQuery.d.ts +2 -2
- package/core/ObservableQuery.js +8 -4
- package/core/ObservableQuery.js.map +1 -1
- package/core/QueryManager.js +1 -1
- package/core/QueryManager.js.map +1 -1
- package/dev/setErrorMessageHandler.d.ts +1 -1
- package/dev/setErrorMessageHandler.js.map +1 -1
- package/link/schema/index.d.ts +1 -1
- package/link/schema/index.js +1 -1
- package/link/schema/index.js.map +1 -1
- package/link/subscriptions/index.js +2 -1
- package/link/subscriptions/index.js.map +1 -1
- package/masking/internal/types.js.map +1 -1
- package/masking/maskDefinition.js +1 -1
- package/masking/maskDefinition.js.map +1 -1
- package/masking/types.d.ts +2 -1
- package/masking/types.js.map +1 -1
- package/package.json +1 -1
- package/react/hooks/internal/index.d.ts +1 -0
- package/react/hooks/internal/index.js +1 -0
- package/react/hooks/internal/index.js.map +1 -1
- package/react/hooks/internal/useDeepMemo.js +2 -0
- package/react/hooks/internal/useDeepMemo.js.map +1 -1
- package/react/hooks/internal/useRenderGuard.js +1 -1
- package/react/hooks/internal/useRenderGuard.js.map +1 -1
- package/react/hooks/internal/useSuspenseHookCacheKey.d.ts +11 -0
- package/react/hooks/internal/useSuspenseHookCacheKey.js +24 -0
- package/react/hooks/internal/useSuspenseHookCacheKey.js.map +1 -0
- package/react/hooks/useBackgroundQuery.js +4 -12
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.js +1 -3
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +1 -1
- package/react/hooks/useLazyQuery.js +2 -0
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +3 -1
- package/react/hooks/useQuery.d.ts +1 -1
- package/react/hooks/useQuery.js +1 -4
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.js +1 -3
- package/react/hooks/useQueryRefHandlers.js.map +1 -1
- package/react/hooks/useReactiveVar.d.ts +2 -1
- package/react/hooks/useReactiveVar.js +2 -1
- package/react/hooks/useReactiveVar.js.map +1 -1
- package/react/hooks/useReadQuery.d.ts +1 -1
- package/react/hooks/useReadQuery.js +1 -3
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.js +1 -1
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseFragment.js +3 -4
- package/react/hooks/useSuspenseFragment.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +1 -1
- package/react/hooks/useSuspenseQuery.js +7 -13
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks/useSyncExternalStore.js +1 -1
- package/react/hooks/useSyncExternalStore.js.map +1 -1
- package/react/hooks-compiled/internal/index.d.ts +1 -0
- package/react/hooks-compiled/internal/index.js +1 -0
- package/react/hooks-compiled/internal/index.js.map +1 -1
- package/react/hooks-compiled/internal/useDeepMemo.js +2 -0
- package/react/hooks-compiled/internal/useDeepMemo.js.map +1 -1
- package/react/hooks-compiled/internal/useRenderGuard.js +1 -1
- package/react/hooks-compiled/internal/useRenderGuard.js.map +1 -1
- package/react/hooks-compiled/internal/useSuspenseHookCacheKey.d.ts +11 -0
- package/react/hooks-compiled/internal/useSuspenseHookCacheKey.js +71 -0
- package/react/hooks-compiled/internal/useSuspenseHookCacheKey.js.map +1 -0
- package/react/hooks-compiled/useBackgroundQuery.js +6 -14
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useFragment.js +14 -18
- package/react/hooks-compiled/useFragment.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +1 -1
- package/react/hooks-compiled/useLazyQuery.js +2 -0
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLoadableQuery.js +69 -75
- package/react/hooks-compiled/useMutation.d.ts +3 -1
- package/react/hooks-compiled/useMutation.js +0 -12
- package/react/hooks-compiled/useMutation.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +1 -1
- package/react/hooks-compiled/useQuery.js +44 -56
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useQueryRefHandlers.js +1 -5
- package/react/hooks-compiled/useQueryRefHandlers.js.map +1 -1
- package/react/hooks-compiled/useReactiveVar.d.ts +2 -1
- package/react/hooks-compiled/useReactiveVar.js +2 -1
- package/react/hooks-compiled/useReactiveVar.js.map +1 -1
- package/react/hooks-compiled/useReadQuery.d.ts +1 -1
- package/react/hooks-compiled/useReadQuery.js +77 -14
- package/react/hooks-compiled/useReadQuery.js.map +1 -1
- package/react/hooks-compiled/useSubscription.js +237 -93
- package/react/hooks-compiled/useSubscription.js.map +1 -1
- package/react/hooks-compiled/useSuspenseFragment.js +3 -4
- package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
- package/react/hooks-compiled/useSuspenseQuery.d.ts +1 -1
- package/react/hooks-compiled/useSuspenseQuery.js +9 -19
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useSyncExternalStore.js +1 -1
- package/react/hooks-compiled/useSyncExternalStore.js.map +1 -1
- package/react/index.compiled.d.ts +1 -1
- package/react/index.compiled.js +1 -1
- package/react/index.compiled.js.map +1 -1
- package/react/internal/cache/QueryReference.d.ts +4 -0
- package/react/internal/cache/QueryReference.js +1 -1
- package/react/internal/cache/QueryReference.js.map +1 -1
- package/react/ssr/useSSRQuery.js +1 -0
- package/react/ssr/useSSRQuery.js.map +1 -1
- package/react/types/types.documentation.d.ts +4 -16
- package/react/types/types.documentation.js.map +1 -1
- package/testing/core/mocking/mockLink.d.ts +3 -1
- package/testing/core/mocking/mockLink.js +2 -2
- package/testing/core/mocking/mockLink.js.map +1 -1
- package/utilities/internal/getMemoryInternals.js.map +1 -1
- package/utilities/internal/globals/global.js +2 -2
- package/utilities/internal/globals/global.js.map +1 -1
- package/utilities/internal/types/DocumentationTypes.d.ts +1 -1
- package/version.js +1 -1
|
@@ -8,7 +8,7 @@ import { useDeepMemo, useRenderGuard } from "./internal/index.js";
|
|
|
8
8
|
import { validateSuspenseHookOptions } from "./internal/validateSuspenseHookOptions.js";
|
|
9
9
|
import { useApolloClient } from "./useApolloClient.js";
|
|
10
10
|
export function useLoadableQuery(query, t0) {
|
|
11
|
-
const $ = _c(
|
|
11
|
+
const $ = _c(35);
|
|
12
12
|
let t1;
|
|
13
13
|
|
|
14
14
|
if ($[0] !== t0) {
|
|
@@ -65,67 +65,63 @@ export function useLoadableQuery(query, t0) {
|
|
|
65
65
|
const queryKey = t5;
|
|
66
66
|
const [queryRef, setQueryRef] = React.useState(null);
|
|
67
67
|
assertWrappedQueryRef(queryRef);
|
|
68
|
-
let
|
|
69
|
-
|
|
70
|
-
if ($[10] !== queryRef) {
|
|
71
|
-
|
|
68
|
+
let internalQueryRef;
|
|
69
|
+
|
|
70
|
+
if ($[10] !== queryRef || $[11] !== watchQueryOptions) {
|
|
71
|
+
internalQueryRef = queryRef && unwrapQueryRef(queryRef);
|
|
72
|
+
if (queryRef && internalQueryRef?.didChangeOptions(watchQueryOptions)) {
|
|
73
|
+
const promise = internalQueryRef.applyOptions(watchQueryOptions);
|
|
74
|
+
updateWrappedQueryRef(queryRef, promise);
|
|
75
|
+
}
|
|
72
76
|
$[10] = queryRef;
|
|
73
|
-
$[11] =
|
|
77
|
+
$[11] = watchQueryOptions;
|
|
78
|
+
$[12] = internalQueryRef;
|
|
74
79
|
} else {
|
|
75
|
-
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
const internalQueryRef = t6;
|
|
79
|
-
|
|
80
|
-
if (queryRef && internalQueryRef?.didChangeOptions(watchQueryOptions)) {
|
|
81
|
-
const promise = internalQueryRef.applyOptions(watchQueryOptions);
|
|
82
|
-
updateWrappedQueryRef(queryRef, promise);
|
|
80
|
+
internalQueryRef = $[12];
|
|
83
81
|
}
|
|
84
82
|
|
|
85
83
|
const calledDuringRender = useRenderGuard();
|
|
86
|
-
let
|
|
84
|
+
let t6;
|
|
87
85
|
|
|
88
|
-
if ($[
|
|
89
|
-
|
|
86
|
+
if ($[13] !== internalQueryRef) {
|
|
87
|
+
t6 = options_0 => {
|
|
90
88
|
if (!internalQueryRef) {
|
|
91
89
|
throw new Error("The query has not been loaded. Please load the query.");
|
|
92
90
|
}
|
|
93
|
-
|
|
94
91
|
const promise_0 = internalQueryRef.fetchMore(options_0);
|
|
95
92
|
setQueryRef(wrapQueryRef(internalQueryRef));
|
|
96
93
|
return promise_0;
|
|
97
94
|
};
|
|
98
|
-
$[
|
|
99
|
-
$[
|
|
95
|
+
$[13] = internalQueryRef;
|
|
96
|
+
$[14] = t6;
|
|
100
97
|
} else {
|
|
101
|
-
|
|
98
|
+
t6 = $[14];
|
|
102
99
|
}
|
|
103
100
|
|
|
104
|
-
const fetchMore =
|
|
105
|
-
let
|
|
101
|
+
const fetchMore = t6;
|
|
102
|
+
let t7;
|
|
106
103
|
|
|
107
|
-
if ($[
|
|
108
|
-
|
|
104
|
+
if ($[15] !== internalQueryRef) {
|
|
105
|
+
t7 = options_1 => {
|
|
109
106
|
if (!internalQueryRef) {
|
|
110
107
|
throw new Error("The query has not been loaded. Please load the query.");
|
|
111
108
|
}
|
|
112
|
-
|
|
113
109
|
const promise_1 = internalQueryRef.refetch(options_1);
|
|
114
110
|
setQueryRef(wrapQueryRef(internalQueryRef));
|
|
115
111
|
return promise_1;
|
|
116
112
|
};
|
|
117
|
-
$[
|
|
118
|
-
$[
|
|
113
|
+
$[15] = internalQueryRef;
|
|
114
|
+
$[16] = t7;
|
|
119
115
|
} else {
|
|
120
|
-
|
|
116
|
+
t7 = $[16];
|
|
121
117
|
}
|
|
122
118
|
|
|
123
|
-
const refetch =
|
|
124
|
-
let
|
|
119
|
+
const refetch = t7;
|
|
120
|
+
let t8;
|
|
125
121
|
|
|
126
|
-
if ($[
|
|
127
|
-
|
|
128
|
-
const args =
|
|
122
|
+
if ($[17] !== calledDuringRender || $[18] !== client || $[19] !== query || $[20] !== queryKey || $[21] !== suspenseCache || $[22] !== watchQueryOptions) {
|
|
123
|
+
t8 = (...t9) => {
|
|
124
|
+
const args = t9;
|
|
129
125
|
invariant(!calledDuringRender(), 31);
|
|
130
126
|
const [variables] = args;
|
|
131
127
|
const cacheKey = [query, canonicalStringify(variables), ...[].concat(queryKey)];
|
|
@@ -135,74 +131,74 @@ export function useLoadableQuery(query, t0) {
|
|
|
135
131
|
}));
|
|
136
132
|
setQueryRef(wrapQueryRef(queryRef_0));
|
|
137
133
|
};
|
|
138
|
-
$[
|
|
139
|
-
$[
|
|
140
|
-
$[
|
|
141
|
-
$[
|
|
142
|
-
$[
|
|
143
|
-
$[
|
|
144
|
-
$[
|
|
134
|
+
$[17] = calledDuringRender;
|
|
135
|
+
$[18] = client;
|
|
136
|
+
$[19] = query;
|
|
137
|
+
$[20] = queryKey;
|
|
138
|
+
$[21] = suspenseCache;
|
|
139
|
+
$[22] = watchQueryOptions;
|
|
140
|
+
$[23] = t8;
|
|
145
141
|
} else {
|
|
146
|
-
|
|
142
|
+
t8 = $[23];
|
|
147
143
|
}
|
|
148
144
|
|
|
149
|
-
const loadQuery =
|
|
150
|
-
let
|
|
145
|
+
const loadQuery = t8;
|
|
146
|
+
let t9;
|
|
151
147
|
|
|
152
|
-
if ($[
|
|
153
|
-
|
|
148
|
+
if ($[24] !== internalQueryRef) {
|
|
149
|
+
t9 = options_2 => {
|
|
154
150
|
invariant(internalQueryRef, 32);
|
|
155
151
|
return internalQueryRef.observable.subscribeToMore(options_2);
|
|
156
152
|
};
|
|
157
|
-
$[
|
|
158
|
-
$[
|
|
153
|
+
$[24] = internalQueryRef;
|
|
154
|
+
$[25] = t9;
|
|
159
155
|
} else {
|
|
160
|
-
|
|
156
|
+
t9 = $[25];
|
|
161
157
|
}
|
|
162
158
|
|
|
163
|
-
const subscribeToMore =
|
|
164
|
-
let
|
|
159
|
+
const subscribeToMore = t9;
|
|
160
|
+
let t10;
|
|
165
161
|
|
|
166
|
-
if ($[
|
|
167
|
-
|
|
162
|
+
if ($[26] === Symbol.for("react.memo_cache_sentinel")) {
|
|
163
|
+
t10 = () => {
|
|
168
164
|
setQueryRef(null);
|
|
169
165
|
};
|
|
170
|
-
$[
|
|
166
|
+
$[26] = t10;
|
|
171
167
|
} else {
|
|
172
|
-
|
|
168
|
+
t10 = $[26];
|
|
173
169
|
}
|
|
174
170
|
|
|
175
|
-
const reset =
|
|
176
|
-
let
|
|
171
|
+
const reset = t10;
|
|
172
|
+
let t11;
|
|
177
173
|
|
|
178
|
-
if ($[
|
|
179
|
-
|
|
174
|
+
if ($[27] !== fetchMore || $[28] !== refetch || $[29] !== subscribeToMore) {
|
|
175
|
+
t11 = {
|
|
180
176
|
fetchMore,
|
|
181
177
|
refetch,
|
|
182
178
|
reset,
|
|
183
179
|
subscribeToMore
|
|
184
180
|
};
|
|
185
|
-
$[
|
|
186
|
-
$[
|
|
187
|
-
$[
|
|
188
|
-
$[
|
|
181
|
+
$[27] = fetchMore;
|
|
182
|
+
$[28] = refetch;
|
|
183
|
+
$[29] = subscribeToMore;
|
|
184
|
+
$[30] = t11;
|
|
189
185
|
} else {
|
|
190
|
-
|
|
186
|
+
t11 = $[30];
|
|
191
187
|
}
|
|
192
188
|
|
|
193
|
-
let
|
|
189
|
+
let t12;
|
|
194
190
|
|
|
195
|
-
if ($[
|
|
196
|
-
|
|
197
|
-
$[
|
|
198
|
-
$[
|
|
199
|
-
$[
|
|
200
|
-
$[
|
|
191
|
+
if ($[31] !== loadQuery || $[32] !== queryRef || $[33] !== t11) {
|
|
192
|
+
t12 = [loadQuery, queryRef, t11];
|
|
193
|
+
$[31] = loadQuery;
|
|
194
|
+
$[32] = queryRef;
|
|
195
|
+
$[33] = t11;
|
|
196
|
+
$[34] = t12;
|
|
201
197
|
} else {
|
|
202
|
-
|
|
198
|
+
t12 = $[34];
|
|
203
199
|
}
|
|
204
200
|
|
|
205
|
-
return
|
|
201
|
+
return t12;
|
|
206
202
|
}
|
|
207
203
|
function useWatchQueryOptions(t0) {
|
|
208
204
|
const $ = _c(5);
|
|
@@ -224,11 +220,9 @@ function useWatchQueryOptions(t0) {
|
|
|
224
220
|
notifyOnNetworkStatusChange: false,
|
|
225
221
|
nextFetchPolicy: void 0
|
|
226
222
|
};
|
|
227
|
-
|
|
228
223
|
if (__DEV__) {
|
|
229
224
|
validateSuspenseHookOptions(watchQueryOptions);
|
|
230
225
|
}
|
|
231
|
-
|
|
232
226
|
return watchQueryOptions;
|
|
233
227
|
};t2 = [client, options, query];
|
|
234
228
|
$[0] = client;
|
|
@@ -143,7 +143,9 @@ export declare namespace useMutation {
|
|
|
143
143
|
}
|
|
144
144
|
interface Result<TData = unknown> {
|
|
145
145
|
/**
|
|
146
|
-
* The data returned from your mutation. Can be `undefined` if `
|
|
146
|
+
* The data returned from your mutation. Can be `undefined` if the `errorPolicy`
|
|
147
|
+
* is `all` or `ignore` and the server returns a GraphQL response with `errors`
|
|
148
|
+
* but not `data` or a network error is returned.
|
|
147
149
|
*/
|
|
148
150
|
data: MaybeMasked<TData> | null | undefined;
|
|
149
151
|
/**
|
|
@@ -119,7 +119,6 @@ export function useMutation(mutation, options) {
|
|
|
119
119
|
};
|
|
120
120
|
const client_0 = executeOptions.client || ref.current.client;
|
|
121
121
|
const context = typeof executeOptions.context === "function" ? executeOptions.context(options_0?.context) : executeOptions.context;
|
|
122
|
-
|
|
123
122
|
if (!ref.current.result.loading && ref.current.isMounted) {
|
|
124
123
|
setResult(ref.current.result = {
|
|
125
124
|
loading: true,
|
|
@@ -129,7 +128,6 @@ export function useMutation(mutation, options) {
|
|
|
129
128
|
client: client_0
|
|
130
129
|
});
|
|
131
130
|
}
|
|
132
|
-
|
|
133
131
|
const mutationId = ref.current.mutationId = ref.current.mutationId + 1;
|
|
134
132
|
const clientOptions = mergeOptions(baseOptions, {
|
|
135
133
|
...executeOptions,
|
|
@@ -142,11 +140,9 @@ export function useMutation(mutation, options) {
|
|
|
142
140
|
error
|
|
143
141
|
} = response;
|
|
144
142
|
const onError = executeOptions.onError || ref.current.options?.onError;
|
|
145
|
-
|
|
146
143
|
if (error && onError) {
|
|
147
144
|
onError(error, clientOptions);
|
|
148
145
|
}
|
|
149
|
-
|
|
150
146
|
if (mutationId === ref.current.mutationId) {
|
|
151
147
|
const result_0 = {
|
|
152
148
|
called: true,
|
|
@@ -155,18 +151,14 @@ export function useMutation(mutation, options) {
|
|
|
155
151
|
error,
|
|
156
152
|
client: client_0
|
|
157
153
|
};
|
|
158
|
-
|
|
159
154
|
if (ref.current.isMounted && !equal(ref.current.result, result_0)) {
|
|
160
155
|
setResult(ref.current.result = result_0);
|
|
161
156
|
}
|
|
162
157
|
}
|
|
163
|
-
|
|
164
158
|
const onCompleted = executeOptions.onCompleted || ref.current.options?.onCompleted;
|
|
165
|
-
|
|
166
159
|
if (!error) {
|
|
167
160
|
onCompleted?.(response.data, clientOptions);
|
|
168
161
|
}
|
|
169
|
-
|
|
170
162
|
return response;
|
|
171
163
|
}, error_0 => {
|
|
172
164
|
if (mutationId === ref.current.mutationId && ref.current.isMounted) {
|
|
@@ -177,18 +169,14 @@ export function useMutation(mutation, options) {
|
|
|
177
169
|
called: true,
|
|
178
170
|
client: client_0
|
|
179
171
|
};
|
|
180
|
-
|
|
181
172
|
if (!equal(ref.current.result, result_1)) {
|
|
182
173
|
setResult(ref.current.result = result_1);
|
|
183
174
|
}
|
|
184
175
|
}
|
|
185
|
-
|
|
186
176
|
const onError_0 = executeOptions.onError || ref.current.options?.onError;
|
|
187
|
-
|
|
188
177
|
if (onError_0) {
|
|
189
178
|
onError_0(error_0, clientOptions);
|
|
190
179
|
}
|
|
191
|
-
|
|
192
180
|
throw error_0;
|
|
193
181
|
}));
|
|
194
182
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutation.js","sources":["../../../src/react/hooks/useMutation.ts"],"sourcesContent":["import type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\nimport { equal } from \"@wry/equality\";\nimport * as React from \"react\";\n\nimport type {\n ApolloCache,\n ApolloClient,\n DefaultContext,\n DocumentNode,\n ErrorLike,\n ErrorPolicy,\n InternalRefetchQueriesInclude,\n MaybeMasked,\n MutationFetchPolicy,\n MutationQueryReducersMap,\n MutationUpdaterFunction,\n NormalizedExecutionResult,\n OnQueryUpdated,\n OperationVariables,\n Unmasked,\n} from \"@apollo/client\";\nimport type { IgnoreModifier } from \"@apollo/client/cache\";\nimport type { NoInfer, Prettify } from \"@apollo/client/utilities/internal\";\nimport {\n mergeOptions,\n preventUnhandledRejection,\n} from \"@apollo/client/utilities/internal\";\n\nimport { useIsomorphicLayoutEffect } from \"./internal/useIsomorphicLayoutEffect.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\n\ntype MakeRequiredVariablesOptional<\n TVariables extends OperationVariables,\n TConfiguredVariables extends Partial<TVariables>,\n> = Prettify<\n {\n [K in keyof TVariables as K extends keyof TConfiguredVariables ? K\n : never]?: TVariables[K];\n } & Omit<TVariables, keyof TConfiguredVariables>\n>;\n\nexport declare namespace useMutation {\n export interface Options<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TConfiguredVariables extends Partial<TVariables> = Partial<TVariables>,\n > {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#optimisticResponse:member} */\n optimisticResponse?:\n | Unmasked<NoInfer<TData>>\n | ((\n vars: TVariables,\n { IGNORE }: { IGNORE: IgnoreModifier }\n ) => Unmasked<NoInfer<TData>> | IgnoreModifier);\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#updateQueries:member} */\n updateQueries?: MutationQueryReducersMap<TData>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#refetchQueries:member} */\n refetchQueries?:\n | ((\n result: NormalizedExecutionResult<Unmasked<TData>>\n ) => InternalRefetchQueriesInclude)\n | InternalRefetchQueriesInclude;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#awaitRefetchQueries:member} */\n awaitRefetchQueries?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#update:member} */\n update?: MutationUpdaterFunction<TData, TVariables, TCache>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onQueryUpdated:member} */\n onQueryUpdated?: OnQueryUpdated<any>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: ErrorPolicy;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables?: Partial<TVariables> & TConfiguredVariables;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#context:member} */\n context?: DefaultContext;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#fetchPolicy:member} */\n fetchPolicy?: MutationFetchPolicy;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#keepRootFields:member} */\n keepRootFields?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#client:member} */\n client?: ApolloClient;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#notifyOnNetworkStatusChange:member} */\n notifyOnNetworkStatusChange?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onCompleted:member} */\n onCompleted?: (\n data: MaybeMasked<TData>,\n clientOptions?: Options<TData, TVariables, TCache>\n ) => void;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onError:member} */\n onError?: (\n error: ErrorLike,\n clientOptions?: Options<TData, TVariables, TCache>\n ) => void;\n }\n\n export interface Result<TData = unknown> {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: MaybeMasked<TData> | null | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error: ErrorLike | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#loading:member} */\n loading: boolean;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#called:member} */\n called: boolean;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#client:member} */\n client: ApolloClient;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#reset:member} */\n reset: () => void;\n }\n\n export type ResultTuple<\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n > = [\n mutate: MutationFunction<TData, TVariables, TCache>,\n result: Result<TData>,\n ];\n\n export type MutationFunction<\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n > = (\n ...[options]: {} extends TVariables ?\n [\n options?: MutationFunctionOptions<TData, TVariables, TCache> & {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables?: TVariables;\n },\n ]\n : [\n options: MutationFunctionOptions<TData, TVariables, TCache> & {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables: TVariables;\n },\n ]\n ) => Promise<ApolloClient.MutateResult<MaybeMasked<TData>>>;\n\n export type MutationFunctionOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n > = Options<TData, TVariables, TCache> & {\n /**\n * {@inheritDoc @apollo/client!MutationOptionsDocumentation#context:member}\n *\n * @remarks\n * When provided as a callback function, the function is called with the\n * value of `context` provided to the `useMutation` hook.\n */\n context?:\n | DefaultContext\n | ((hookContext: DefaultContext | undefined) => DefaultContext);\n };\n\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client/react!useMutation:function(1)} */\n export function useMutation<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: useMutation.Options<TData, TVariables>\n ): useMutation.ResultTuple<TData, TVariables>;\n }\n}\n\n/**\n * > Refer to the [Mutations](https://www.apollographql.com/docs/react/data/mutations/) section for a more in-depth overview of `useMutation`.\n *\n * @example\n *\n * ```jsx\n * import { gql, useMutation } from \"@apollo/client\";\n *\n * const ADD_TODO = gql`\n * mutation AddTodo($type: String!) {\n * addTodo(type: $type) {\n * id\n * type\n * }\n * }\n * `;\n *\n * function AddTodo() {\n * let input;\n * const [addTodo, { data }] = useMutation(ADD_TODO);\n *\n * return (\n * <div>\n * <form\n * onSubmit={(e) => {\n * e.preventDefault();\n * addTodo({ variables: { type: input.value } });\n * input.value = \"\";\n * }}\n * >\n * <input\n * ref={(node) => {\n * input = node;\n * }}\n * />\n * <button type=\"submit\">Add Todo</button>\n * </form>\n * </div>\n * );\n * }\n * ```\n *\n * @param mutation - A GraphQL mutation document parsed into an AST by `gql`.\n * @param options - Options to control how the mutation is executed.\n * @returns A tuple in the form of `[mutate, result]`\n */\nexport function useMutation<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TConfiguredVariables extends Partial<TVariables> = {},\n>(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: useMutation.Options<\n NoInfer<TData>,\n NoInfer<TVariables>,\n TCache,\n {\n [K in keyof TConfiguredVariables]: K extends keyof TVariables ?\n TConfiguredVariables[K]\n : never;\n }\n >\n): useMutation.ResultTuple<\n TData,\n MakeRequiredVariablesOptional<TVariables, TConfiguredVariables>,\n TCache\n> {\n const client = useApolloClient(options?.client);\n const [result, setResult] = React.useState<\n Omit<useMutation.Result<TData>, \"reset\">\n >(() => createInitialResult(client));\n\n const ref = React.useRef({\n result,\n mutationId: 0,\n isMounted: true,\n client,\n mutation,\n options,\n });\n\n useIsomorphicLayoutEffect(() => {\n Object.assign(ref.current, { client, options, mutation });\n });\n\n const execute = React.useCallback(\n (\n executeOptions: useMutation.MutationFunctionOptions<\n TData,\n TVariables,\n TCache\n > = {} as useMutation.MutationFunctionOptions<TData, TVariables, TCache>\n ) => {\n const { options, mutation } = ref.current;\n const baseOptions = { ...options, mutation };\n const client = executeOptions.client || ref.current.client;\n const context =\n typeof executeOptions.context === \"function\" ?\n executeOptions.context(options?.context)\n : executeOptions.context;\n\n if (!ref.current.result.loading && ref.current.isMounted) {\n setResult(\n (ref.current.result = {\n loading: true,\n error: undefined,\n data: undefined,\n called: true,\n client,\n })\n );\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(baseOptions, {\n ...executeOptions,\n context,\n } as any);\n\n return preventUnhandledRejection(\n client\n .mutate(\n clientOptions as ApolloClient.MutateOptions<\n TData,\n OperationVariables\n >\n )\n .then(\n (response) => {\n const { data, error } = response;\n\n const onError =\n executeOptions.onError || ref.current.options?.onError;\n\n if (error && onError) {\n onError(error, clientOptions);\n }\n\n if (mutationId === ref.current.mutationId) {\n const result = {\n called: true,\n loading: false,\n data,\n error,\n client,\n };\n\n if (\n ref.current.isMounted &&\n !equal(ref.current.result, result)\n ) {\n setResult((ref.current.result = result));\n }\n }\n\n const onCompleted =\n executeOptions.onCompleted || ref.current.options?.onCompleted;\n\n if (!error) {\n onCompleted?.(response.data!, clientOptions);\n }\n\n return response;\n },\n (error) => {\n if (\n mutationId === ref.current.mutationId &&\n ref.current.isMounted\n ) {\n const result = {\n loading: false,\n error,\n data: void 0,\n called: true,\n client,\n };\n\n if (!equal(ref.current.result, result)) {\n setResult((ref.current.result = result));\n }\n }\n\n const onError =\n executeOptions.onError || ref.current.options?.onError;\n\n if (onError) {\n onError(error, clientOptions);\n }\n\n throw error;\n }\n )\n );\n },\n []\n );\n\n const reset = React.useCallback(() => {\n if (ref.current.isMounted) {\n const result = createInitialResult(ref.current.client);\n Object.assign(ref.current, { mutationId: 0, result });\n setResult(result);\n }\n }, []);\n\n React.useEffect(() => {\n const current = ref.current;\n current.isMounted = true;\n\n return () => {\n current.isMounted = false;\n };\n }, []);\n\n return [execute as any, { reset, ...result }];\n}\n\nfunction createInitialResult(client: ApolloClient) {\n return {\n data: undefined,\n error: undefined,\n called: false,\n loading: false,\n client,\n };\n}\n"],"names":[],"mappings":"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"}
|
|
1
|
+
{"version":3,"file":"useMutation.js","sources":["../../../src/react/hooks/useMutation.ts"],"sourcesContent":["import type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\nimport { equal } from \"@wry/equality\";\nimport * as React from \"react\";\n\nimport type {\n ApolloCache,\n ApolloClient,\n DefaultContext,\n DocumentNode,\n ErrorLike,\n ErrorPolicy,\n InternalRefetchQueriesInclude,\n MaybeMasked,\n MutationFetchPolicy,\n MutationQueryReducersMap,\n MutationUpdaterFunction,\n NormalizedExecutionResult,\n OnQueryUpdated,\n OperationVariables,\n Unmasked,\n} from \"@apollo/client\";\nimport type { IgnoreModifier } from \"@apollo/client/cache\";\nimport type { NoInfer, Prettify } from \"@apollo/client/utilities/internal\";\nimport {\n mergeOptions,\n preventUnhandledRejection,\n} from \"@apollo/client/utilities/internal\";\n\nimport { useIsomorphicLayoutEffect } from \"./internal/useIsomorphicLayoutEffect.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\n\ntype MakeRequiredVariablesOptional<\n TVariables extends OperationVariables,\n TConfiguredVariables extends Partial<TVariables>,\n> = Prettify<\n {\n [K in keyof TVariables as K extends keyof TConfiguredVariables ? K\n : never]?: TVariables[K];\n } & Omit<TVariables, keyof TConfiguredVariables>\n>;\n\nexport declare namespace useMutation {\n export interface Options<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TConfiguredVariables extends Partial<TVariables> = Partial<TVariables>,\n > {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#optimisticResponse:member} */\n optimisticResponse?:\n | Unmasked<NoInfer<TData>>\n | ((\n vars: TVariables,\n { IGNORE }: { IGNORE: IgnoreModifier }\n ) => Unmasked<NoInfer<TData>> | IgnoreModifier);\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#updateQueries:member} */\n updateQueries?: MutationQueryReducersMap<TData>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#refetchQueries:member} */\n refetchQueries?:\n | ((\n result: NormalizedExecutionResult<Unmasked<TData>>\n ) => InternalRefetchQueriesInclude)\n | InternalRefetchQueriesInclude;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#awaitRefetchQueries:member} */\n awaitRefetchQueries?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#update:member} */\n update?: MutationUpdaterFunction<TData, TVariables, TCache>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onQueryUpdated:member} */\n onQueryUpdated?: OnQueryUpdated<any>;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#errorPolicy:member} */\n errorPolicy?: ErrorPolicy;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables?: Partial<TVariables> & TConfiguredVariables;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#context:member} */\n context?: DefaultContext;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#fetchPolicy:member} */\n fetchPolicy?: MutationFetchPolicy;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#keepRootFields:member} */\n keepRootFields?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#client:member} */\n client?: ApolloClient;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#notifyOnNetworkStatusChange:member} */\n notifyOnNetworkStatusChange?: boolean;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onCompleted:member} */\n onCompleted?: (\n data: MaybeMasked<TData>,\n clientOptions?: Options<TData, TVariables, TCache>\n ) => void;\n\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#onError:member} */\n onError?: (\n error: ErrorLike,\n clientOptions?: Options<TData, TVariables, TCache>\n ) => void;\n }\n\n export interface Result<TData = unknown> {\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#data:member} */\n data: MaybeMasked<TData> | null | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#error:member} */\n error: ErrorLike | undefined;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#loading:member} */\n loading: boolean;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#called:member} */\n called: boolean;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#client:member} */\n client: ApolloClient;\n\n /** {@inheritDoc @apollo/client!MutationResultDocumentation#reset:member} */\n reset: () => void;\n }\n\n export type ResultTuple<\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n > = [\n mutate: MutationFunction<TData, TVariables, TCache>,\n result: Result<TData>,\n ];\n\n export type MutationFunction<\n TData,\n TVariables extends OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n > = (\n ...[options]: {} extends TVariables ?\n [\n options?: MutationFunctionOptions<TData, TVariables, TCache> & {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables?: TVariables;\n },\n ]\n : [\n options: MutationFunctionOptions<TData, TVariables, TCache> & {\n /** {@inheritDoc @apollo/client!MutationOptionsDocumentation#variables:member} */\n variables: TVariables;\n },\n ]\n ) => Promise<ApolloClient.MutateResult<MaybeMasked<TData>>>;\n\n export type MutationFunctionOptions<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n > = Options<TData, TVariables, TCache> & {\n /**\n * {@inheritDoc @apollo/client!MutationOptionsDocumentation#context:member}\n *\n * @remarks\n * When provided as a callback function, the function is called with the\n * value of `context` provided to the `useMutation` hook.\n */\n context?:\n | DefaultContext\n | ((hookContext: DefaultContext | undefined) => DefaultContext);\n };\n\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client/react!useMutation:function(1)} */\n export function useMutation<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: useMutation.Options<TData, TVariables>\n ): useMutation.ResultTuple<TData, TVariables>;\n }\n}\n\n/**\n * > Refer to the [Mutations](https://www.apollographql.com/docs/react/data/mutations/) section for a more in-depth overview of `useMutation`.\n *\n * @example\n *\n * ```jsx\n * import { gql, useMutation } from \"@apollo/client\";\n *\n * const ADD_TODO = gql`\n * mutation AddTodo($type: String!) {\n * addTodo(type: $type) {\n * id\n * type\n * }\n * }\n * `;\n *\n * function AddTodo() {\n * let input;\n * const [addTodo, { data }] = useMutation(ADD_TODO);\n *\n * return (\n * <div>\n * <form\n * onSubmit={(e) => {\n * e.preventDefault();\n * addTodo({ variables: { type: input.value } });\n * input.value = \"\";\n * }}\n * >\n * <input\n * ref={(node) => {\n * input = node;\n * }}\n * />\n * <button type=\"submit\">Add Todo</button>\n * </form>\n * </div>\n * );\n * }\n * ```\n *\n * @param mutation - A GraphQL mutation document parsed into an AST by `gql`.\n * @param options - Options to control how the mutation is executed.\n * @returns A tuple in the form of `[mutate, result]`\n */\nexport function useMutation<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n TCache extends ApolloCache = ApolloCache,\n TConfiguredVariables extends Partial<TVariables> = {},\n>(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: useMutation.Options<\n NoInfer<TData>,\n NoInfer<TVariables>,\n TCache,\n {\n [K in keyof TConfiguredVariables]: K extends keyof TVariables ?\n TConfiguredVariables[K]\n : never;\n }\n >\n): useMutation.ResultTuple<\n TData,\n MakeRequiredVariablesOptional<TVariables, TConfiguredVariables>,\n TCache\n> {\n const client = useApolloClient(options?.client);\n const [result, setResult] = React.useState<\n Omit<useMutation.Result<TData>, \"reset\">\n >(() => createInitialResult(client));\n\n const ref = React.useRef({\n result,\n mutationId: 0,\n isMounted: true,\n client,\n mutation,\n options,\n });\n\n useIsomorphicLayoutEffect(() => {\n Object.assign(ref.current, { client, options, mutation });\n });\n\n const execute = React.useCallback(\n (\n executeOptions: useMutation.MutationFunctionOptions<\n TData,\n TVariables,\n TCache\n > = {} as useMutation.MutationFunctionOptions<TData, TVariables, TCache>\n ) => {\n const { options, mutation } = ref.current;\n const baseOptions = { ...options, mutation };\n const client = executeOptions.client || ref.current.client;\n const context =\n typeof executeOptions.context === \"function\" ?\n executeOptions.context(options?.context)\n : executeOptions.context;\n\n if (!ref.current.result.loading && ref.current.isMounted) {\n setResult(\n (ref.current.result = {\n loading: true,\n error: undefined,\n data: undefined,\n called: true,\n client,\n })\n );\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(baseOptions, {\n ...executeOptions,\n context,\n } as any);\n\n return preventUnhandledRejection(\n client\n .mutate(\n clientOptions as ApolloClient.MutateOptions<\n TData,\n OperationVariables\n >\n )\n .then(\n (response) => {\n const { data, error } = response;\n\n const onError =\n executeOptions.onError || ref.current.options?.onError;\n\n if (error && onError) {\n onError(error, clientOptions);\n }\n\n if (mutationId === ref.current.mutationId) {\n const result = {\n called: true,\n loading: false,\n data,\n error,\n client,\n };\n\n if (\n ref.current.isMounted &&\n !equal(ref.current.result, result)\n ) {\n setResult((ref.current.result = result));\n }\n }\n\n const onCompleted =\n executeOptions.onCompleted || ref.current.options?.onCompleted;\n\n if (!error) {\n onCompleted?.(response.data!, clientOptions);\n }\n\n return response;\n },\n (error) => {\n if (\n mutationId === ref.current.mutationId &&\n ref.current.isMounted\n ) {\n const result = {\n loading: false,\n error,\n data: void 0,\n called: true,\n client,\n };\n\n if (!equal(ref.current.result, result)) {\n setResult((ref.current.result = result));\n }\n }\n\n const onError =\n executeOptions.onError || ref.current.options?.onError;\n\n if (onError) {\n onError(error, clientOptions);\n }\n\n throw error;\n }\n )\n );\n },\n []\n );\n\n const reset = React.useCallback(() => {\n if (ref.current.isMounted) {\n const result = createInitialResult(ref.current.client);\n Object.assign(ref.current, { mutationId: 0, result });\n setResult(result);\n }\n }, []);\n\n React.useEffect(() => {\n const current = ref.current;\n current.isMounted = true;\n\n return () => {\n current.isMounted = false;\n };\n }, []);\n\n return [execute as any, { reset, ...result }];\n}\n\nfunction createInitialResult(client: ApolloClient) {\n return {\n data: undefined,\n error: undefined,\n called: false,\n loading: false,\n client,\n };\n}\n"],"names":[],"mappings":"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"}
|
|
@@ -142,7 +142,7 @@ export declare namespace useQuery {
|
|
|
142
142
|
*/
|
|
143
143
|
previousData?: MaybeMasked<TData>;
|
|
144
144
|
/**
|
|
145
|
-
* A single ErrorLike object describing the error that
|
|
145
|
+
* A single ErrorLike object describing the error that occurred during the latest
|
|
146
146
|
* query execution.
|
|
147
147
|
*
|
|
148
148
|
* For more information, see [Handling operation errors](https://www.apollographql.com/docs/react/data/error-handling/).
|
|
@@ -24,9 +24,7 @@ import { useSyncExternalStore } from "./useSyncExternalStore.js";
|
|
|
24
24
|
const lastWatchOptions = Symbol();
|
|
25
25
|
export function useQuery(query, ...[options]) {
|
|
26
26
|
"use no memo";
|
|
27
|
-
return wrapHook("useQuery",
|
|
28
|
-
// eslint-disable-next-line react-compiler/react-compiler
|
|
29
|
-
useQuery_, useApolloClient(typeof options === "object" ? options.client : undefined))(query, options);
|
|
27
|
+
return wrapHook("useQuery", useQuery_, useApolloClient(typeof options === "object" ? options.client : undefined))(query, options);
|
|
30
28
|
}
|
|
31
29
|
function useQuery_(query, t0) {
|
|
32
30
|
const $ = _c(38);
|
|
@@ -84,7 +82,6 @@ function useQuery_(query, t0) {
|
|
|
84
82
|
|
|
85
83
|
const createState = t3;
|
|
86
84
|
let [state, setState] = React.useState(createState);
|
|
87
|
-
|
|
88
85
|
if (client !== state.client || query !== state.query) {
|
|
89
86
|
const t4 = setState;
|
|
90
87
|
let t5;
|
|
@@ -100,7 +97,6 @@ function useQuery_(query, t0) {
|
|
|
100
97
|
|
|
101
98
|
t4(state = t5);
|
|
102
99
|
}
|
|
103
|
-
|
|
104
100
|
const {
|
|
105
101
|
observable: observable_0,
|
|
106
102
|
resultData
|
|
@@ -109,110 +105,107 @@ function useQuery_(query, t0) {
|
|
|
109
105
|
useResubscribeIfNecessary(resultData, observable_0, watchQueryOptions);
|
|
110
106
|
const result = useResult(observable_0, resultData, ssr);
|
|
111
107
|
let t4;
|
|
112
|
-
let t5;
|
|
113
108
|
|
|
114
109
|
if ($[11] !== observable_0) {
|
|
115
|
-
|
|
110
|
+
t4 = observable_0.refetch.bind(observable_0);
|
|
116
111
|
$[11] = observable_0;
|
|
117
|
-
$[12] =
|
|
112
|
+
$[12] = t4;
|
|
118
113
|
} else {
|
|
119
|
-
|
|
114
|
+
t4 = $[12];
|
|
120
115
|
}
|
|
121
116
|
|
|
122
|
-
let
|
|
117
|
+
let t5;
|
|
123
118
|
|
|
124
119
|
if ($[13] !== observable_0) {
|
|
125
|
-
|
|
120
|
+
t5 = observable_0.fetchMore.bind(observable_0);
|
|
126
121
|
$[13] = observable_0;
|
|
127
|
-
$[14] =
|
|
122
|
+
$[14] = t5;
|
|
128
123
|
} else {
|
|
129
|
-
|
|
124
|
+
t5 = $[14];
|
|
130
125
|
}
|
|
131
126
|
|
|
132
|
-
let
|
|
127
|
+
let t6;
|
|
133
128
|
|
|
134
129
|
if ($[15] !== observable_0) {
|
|
135
|
-
|
|
130
|
+
t6 = observable_0.updateQuery.bind(observable_0);
|
|
136
131
|
$[15] = observable_0;
|
|
137
|
-
$[16] =
|
|
132
|
+
$[16] = t6;
|
|
138
133
|
} else {
|
|
139
|
-
|
|
134
|
+
t6 = $[16];
|
|
140
135
|
}
|
|
141
136
|
|
|
142
|
-
let
|
|
137
|
+
let t7;
|
|
143
138
|
|
|
144
139
|
if ($[17] !== observable_0) {
|
|
145
|
-
|
|
140
|
+
t7 = observable_0.startPolling.bind(observable_0);
|
|
146
141
|
$[17] = observable_0;
|
|
147
|
-
$[18] =
|
|
142
|
+
$[18] = t7;
|
|
148
143
|
} else {
|
|
149
|
-
|
|
144
|
+
t7 = $[18];
|
|
150
145
|
}
|
|
151
146
|
|
|
152
|
-
let
|
|
147
|
+
let t8;
|
|
153
148
|
|
|
154
149
|
if ($[19] !== observable_0) {
|
|
155
|
-
|
|
150
|
+
t8 = observable_0.stopPolling.bind(observable_0);
|
|
156
151
|
$[19] = observable_0;
|
|
157
|
-
$[20] =
|
|
152
|
+
$[20] = t8;
|
|
158
153
|
} else {
|
|
159
|
-
|
|
154
|
+
t8 = $[20];
|
|
160
155
|
}
|
|
161
156
|
|
|
162
|
-
let
|
|
157
|
+
let t9;
|
|
163
158
|
|
|
164
159
|
if ($[21] !== observable_0) {
|
|
165
|
-
|
|
160
|
+
t9 = observable_0.subscribeToMore.bind(observable_0);
|
|
166
161
|
$[21] = observable_0;
|
|
167
|
-
$[22] =
|
|
162
|
+
$[22] = t9;
|
|
168
163
|
} else {
|
|
169
|
-
|
|
164
|
+
t9 = $[22];
|
|
170
165
|
}
|
|
171
166
|
|
|
172
|
-
let
|
|
167
|
+
let t10;
|
|
173
168
|
|
|
174
|
-
if ($[23] !==
|
|
175
|
-
|
|
176
|
-
refetch:
|
|
177
|
-
fetchMore:
|
|
178
|
-
updateQuery:
|
|
179
|
-
startPolling:
|
|
180
|
-
stopPolling:
|
|
181
|
-
subscribeToMore:
|
|
169
|
+
if ($[23] !== t4 || $[24] !== t5 || $[25] !== t6 || $[26] !== t7 || $[27] !== t8 || $[28] !== t9) {
|
|
170
|
+
t10 = {
|
|
171
|
+
refetch: t4,
|
|
172
|
+
fetchMore: t5,
|
|
173
|
+
updateQuery: t6,
|
|
174
|
+
startPolling: t7,
|
|
175
|
+
stopPolling: t8,
|
|
176
|
+
subscribeToMore: t9
|
|
182
177
|
};
|
|
183
|
-
$[23] =
|
|
178
|
+
$[23] = t4;
|
|
184
179
|
$[24] = t5;
|
|
185
180
|
$[25] = t6;
|
|
186
181
|
$[26] = t7;
|
|
187
182
|
$[27] = t8;
|
|
188
183
|
$[28] = t9;
|
|
189
|
-
$[29] =
|
|
184
|
+
$[29] = t10;
|
|
190
185
|
} else {
|
|
191
|
-
|
|
186
|
+
t10 = $[29];
|
|
192
187
|
}
|
|
193
188
|
|
|
194
|
-
|
|
195
|
-
const obsQueryFields = t4;
|
|
189
|
+
const obsQueryFields = t10;
|
|
196
190
|
const previousData = resultData.previousData;
|
|
197
|
-
let t12;
|
|
198
191
|
let rest;
|
|
199
192
|
|
|
200
193
|
if ($[30] !== result) {
|
|
201
194
|
const {
|
|
202
195
|
partial,
|
|
203
|
-
...
|
|
196
|
+
...t11
|
|
204
197
|
} = result;
|
|
205
|
-
rest =
|
|
198
|
+
rest = t11;
|
|
206
199
|
$[30] = result;
|
|
207
200
|
$[31] = rest;
|
|
208
201
|
} else {
|
|
209
202
|
rest = $[31];
|
|
210
203
|
}
|
|
211
204
|
|
|
212
|
-
let
|
|
205
|
+
let t11;
|
|
213
206
|
|
|
214
207
|
if ($[32] !== client || $[33] !== obsQueryFields || $[34] !== observable_0 || $[35] !== previousData || $[36] !== rest) {
|
|
215
|
-
|
|
208
|
+
t11 = {
|
|
216
209
|
...rest,
|
|
217
210
|
client,
|
|
218
211
|
observable: observable_0,
|
|
@@ -225,13 +218,12 @@ function useQuery_(query, t0) {
|
|
|
225
218
|
$[34] = observable_0;
|
|
226
219
|
$[35] = previousData;
|
|
227
220
|
$[36] = rest;
|
|
228
|
-
$[37] =
|
|
221
|
+
$[37] = t11;
|
|
229
222
|
} else {
|
|
230
|
-
|
|
223
|
+
t11 = $[37];
|
|
231
224
|
}
|
|
232
225
|
|
|
233
|
-
|
|
234
|
-
return t12;
|
|
226
|
+
return t11;
|
|
235
227
|
}
|
|
236
228
|
const fromSkipToken = Symbol();
|
|
237
229
|
function useOptions(query, options, defaultOptions) {
|
|
@@ -249,17 +241,14 @@ function useOptions(query, options, defaultOptions) {
|
|
|
249
241
|
opts[fromSkipToken] = true;
|
|
250
242
|
return opts;
|
|
251
243
|
}
|
|
252
|
-
|
|
253
244
|
const watchQueryOptions = mergeOptions(defaultOptions, {
|
|
254
245
|
...options,
|
|
255
246
|
query
|
|
256
247
|
});
|
|
257
|
-
|
|
258
248
|
if (options.skip) {
|
|
259
249
|
watchQueryOptions.initialFetchPolicy = options.initialFetchPolicy || options.fetchPolicy;
|
|
260
250
|
watchQueryOptions.fetchPolicy = "standby";
|
|
261
251
|
}
|
|
262
|
-
|
|
263
252
|
return watchQueryOptions;
|
|
264
253
|
};t1 = [query, options, defaultOptions];
|
|
265
254
|
$[0] = defaultOptions;
|
|
@@ -302,7 +291,6 @@ function useResult(observable, resultData, ssr) {
|
|
|
302
291
|
equal(resultData.variables, observable.variables)) {
|
|
303
292
|
return;
|
|
304
293
|
}
|
|
305
|
-
// eslint-disable-next-line react-compiler/react-compiler
|
|
306
294
|
resultData.variables = observable.variables;
|
|
307
295
|
if (previous.data && !equal(previous.data, result.data)) {
|
|
308
296
|
resultData.previousData = previous.data;
|