@apollo/client 4.2.0-alpha.1 → 4.2.0-alpha.3
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 +209 -0
- package/__cjs/core/ApolloClient.cjs +25 -12
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +305 -146
- package/__cjs/core/QueryManager.cjs.map +1 -1
- package/__cjs/core/defaultOptions.cjs +3 -0
- package/__cjs/core/defaultOptions.cjs.map +1 -0
- package/__cjs/core/defaultOptions.d.cts +90 -0
- package/__cjs/core/index.cjs.map +1 -1
- package/__cjs/core/index.d.cts +2 -1
- package/__cjs/link/ws/index.cjs +9 -1
- package/__cjs/link/ws/index.cjs.map +1 -1
- package/__cjs/link/ws/index.d.cts +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.cjs +3 -3
- package/__cjs/react/hooks/useBackgroundQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useBackgroundQuery.d.cts +1598 -765
- package/__cjs/react/hooks/useLazyQuery.cjs +3 -5
- package/__cjs/react/hooks/useLazyQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLazyQuery.d.cts +369 -115
- package/__cjs/react/hooks/useLoadableQuery.cjs +8 -4
- package/__cjs/react/hooks/useLoadableQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useLoadableQuery.d.cts +507 -192
- package/__cjs/react/hooks/useMutation.cjs +5 -48
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +239 -130
- package/__cjs/react/hooks/useQuery.cjs +5 -5
- package/__cjs/react/hooks/useQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useQuery.d.cts +636 -276
- package/__cjs/react/hooks/useSubscription.cjs +1 -1
- package/__cjs/react/hooks/useSubscription.cjs.map +1 -1
- package/__cjs/react/hooks/useSubscription.d.cts +2 -2
- package/__cjs/react/hooks/useSuspenseQuery.cjs +3 -3
- package/__cjs/react/hooks/useSuspenseQuery.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseQuery.d.cts +799 -399
- package/__cjs/react/internal/cache/getSuspenseCache.cjs.map +1 -1
- package/__cjs/react/internal/cache/getSuspenseCache.d.cts +7 -0
- package/__cjs/utilities/internal/LazyType.cjs +3 -0
- package/__cjs/utilities/internal/LazyType.cjs.map +1 -0
- package/__cjs/utilities/internal/LazyType.d.cts +10 -0
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +3 -0
- package/__cjs/utilities/internal/types/OptionWithFallback.cjs +3 -0
- package/__cjs/utilities/internal/types/OptionWithFallback.cjs.map +1 -0
- package/__cjs/utilities/internal/types/OptionWithFallback.d.cts +5 -0
- package/__cjs/utilities/internal/types/SignatureStyle.cjs +3 -0
- package/__cjs/utilities/internal/types/SignatureStyle.cjs.map +1 -0
- package/__cjs/utilities/internal/types/SignatureStyle.d.cts +24 -0
- package/__cjs/version.cjs +1 -1
- package/core/ApolloClient.d.ts +305 -146
- package/core/ApolloClient.js +25 -12
- package/core/ApolloClient.js.map +1 -1
- package/core/QueryManager.js.map +1 -1
- package/core/defaultOptions.d.ts +90 -0
- package/core/defaultOptions.js +2 -0
- package/core/defaultOptions.js.map +1 -0
- package/core/index.d.ts +2 -1
- package/core/index.js.map +1 -1
- package/link/ws/index.d.ts +1 -1
- package/link/ws/index.js +9 -1
- package/link/ws/index.js.map +1 -1
- package/package.json +3 -7
- package/react/hooks/useBackgroundQuery.d.ts +1598 -765
- package/react/hooks/useBackgroundQuery.js +2 -2
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useLazyQuery.d.ts +369 -115
- package/react/hooks/useLazyQuery.js +2 -4
- package/react/hooks/useLazyQuery.js.map +1 -1
- package/react/hooks/useLoadableQuery.d.ts +507 -192
- package/react/hooks/useLoadableQuery.js +7 -3
- package/react/hooks/useLoadableQuery.js.map +1 -1
- package/react/hooks/useMutation.d.ts +239 -130
- package/react/hooks/useMutation.js +5 -48
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts +636 -276
- package/react/hooks/useQuery.js +2 -2
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useSubscription.d.ts +2 -2
- package/react/hooks/useSubscription.js +1 -1
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseQuery.d.ts +799 -399
- package/react/hooks/useSuspenseQuery.js +2 -2
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/hooks-compiled/useBackgroundQuery.d.ts +1598 -765
- package/react/hooks-compiled/useBackgroundQuery.js +2 -2
- package/react/hooks-compiled/useBackgroundQuery.js.map +1 -1
- package/react/hooks-compiled/useLazyQuery.d.ts +369 -115
- package/react/hooks-compiled/useLazyQuery.js +2 -4
- package/react/hooks-compiled/useLazyQuery.js.map +1 -1
- package/react/hooks-compiled/useLoadableQuery.d.ts +507 -192
- package/react/hooks-compiled/useLoadableQuery.js +2 -2
- package/react/hooks-compiled/useLoadableQuery.js.map +1 -1
- package/react/hooks-compiled/useMutation.d.ts +239 -130
- package/react/hooks-compiled/useMutation.js +4 -47
- package/react/hooks-compiled/useMutation.js.map +1 -1
- package/react/hooks-compiled/useQuery.d.ts +636 -276
- package/react/hooks-compiled/useQuery.js +2 -2
- package/react/hooks-compiled/useQuery.js.map +1 -1
- package/react/hooks-compiled/useSubscription.d.ts +2 -2
- package/react/hooks-compiled/useSubscription.js +1 -1
- package/react/hooks-compiled/useSubscription.js.map +1 -1
- package/react/hooks-compiled/useSuspenseQuery.d.ts +799 -399
- package/react/hooks-compiled/useSuspenseQuery.js +2 -2
- package/react/hooks-compiled/useSuspenseQuery.js.map +1 -1
- package/react/internal/cache/getSuspenseCache.d.ts +7 -0
- package/react/internal/cache/getSuspenseCache.js.map +1 -1
- package/skills/apollo-client/SKILL.md +168 -0
- package/skills/apollo-client/references/caching.md +560 -0
- package/skills/apollo-client/references/error-handling.md +350 -0
- package/skills/apollo-client/references/fragments.md +804 -0
- package/skills/apollo-client/references/integration-client.md +336 -0
- package/skills/apollo-client/references/integration-nextjs.md +325 -0
- package/skills/apollo-client/references/integration-react-router.md +256 -0
- package/skills/apollo-client/references/integration-tanstack-start.md +378 -0
- package/skills/apollo-client/references/mutations.md +549 -0
- package/skills/apollo-client/references/queries.md +416 -0
- package/skills/apollo-client/references/state-management.md +428 -0
- package/skills/apollo-client/references/suspense-hooks.md +773 -0
- package/skills/apollo-client/references/troubleshooting.md +487 -0
- package/skills/apollo-client/references/typescript-codegen.md +133 -0
- package/utilities/internal/LazyType.d.ts +10 -0
- package/utilities/internal/LazyType.js +2 -0
- package/utilities/internal/LazyType.js.map +1 -0
- package/utilities/internal/index.d.ts +3 -0
- package/utilities/internal/index.js.map +1 -1
- package/utilities/internal/types/OptionWithFallback.d.ts +5 -0
- package/utilities/internal/types/OptionWithFallback.js +2 -0
- package/utilities/internal/types/OptionWithFallback.js.map +1 -0
- package/utilities/internal/types/SignatureStyle.d.ts +24 -0
- package/utilities/internal/types/SignatureStyle.js +2 -0
- package/utilities/internal/types/SignatureStyle.js.map +1 -0
- package/version.js +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,195 @@
|
|
|
1
1
|
# @apollo/client
|
|
2
2
|
|
|
3
|
+
## 4.2.0-alpha.3
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- [#13206](https://github.com/apollographql/apollo-client/pull/13206) [`08fccab`](https://github.com/apollographql/apollo-client/commit/08fccab68822e99c6edd539cb4162d1a3df4f4c9) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Extend the `defaultOptions` type-safety work to `client.mutate` and `useMutation`.
|
|
8
|
+
|
|
9
|
+
The `errorPolicy` option now flows through to the result types for mutations in the same way it already does for queries:
|
|
10
|
+
|
|
11
|
+
- `ApolloClient.MutateResult<TData, TErrorPolicy>` maps `errorPolicy` to the concrete shape of `data` and `error`:
|
|
12
|
+
- `"none"` → `{ data: TData; error?: never }`
|
|
13
|
+
- `"all"` → `{ data: TData | undefined; error?: ErrorLike }`
|
|
14
|
+
- `"ignore"` → `{ data: TData | undefined; error?: never }`
|
|
15
|
+
- `client.mutate` and `useMutation` pick up the declared `defaultOptions.mutate.errorPolicy` and the explicit `errorPolicy` on each call to narrow return types accordingly.
|
|
16
|
+
- `useMutation.Result.error` is narrowed to `undefined` when `errorPolicy` is `"ignore"`, since `client.mutate` never resolves with an error in that case.
|
|
17
|
+
|
|
18
|
+
`DeclareDefaultOptions.Mutate` already accepted `errorPolicy`; the new behavior is that once you declare it, hook and method return types reflect it:
|
|
19
|
+
|
|
20
|
+
```ts
|
|
21
|
+
// apollo.d.ts
|
|
22
|
+
import "@apollo/client";
|
|
23
|
+
|
|
24
|
+
declare module "@apollo/client" {
|
|
25
|
+
namespace ApolloClient {
|
|
26
|
+
namespace DeclareDefaultOptions {
|
|
27
|
+
interface Mutate {
|
|
28
|
+
errorPolicy: "all";
|
|
29
|
+
}
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
}
|
|
33
|
+
```
|
|
34
|
+
|
|
35
|
+
```ts
|
|
36
|
+
const result = await client.mutate({ mutation: MUTATION });
|
|
37
|
+
result.data;
|
|
38
|
+
// ^? TData | undefined
|
|
39
|
+
result.error;
|
|
40
|
+
// ^? ErrorLike | undefined
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
Setting `errorPolicy` on an individual call overrides the default for that call's return type.
|
|
44
|
+
|
|
45
|
+
## 4.2.0-alpha.2
|
|
46
|
+
|
|
47
|
+
### Minor Changes
|
|
48
|
+
|
|
49
|
+
- [#13132](https://github.com/apollographql/apollo-client/pull/13132) [`f3ce805`](https://github.com/apollographql/apollo-client/commit/f3ce805425d10a9666218a8e109288a2d46dcab1) Thanks [@phryneas](https://github.com/phryneas)! - Introduce "classic" and "modern" method and hook signatures.
|
|
50
|
+
|
|
51
|
+
Apollo Client 4.2 introduces two signature styles for methods and hooks. All signatures previously present are now "classic" signatures, and a new set of "modern" signatures are added alongside them.
|
|
52
|
+
|
|
53
|
+
**Classic signatures** are the default and are identical to the signatures before Apollo Client 4.2, preserving backward compatibility. Classic signatures still work with manually specified TypeScript generics (e.g., `useSuspenseQuery<MyData>(...)`). However, manually specifying generics has been discouraged for a long time—instead, we recommend using `TypedDocumentNode` to automatically infer types, which provides more accurate results without any manual annotations.
|
|
54
|
+
|
|
55
|
+
**Modern signatures** automatically incorporate your declared `defaultOptions` into return types, providing more accurate types. Modern signatures infer types from the document node and do not support manually passing generic type arguments; TypeScript will produce a type error if you attempt to do so.
|
|
56
|
+
|
|
57
|
+
Methods and hooks automatically switch to modern signatures the moment any non-optional property is declared in `DeclareDefaultOptions`. The switch happens across all methods and hooks globally:
|
|
58
|
+
|
|
59
|
+
```ts
|
|
60
|
+
// apollo.d.ts
|
|
61
|
+
import "@apollo/client";
|
|
62
|
+
declare module "@apollo/client" {
|
|
63
|
+
namespace ApolloClient {
|
|
64
|
+
namespace DeclareDefaultOptions {
|
|
65
|
+
interface WatchQuery {
|
|
66
|
+
errorPolicy: "all"; // non-optional → modern signatures activated automatically
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Users can also manually switch to modern signatures without declaring any `defaultOptions`, for example when wanting accurate type inference without relying on global `defaultOptions`:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
// apollo.d.ts
|
|
77
|
+
import "@apollo/client";
|
|
78
|
+
declare module "@apollo/client" {
|
|
79
|
+
export interface TypeOverrides {
|
|
80
|
+
signatureStyle: "modern";
|
|
81
|
+
}
|
|
82
|
+
}
|
|
83
|
+
```
|
|
84
|
+
|
|
85
|
+
Users can do a global `DeclareDefaultOptions` type augmentation and then manually switch back to "classic" for migration purposes:
|
|
86
|
+
|
|
87
|
+
```ts
|
|
88
|
+
// apollo.d.ts
|
|
89
|
+
import "@apollo/client";
|
|
90
|
+
declare module "@apollo/client" {
|
|
91
|
+
export interface TypeOverrides {
|
|
92
|
+
signatureStyle: "classic";
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
Note that this is **not recommended for long-term use**. When combined with `DeclareDefaultOptions`, switching back to classic results in the same incorrect types as before Apollo Client 4.2—methods and hooks will not reflect the `defaultOptions` you've declared.
|
|
98
|
+
|
|
99
|
+
- [#13132](https://github.com/apollographql/apollo-client/pull/13132) [`f3ce805`](https://github.com/apollographql/apollo-client/commit/f3ce805425d10a9666218a8e109288a2d46dcab1) Thanks [@phryneas](https://github.com/phryneas)! - Synchronize method and hook return types with `defaultOptions`.
|
|
100
|
+
|
|
101
|
+
Prior to this change, the following code snippet would always apply:
|
|
102
|
+
|
|
103
|
+
```ts
|
|
104
|
+
declare const MY_QUERY: TypedDocumentNode<TData, TVariables>;
|
|
105
|
+
const result1 = useSuspenseQuery(MY_QUERY);
|
|
106
|
+
result1.data;
|
|
107
|
+
// ^? TData
|
|
108
|
+
const result2 = useSuspenseQuery(MY_QUERY, { errorPolicy: "all" });
|
|
109
|
+
result2.data;
|
|
110
|
+
// ^? TData | undefined
|
|
111
|
+
```
|
|
112
|
+
|
|
113
|
+
While these types are generally correct, if you were to set `errorPolicy: 'all'` as a default option, the type of `result.data` for the first query would remain `TData` instead of changing to `TData | undefined` to match the runtime behavior.
|
|
114
|
+
|
|
115
|
+
We are now enforcing that certain `defaultOptions` types need to be registered globally. This means that if you want to use `errorPolicy: 'all'` as a default option for a query, you will need to register its type like this:
|
|
116
|
+
|
|
117
|
+
```ts
|
|
118
|
+
// apollo.d.ts
|
|
119
|
+
import "@apollo/client";
|
|
120
|
+
|
|
121
|
+
declare module "@apollo/client" {
|
|
122
|
+
namespace ApolloClient {
|
|
123
|
+
namespace DeclareDefaultOptions {
|
|
124
|
+
interface WatchQuery {
|
|
125
|
+
// possible global-registered values:
|
|
126
|
+
// * `errorPolicy`
|
|
127
|
+
// * `returnPartialData`
|
|
128
|
+
errorPolicy: "all";
|
|
129
|
+
}
|
|
130
|
+
interface Query {
|
|
131
|
+
// possible global-registered values:
|
|
132
|
+
// * `errorPolicy`
|
|
133
|
+
}
|
|
134
|
+
interface Mutate {
|
|
135
|
+
// possible global-registered values:
|
|
136
|
+
// * `errorPolicy`
|
|
137
|
+
}
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
}
|
|
141
|
+
```
|
|
142
|
+
|
|
143
|
+
Once this type declaration is in place, the type of `result.data` in the above example will correctly be changed to `TData | undefined`, reflecting the possibility that if an error occurs, `data` might be `undefined`. Manually specifying `useSuspenseQuery(MY_QUERY, { errorPolicy: "none" });` changes `result.data` to `TData` to reflect the local override.
|
|
144
|
+
|
|
145
|
+
This change means that you will need to declare your default options types in order to use `defaultOptions` with `ApolloClient`, otherwise you will see a TypeScript error.
|
|
146
|
+
|
|
147
|
+
Without the type declaration, the following (previously valid) code will now error:
|
|
148
|
+
|
|
149
|
+
```ts
|
|
150
|
+
new ApolloClient({
|
|
151
|
+
link: ApolloLink.empty(),
|
|
152
|
+
cache: new InMemoryCache(),
|
|
153
|
+
defaultOptions: {
|
|
154
|
+
watchQuery: {
|
|
155
|
+
// results in a type error:
|
|
156
|
+
// Type '"all"' is not assignable to type '"A default option for watchQuery.errorPolicy must be declared in ApolloClient.DeclareDefaultOptions before usage. See https://www.apollographql.com/docs/react/data/typescript#declaring-default-options-for-type-safety."'.
|
|
157
|
+
errorPolicy: "all",
|
|
158
|
+
},
|
|
159
|
+
},
|
|
160
|
+
});
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
If you are creating multiple instances of Apollo Client with conflicting default options and you cannot register a single `defaultOptions` value as a result, you can relax the constraints by declaring those options as union types covering all values used by all clients. The properties can be required (to enforce them in `defaultOptions`) or optional (if some constructor calls won't pass a value):
|
|
164
|
+
|
|
165
|
+
```ts
|
|
166
|
+
// apollo.d.ts
|
|
167
|
+
import "@apollo/client";
|
|
168
|
+
|
|
169
|
+
declare module "@apollo/client" {
|
|
170
|
+
export namespace ApolloClient {
|
|
171
|
+
export namespace DeclareDefaultOptions {
|
|
172
|
+
interface WatchQuery {
|
|
173
|
+
errorPolicy?: "none" | "all" | "ignore";
|
|
174
|
+
returnPartialData?: boolean;
|
|
175
|
+
}
|
|
176
|
+
interface Query {
|
|
177
|
+
errorPolicy?: "none" | "all" | "ignore";
|
|
178
|
+
}
|
|
179
|
+
interface Mutate {
|
|
180
|
+
errorPolicy?: "none" | "all" | "ignore";
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
```
|
|
186
|
+
|
|
187
|
+
With this declaration, the `ApolloClient` constructor accepts any of those values in `defaultOptions`. The tradeoff is that hook and method return types become more generic. For example, calling `useSuspenseQuery` without an explicit `errorPolicy` will return a result typed as if all error policies are possible, since TypeScript can't know which specific value your instance uses at runtime.
|
|
188
|
+
|
|
189
|
+
Note that making a property optional (`errorPolicy?:`) is equivalent to adding the TypeScript default value (`"none"`) to the union. So `errorPolicy?: "all" | "ignore"` has the same effect on return types as `errorPolicy: "none" | "all" | "ignore"`, because TypeScript assumes the option could also be absent (i.e., `"none"`).
|
|
190
|
+
|
|
191
|
+
You can also use a **partial union** that only lists the values you actually use. For example, if you only ever use `"all"` or `"ignore"`, declare `errorPolicy: "all" | "ignore"` (required) to keep the union narrow and avoid unused values broadening your signatures unnecessarily.
|
|
192
|
+
|
|
3
193
|
## 4.2.0-alpha.1
|
|
4
194
|
|
|
5
195
|
### Patch Changes
|
|
@@ -12,6 +202,25 @@
|
|
|
12
202
|
|
|
13
203
|
- [#13130](https://github.com/apollographql/apollo-client/pull/13130) [`dd12231`](https://github.com/apollographql/apollo-client/commit/dd122316028b55307de4a40335512307c8fa916a) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Improve the accuracy of `client.query` return type to better detect the current `errorPolicy`. The `data` property is no longer nullable when the `errorPolicy` is `none`. This makes it possible to remove the `undefined` checks or optional chaining in most cases.
|
|
14
204
|
|
|
205
|
+
## 4.1.9
|
|
206
|
+
|
|
207
|
+
### Patch Changes
|
|
208
|
+
|
|
209
|
+
- [#13203](https://github.com/apollographql/apollo-client/pull/13203) [`099954b`](https://github.com/apollographql/apollo-client/commit/099954b9905c0f80b57563eb64157386f4493e84) Thanks [@copilot-swe-agent](https://github.com/apps/copilot-swe-agent)! - Remove the `workspaces` field from the published `package.json` in `dist` to avoid Yarn v1 warnings about workspaces requiring private packages.
|
|
210
|
+
|
|
211
|
+
## 4.1.8
|
|
212
|
+
|
|
213
|
+
### Patch Changes
|
|
214
|
+
|
|
215
|
+
- [#13202](https://github.com/apollographql/apollo-client/pull/13202) [`8a51ea6`](https://github.com/apollographql/apollo-client/commit/8a51ea636600dbe4b48477d32f30469b7d36b152) Thanks [@phryneas](https://github.com/phryneas)! - Ship agent skill for usage with @tanstack/intent — the skill is now bundled in the npm package under `skills/apollo-client/` and discoverable by `intent list`.
|
|
216
|
+
For more context, see the [TanStack Intent QuickStart](https://tanstack.com/intent/latest/docs/getting-started/quick-start-consumers).
|
|
217
|
+
|
|
218
|
+
## 4.1.7
|
|
219
|
+
|
|
220
|
+
### Patch Changes
|
|
221
|
+
|
|
222
|
+
- [#13187](https://github.com/apollographql/apollo-client/pull/13187) [`bb3fd9b`](https://github.com/apollographql/apollo-client/commit/bb3fd9b3d40a2505add673a6ee89d85b8b4c8984) Thanks [@jerelmiller](https://github.com/jerelmiller)! - Fix RxJS interop issue with the observable returned by `WebSocketLink`.
|
|
223
|
+
|
|
15
224
|
## 4.1.6
|
|
16
225
|
|
|
17
226
|
### Patch Changes
|
|
@@ -84,7 +84,11 @@ class ApolloClient {
|
|
|
84
84
|
this.link = link;
|
|
85
85
|
this.cache = cache;
|
|
86
86
|
this.queryDeduplication = queryDeduplication;
|
|
87
|
-
|
|
87
|
+
// `DefaultOptions.Input` and `DefaultOptions` are inherently incompatible,
|
|
88
|
+
// as the `.Input` type restricts certain values from being passed in if not
|
|
89
|
+
// configured globally.
|
|
90
|
+
// Without those, it's compatible though so it is fine to cast.
|
|
91
|
+
this.defaultOptions = (defaultOptions || {});
|
|
88
92
|
this.devtoolsConfig = {
|
|
89
93
|
...devtools,
|
|
90
94
|
enabled: devtools?.enabled ?? environment_1.__DEV__,
|
|
@@ -225,7 +229,16 @@ class ApolloClient {
|
|
|
225
229
|
}
|
|
226
230
|
return this.queryManager.watchQuery(options);
|
|
227
231
|
}
|
|
228
|
-
|
|
232
|
+
/**
|
|
233
|
+
* This resolves a single query according to the options specified and
|
|
234
|
+
* returns a `Promise` which is either resolved with the resulting data
|
|
235
|
+
* or rejected with an error.
|
|
236
|
+
*
|
|
237
|
+
* @param options - An object of type `QueryOptions` that allows us to
|
|
238
|
+
* describe how this query should be treated e.g. whether it should hit the
|
|
239
|
+
* server at all or just resolve from the cache, etc.
|
|
240
|
+
*/
|
|
241
|
+
query = (options) => {
|
|
229
242
|
if (this.defaultOptions.query) {
|
|
230
243
|
options = (0, internal_1.mergeOptions)(this.defaultOptions.query, options);
|
|
231
244
|
}
|
|
@@ -239,16 +252,16 @@ class ApolloClient {
|
|
|
239
252
|
(0, invariant_1.invariant)(!options.notifyOnNetworkStatusChange, 76);
|
|
240
253
|
}
|
|
241
254
|
return this.queryManager.query(options);
|
|
242
|
-
}
|
|
255
|
+
};
|
|
243
256
|
/**
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
247
|
-
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
mutate(options) {
|
|
257
|
+
* This resolves a single mutation according to the options specified and returns a
|
|
258
|
+
* Promise which is either resolved with the resulting data or rejected with an
|
|
259
|
+
* error. In some cases both `data` and `errors` might be undefined, for example
|
|
260
|
+
* when `errorPolicy` is set to `'ignore'`.
|
|
261
|
+
*
|
|
262
|
+
* It takes options as an object with the following keys and values:
|
|
263
|
+
*/
|
|
264
|
+
mutate = (options) => {
|
|
252
265
|
const optionsWithDefaults = (0, internal_1.mergeOptions)((0, internal_1.compact)({
|
|
253
266
|
fetchPolicy: "network-only",
|
|
254
267
|
errorPolicy: "none",
|
|
@@ -260,7 +273,7 @@ class ApolloClient {
|
|
|
260
273
|
}
|
|
261
274
|
(0, internal_1.checkDocument)(optionsWithDefaults.mutation, graphql_1.OperationTypeNode.MUTATION);
|
|
262
275
|
return this.queryManager.mutate(optionsWithDefaults);
|
|
263
|
-
}
|
|
276
|
+
};
|
|
264
277
|
/**
|
|
265
278
|
* This subscribes to a graphql subscription according to the options specified and returns an
|
|
266
279
|
* `Observable` which either emits received data or an error.
|