@apollo/client 4.1.0-alpha.1 → 4.1.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 +83 -0
- package/__cjs/cache/core/cache.cjs +148 -50
- package/__cjs/cache/core/cache.cjs.map +1 -1
- package/__cjs/cache/core/cache.d.cts +72 -23
- package/__cjs/cache/inmemory/inMemoryCache.cjs +12 -1
- package/__cjs/cache/inmemory/inMemoryCache.cjs.map +1 -1
- package/__cjs/core/ApolloClient.cjs +24 -27
- package/__cjs/core/ApolloClient.cjs.map +1 -1
- package/__cjs/core/ApolloClient.d.cts +87 -2
- package/__cjs/incremental/handlers/defer20220824.cjs +6 -2
- package/__cjs/incremental/handlers/defer20220824.cjs.map +1 -1
- package/__cjs/incremental/handlers/defer20220824.d.cts +0 -2
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs +9 -3
- package/__cjs/incremental/handlers/graphql17Alpha9.cjs.map +1 -1
- package/__cjs/incremental/handlers/notImplemented.cjs +1 -1
- package/__cjs/incremental/handlers/notImplemented.cjs.map +1 -1
- package/__cjs/invariantErrorCodes.cjs +2 -2
- package/__cjs/react/hooks/useFragment.cjs +37 -84
- package/__cjs/react/hooks/useFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useFragment.d.cts +65 -6
- package/__cjs/react/hooks/useMutation.cjs +7 -1
- package/__cjs/react/hooks/useMutation.cjs.map +1 -1
- package/__cjs/react/hooks/useMutation.d.cts +13 -1
- package/__cjs/react/hooks/useQuery.d.cts +1 -1
- package/__cjs/react/hooks/useSuspenseFragment.cjs +13 -12
- package/__cjs/react/hooks/useSuspenseFragment.cjs.map +1 -1
- package/__cjs/react/hooks/useSuspenseFragment.d.cts +33 -7
- package/__cjs/react/internal/cache/FragmentReference.cjs +3 -22
- package/__cjs/react/internal/cache/FragmentReference.cjs.map +1 -1
- package/__cjs/react/internal/cache/FragmentReference.d.cts +2 -4
- package/__cjs/react/internal/cache/SuspenseCache.cjs.map +1 -1
- package/__cjs/react/internal/cache/SuspenseCache.d.cts +1 -1
- package/__cjs/react/internal/cache/types.d.cts +2 -2
- package/__cjs/utilities/DeepPartial.cjs.map +1 -1
- package/__cjs/utilities/DeepPartial.d.cts +1 -1
- package/__cjs/utilities/internal/combineLatestBatched.cjs +71 -0
- package/__cjs/utilities/internal/combineLatestBatched.cjs.map +1 -0
- package/__cjs/utilities/internal/combineLatestBatched.d.cts +14 -0
- package/__cjs/utilities/internal/index.cjs +4 -2
- package/__cjs/utilities/internal/index.cjs.map +1 -1
- package/__cjs/utilities/internal/index.d.cts +1 -0
- package/__cjs/version.cjs +1 -1
- package/cache/core/cache.d.ts +72 -23
- package/cache/core/cache.js +151 -53
- package/cache/core/cache.js.map +1 -1
- package/cache/inmemory/inMemoryCache.js +12 -1
- package/cache/inmemory/inMemoryCache.js.map +1 -1
- package/core/ApolloClient.d.ts +87 -2
- package/core/ApolloClient.js +24 -27
- package/core/ApolloClient.js.map +1 -1
- package/incremental/handlers/defer20220824.d.ts +0 -2
- package/incremental/handlers/defer20220824.js +6 -2
- package/incremental/handlers/defer20220824.js.map +1 -1
- package/incremental/handlers/graphql17Alpha9.js +9 -3
- package/incremental/handlers/graphql17Alpha9.js.map +1 -1
- package/incremental/handlers/notImplemented.js +1 -1
- package/incremental/handlers/notImplemented.js.map +1 -1
- package/invariantErrorCodes.js +2 -2
- package/package.json +1 -1
- package/react/hooks/useFragment.d.ts +65 -6
- package/react/hooks/useFragment.js +37 -84
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useMutation.d.ts +13 -1
- package/react/hooks/useMutation.js +7 -1
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useSuspenseFragment.d.ts +33 -7
- package/react/hooks/useSuspenseFragment.js +14 -13
- package/react/hooks/useSuspenseFragment.js.map +1 -1
- package/react/hooks-compiled/useFragment.d.ts +65 -6
- package/react/hooks-compiled/useFragment.js +111 -85
- package/react/hooks-compiled/useFragment.js.map +1 -1
- package/react/hooks-compiled/useMutation.d.ts +13 -1
- package/react/hooks-compiled/useMutation.js +5 -1
- package/react/hooks-compiled/useMutation.js.map +1 -1
- package/react/hooks-compiled/useSuspenseFragment.d.ts +33 -7
- package/react/hooks-compiled/useSuspenseFragment.js +14 -13
- package/react/hooks-compiled/useSuspenseFragment.js.map +1 -1
- package/react/internal/cache/FragmentReference.d.ts +2 -4
- package/react/internal/cache/FragmentReference.js +3 -22
- package/react/internal/cache/FragmentReference.js.map +1 -1
- package/react/internal/cache/SuspenseCache.d.ts +1 -1
- package/react/internal/cache/SuspenseCache.js.map +1 -1
- package/react/internal/cache/types.d.ts +2 -2
- package/react/internal/cache/types.js.map +1 -1
- package/utilities/DeepPartial.d.ts +1 -1
- package/utilities/DeepPartial.js.map +1 -1
- package/utilities/internal/combineLatestBatched.d.ts +14 -0
- package/utilities/internal/combineLatestBatched.js +68 -0
- package/utilities/internal/combineLatestBatched.js.map +1 -0
- package/utilities/internal/index.d.ts +1 -0
- package/utilities/internal/index.js +1 -0
- package/utilities/internal/index.js.map +1 -1
- package/version.js +1 -1
|
@@ -1,15 +1,8 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { c as _c } from "@apollo/client/react/internal/compiler-runtime";
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import { useDeepMemo, wrapHook } from "./internal/index.js";
|
|
4
4
|
import { useApolloClient } from "./useApolloClient.js";
|
|
5
5
|
import { useSyncExternalStore } from "./useSyncExternalStore.js";
|
|
6
|
-
/**
|
|
7
|
-
* `useFragment` represents a lightweight live binding into the Apollo Client Cache and enables Apollo Client to broadcast very specific fragment results to individual components. This hook returns an always-up-to-date view of whatever data the cache currently contains for a given fragment. `useFragment` never triggers network requests of its own.
|
|
8
|
-
*
|
|
9
|
-
* Note that the `useQuery` hook remains the primary hook responsible for querying and populating data in the cache ([see the API reference](./hooks#usequery)). As a result, the component reading the fragment data via `useFragment` is still subscribed to all changes in the query data, but receives updates only when that fragment's specific data change.
|
|
10
|
-
*
|
|
11
|
-
* To view a `useFragment` example, see the [Fragments](https://www.apollographql.com/docs/react/data/fragments#usefragment) page.
|
|
12
|
-
*/
|
|
13
6
|
export function useFragment(options) {
|
|
14
7
|
"use no memo";
|
|
15
8
|
return wrapHook("useFragment",
|
|
@@ -17,87 +10,120 @@ export function useFragment(options) {
|
|
|
17
10
|
useFragment_, useApolloClient(options.client))(options);
|
|
18
11
|
}
|
|
19
12
|
function useFragment_(options) {
|
|
13
|
+
const $ = _c(19);
|
|
20
14
|
const client = useApolloClient(options.client);
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
15
|
+
let from;
|
|
16
|
+
let rest;
|
|
17
|
+
|
|
18
|
+
if ($[0] !== options) {
|
|
19
|
+
({
|
|
20
|
+
from,
|
|
21
|
+
...rest
|
|
22
|
+
} = options);
|
|
23
|
+
$[0] = options;
|
|
24
|
+
$[1] = from;
|
|
25
|
+
$[2] = rest;
|
|
26
|
+
} else {
|
|
27
|
+
from = $[1];
|
|
28
|
+
rest = $[2];
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
const {
|
|
32
|
+
cache
|
|
33
|
+
} = client;
|
|
34
|
+
let t0;
|
|
35
|
+
let t1;
|
|
36
|
+
|
|
37
|
+
if ($[3] !== cache || $[4] !== from) {
|
|
38
|
+
t0 = () => {
|
|
39
|
+
const fromArray = Array.isArray(from) ? from : [from];
|
|
40
|
+
const ids = fromArray.map(
|
|
41
|
+
value => typeof value === "string" ? value : value === null ? null : cache.identify(value)
|
|
42
|
+
);
|
|
43
|
+
return Array.isArray(from) ? ids : ids[0];
|
|
44
|
+
};t1 = [cache, from];
|
|
45
|
+
$[3] = cache;
|
|
46
|
+
$[4] = from;
|
|
47
|
+
$[5] = t0;
|
|
48
|
+
$[6] = t1;
|
|
49
|
+
} else {
|
|
50
|
+
t0 = $[5];
|
|
51
|
+
t1 = $[6];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
const ids_0 = useDeepMemo(t0, t1);
|
|
55
|
+
let t2;
|
|
56
|
+
let t3;
|
|
57
|
+
|
|
58
|
+
if ($[7] !== ids_0 || $[8] !== rest) {
|
|
59
|
+
t2 = () => ({
|
|
60
|
+
...rest,
|
|
61
|
+
from: ids_0
|
|
62
|
+
});t3 = [rest, ids_0];
|
|
63
|
+
$[7] = ids_0;
|
|
64
|
+
$[8] = rest;
|
|
65
|
+
$[9] = t2;
|
|
66
|
+
$[10] = t3;
|
|
67
|
+
} else {
|
|
68
|
+
t2 = $[9];
|
|
69
|
+
t3 = $[10];
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
const stableOptions = useDeepMemo(t2, t3);
|
|
73
|
+
let t4;
|
|
74
|
+
let t5;
|
|
75
|
+
|
|
76
|
+
if ($[11] !== client || $[12] !== stableOptions) {
|
|
77
|
+
t5 = client.watchFragment(stableOptions);
|
|
78
|
+
$[11] = client;
|
|
79
|
+
$[12] = stableOptions;
|
|
80
|
+
$[13] = t5;
|
|
81
|
+
} else {
|
|
82
|
+
t5 = $[13];
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
t4 = t5;
|
|
86
|
+
const observable = t4;
|
|
87
|
+
let t6;
|
|
88
|
+
|
|
89
|
+
if ($[14] !== from || $[15] !== observable) {
|
|
90
|
+
t6 = () => from === null ? nullResult : observable.getCurrentResult();
|
|
91
|
+
$[14] = from;
|
|
92
|
+
$[15] = observable;
|
|
93
|
+
$[16] = t6;
|
|
94
|
+
} else {
|
|
95
|
+
t6 = $[16];
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
const getSnapshot = t6;
|
|
99
|
+
let t7;
|
|
100
|
+
|
|
101
|
+
if ($[17] !== observable) {
|
|
102
|
+
t7 = update => {
|
|
103
|
+
let lastTimeout = 0;
|
|
104
|
+
const subscription = observable.subscribe({
|
|
105
|
+
next: () => {
|
|
82
106
|
clearTimeout(lastTimeout);
|
|
83
|
-
lastTimeout = setTimeout(
|
|
84
|
-
}
|
|
107
|
+
lastTimeout = setTimeout(update);
|
|
108
|
+
}
|
|
85
109
|
});
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
110
|
+
|
|
111
|
+
return () => {
|
|
112
|
+
subscription.unsubscribe();
|
|
113
|
+
clearTimeout(lastTimeout);
|
|
114
|
+
};
|
|
89
115
|
};
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
data: diff.result,
|
|
95
|
-
complete: !!diff.complete,
|
|
96
|
-
dataState: diff.complete ? "complete" : "partial",
|
|
97
|
-
}; // TODO: Remove assertion once useFragment returns null
|
|
98
|
-
if (diff.missing) {
|
|
99
|
-
result.missing = diff.missing.missing;
|
|
116
|
+
$[17] = observable;
|
|
117
|
+
$[18] = t7;
|
|
118
|
+
} else {
|
|
119
|
+
t7 = $[18];
|
|
100
120
|
}
|
|
101
|
-
|
|
121
|
+
|
|
122
|
+
return useSyncExternalStore(t7, getSnapshot, getSnapshot);
|
|
102
123
|
}
|
|
124
|
+
const nullResult = Object.freeze({
|
|
125
|
+
data: {},
|
|
126
|
+
dataState: "partial",
|
|
127
|
+
complete: false,
|
|
128
|
+
});
|
|
103
129
|
//# sourceMappingURL=useFragment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFragment.js","sources":["../../../src/react/hooks/useFragment.ts"],"sourcesContent":["import { equal } from \"@wry/equality\";\nimport * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataValue,\n DocumentNode,\n GetDataState,\n OperationVariables,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport type {\n Cache,\n MissingTree,\n Reference,\n StoreObject,\n} from \"@apollo/client/cache\";\nimport type { FragmentType, MaybeMasked } from \"@apollo/client/masking\";\nimport type { NoInfer } from \"@apollo/client/utilities/internal\";\n\nimport { useDeepMemo, wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\n\nexport declare namespace useFragment {\n import _self = useFragment;\n export interface Options<TData, TVariables extends OperationVariables> {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to select a single.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: NoInfer<TVariables>;\n\n /**\n * An object containing a `__typename` and primary key fields (such as `id`) identifying the entity object from which the fragment will be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID (uncommon).\n */\n from:\n | StoreObject\n | Reference\n | FragmentType<NoInfer<TData>>\n | string\n | null;\n\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted.\n *\n * @defaultValue true\n */\n optimistic?: boolean;\n\n /**\n * The instance of `ApolloClient` to use to look up the fragment.\n *\n * By default, the instance that's passed down via context is used, but you\n * can provide a different instance here.\n *\n * @docGroup 1. Operation options\n */\n client?: ApolloClient;\n }\n\n namespace DocumentationTypes {\n namespace useFragment {\n export interface Options<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends _self.Options<TData, TVariables> {}\n }\n }\n\n // TODO: Update this to return `null` when there is no data returned from the\n // fragment.\n export type Result<TData> =\n | ({\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#complete:member} */\n complete: true;\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#missing:member} */\n missing?: never;\n } & GetDataState<MaybeMasked<TData>, \"complete\">)\n | ({\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#complete:member} */\n complete: false;\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#missing:member} */\n missing?: MissingTree;\n } & GetDataState<MaybeMasked<TData>, \"partial\">);\n\n export namespace DocumentationTypes {\n namespace useFragment {\n export interface Result<TData> {\n data: MaybeMasked<TData> | DataValue.Partial<MaybeMasked<TData>>;\n complete: boolean;\n /**\n * A tree of all `MissingFieldError` messages reported during fragment reading, where the branches of the tree indicate the paths of the errors within the query result.\n */\n missing?: MissingTree;\n }\n }\n }\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\n export function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >({\n fragment,\n from,\n fragmentName,\n variables,\n optimistic,\n client,\n }: useFragment.Options<TData, TVariables>): useFragment.Result<TData>;\n }\n}\n\n/**\n * `useFragment` represents a lightweight live binding into the Apollo Client Cache and enables Apollo Client to broadcast very specific fragment results to individual components. This hook returns an always-up-to-date view of whatever data the cache currently contains for a given fragment. `useFragment` never triggers network requests of its own.\n *\n * Note that the `useQuery` hook remains the primary hook responsible for querying and populating data in the cache ([see the API reference](./hooks#usequery)). As a result, the component reading the fragment data via `useFragment` is still subscribed to all changes in the query data, but receives updates only when that fragment's specific data change.\n *\n * To view a `useFragment` example, see the [Fragments](https://www.apollographql.com/docs/react/data/fragments#usefragment) page.\n */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(options: useFragment.Options<TData, TVariables>): useFragment.Result<TData> {\n \"use no memo\";\n return wrapHook(\n \"useFragment\",\n // eslint-disable-next-line react-compiler/react-compiler\n useFragment_,\n useApolloClient(options.client)\n )(options);\n}\n\nfunction useFragment_<TData, TVariables extends OperationVariables>(\n options: useFragment.Options<TData, TVariables>\n): useFragment.Result<TData> {\n const client = useApolloClient(options.client);\n const { cache } = client;\n const { from, ...rest } = options;\n\n // We calculate the cache id seperately from `stableOptions` because we don't\n // want changes to non key fields in the `from` property to affect\n // `stableOptions` and retrigger our subscription. If the cache identifier\n // stays the same between renders, we want to reuse the existing subscription.\n const id = React.useMemo(\n () =>\n typeof from === \"string\" ? from\n : from === null ? null\n : cache.identify(from),\n [cache, from]\n );\n\n const stableOptions = useDeepMemo(() => ({ ...rest, from: id! }), [rest, id]);\n\n // Since .next is async, we need to make sure that we\n // get the correct diff on the next render given new diffOptions\n const diff = React.useMemo(() => {\n const { fragment, fragmentName, from, optimistic = true } = stableOptions;\n\n if (from === null) {\n return {\n result: diffToResult({\n result: {},\n complete: false,\n } as Cache.DiffResult<TData>),\n };\n }\n\n const { cache } = client;\n const diff = cache.diff<TData, TVariables>({\n ...stableOptions,\n returnPartialData: true,\n id: from,\n query: cache[\"getFragmentDoc\"](\n client[\"transform\"](fragment),\n fragmentName\n ),\n optimistic,\n });\n\n return {\n result: diffToResult<TData>({\n ...diff,\n result: client[\"queryManager\"].maskFragment({\n fragment,\n fragmentName,\n // TODO: Revert to `diff.result` once `useFragment` supports `null` as\n // valid return value\n data: diff.result === null ? {} : diff.result,\n }) as any,\n }),\n };\n }, [client, stableOptions]);\n\n // Used for both getSnapshot and getServerSnapshot\n const getSnapshot = React.useCallback(() => diff.result, [diff]);\n\n return useSyncExternalStore(\n React.useCallback(\n (forceUpdate) => {\n let lastTimeout = 0;\n\n const subscription =\n stableOptions.from === null ?\n null\n : client.watchFragment(stableOptions).subscribe({\n next: (result) => {\n // Avoid unnecessarily rerendering this hook for the initial result\n // emitted from watchFragment which should be equal to\n // `diff.result`.\n if (equal(result, diff.result)) return;\n diff.result = result;\n // If we get another update before we've re-rendered, bail out of\n // the update and try again. This ensures that the relative timing\n // between useQuery and useFragment stays roughly the same as\n // fixed in https://github.com/apollographql/apollo-client/pull/11083\n clearTimeout(lastTimeout);\n lastTimeout = setTimeout(forceUpdate) as any;\n },\n });\n return () => {\n subscription?.unsubscribe();\n clearTimeout(lastTimeout);\n };\n },\n [client, stableOptions, diff]\n ),\n getSnapshot,\n getSnapshot\n );\n}\n\nfunction diffToResult<TData>(\n diff: Cache.DiffResult<TData>\n): useFragment.Result<TData> {\n const result = {\n data: diff.result,\n complete: !!diff.complete,\n dataState: diff.complete ? \"complete\" : \"partial\",\n } as useFragment.Result<TData>; // TODO: Remove assertion once useFragment returns null\n\n if (diff.missing) {\n result.missing = diff.missing.missing;\n }\n\n return result;\n}\n"],"names":[],"mappings":"AAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAE,CAAT,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,EAAsB,CAAtB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAqC;AACrC,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAP,CAAA,EAAY,CAAZ,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAAuB,CAAvB,CAAA,CAAA,CAAA,CAAA,CAAA,CAA8B;AAmB9B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QAChB,CAAJ,CAAA,CAAA,CAAA,CAAA,CAAU,CAAC,CAAX,CAAA,CAAA,CAAA,CAAA,CAAA,EAAA,EAAqB,CAArB,CAAA,CAAA,CAAyB,CAAC,CAA1B,CAAA,CAAA,CAAA,CAAA,CAAA,CAAiC,CAAC,CAAlC,CAAA,CAAA,CAAA,CAAA,CAAA,CAAyC;IACvC;IAEA,CAAF,CAAA,CAAA,CAAA,CAAA,EAAS,CAAT,CAAA,CAAA,CAAA,CAAA,CAAe;AACf;"}
|
|
1
|
+
{"version":3,"file":"useFragment.js","sources":["../../../src/react/hooks/useFragment.ts"],"sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataValue,\n DocumentNode,\n GetDataState,\n OperationVariables,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport type { ApolloCache, MissingTree } from \"@apollo/client/cache\";\nimport type { MaybeMasked } from \"@apollo/client/masking\";\nimport type { NoInfer } from \"@apollo/client/utilities/internal\";\n\nimport { useDeepMemo, wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\n\nexport declare namespace useFragment {\n import _self = useFragment;\n\n export interface Options<TData, TVariables extends OperationVariables> {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to select a single.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * Any variables that the GraphQL query may depend on.\n */\n variables?: NoInfer<TVariables>;\n\n /**\n * An object or array containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID (uncommon).\n */\n from: useFragment.FromValue<TData> | Array<useFragment.FromValue<TData>>;\n\n /**\n * Whether to read from optimistic or non-optimistic cache data. If\n * this named option is provided, the optimistic parameter of the\n * readQuery method can be omitted.\n *\n * @defaultValue true\n */\n optimistic?: boolean;\n\n /**\n * The instance of `ApolloClient` to use to look up the fragment.\n *\n * By default, the instance that's passed down via context is used, but you\n * can provide a different instance here.\n *\n * @docGroup 1. Operation options\n */\n client?: ApolloClient;\n }\n\n namespace DocumentationTypes {\n namespace useFragment {\n export interface Options<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends _self.Options<TData, TVariables> {}\n }\n }\n\n /**\n * Acceptable values provided to the `from` option.\n */\n export type FromValue<TData> = ApolloCache.WatchFragmentFromValue<TData>;\n\n // TODO: Update this to return `null` when there is no data returned from the\n // fragment.\n export type Result<TData> =\n | ({\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#complete:member} */\n complete: true;\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#missing:member} */\n missing?: never;\n } & GetDataState<MaybeMasked<TData>, \"complete\">)\n | {\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#complete:member} */\n complete: false;\n /** {@inheritDoc @apollo/client/react!useFragment.DocumentationTypes.useFragment.Result#missing:member} */\n missing?: MissingTree;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#data:member} */\n data: TData extends Array<infer TItem> ?\n Array<DataValue.Partial<TItem> | null>\n : DataValue.Partial<TData>;\n /** {@inheritDoc @apollo/client!QueryResultDocumentation#dataState:member} */\n dataState: \"partial\";\n };\n\n export namespace DocumentationTypes {\n namespace useFragment {\n export interface Result<TData> {\n data: MaybeMasked<TData> | DataValue.Partial<MaybeMasked<TData>>;\n complete: boolean;\n /**\n * A tree of all `MissingFieldError` messages reported during fragment reading, where the branches of the tree indicate the paths of the errors within the query result.\n */\n missing?: MissingTree;\n }\n }\n }\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\n export function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n >({\n fragment,\n from,\n fragmentName,\n variables,\n optimistic,\n client,\n }: useFragment.Options<TData, TVariables>): useFragment.Result<TData>;\n }\n}\n\n/**\n * `useFragment` represents a lightweight live binding into the Apollo Client Cache and enables Apollo Client to broadcast very specific fragment results to individual components. This hook returns an always-up-to-date view of whatever data the cache currently contains for a given fragment. `useFragment` never triggers network requests of its own.\n *\n * Note that the `useQuery` hook remains the primary hook responsible for querying and populating data in the cache ([see the API reference](./hooks#usequery)). As a result, the component reading the fragment data via `useFragment` is still subscribed to all changes in the query data, but receives updates only when that fragment's specific data change.\n *\n * To view a `useFragment` example, see the [Fragments](https://www.apollographql.com/docs/react/data/fragments#usefragment) page.\n */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables> & {\n from: Array<NonNullable<useFragment.FromValue<TData>>>;\n }\n): useFragment.Result<Array<TData>>;\n\n/** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables> & {\n from: Array<null>;\n }\n): useFragment.Result<Array<null>>;\n\n/** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables> & {\n from: Array<useFragment.FromValue<TData>>;\n }\n): useFragment.Result<Array<TData | null>>;\n\n/** {@inheritDoc @apollo/client/react!useFragment:function(1)} */\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(options: useFragment.Options<TData, TVariables>): useFragment.Result<TData>;\n\nexport function useFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useFragment.Options<TData, TVariables>\n): useFragment.Result<TData> | useFragment.Result<Array<TData | null>> {\n \"use no memo\";\n return wrapHook(\n \"useFragment\",\n // eslint-disable-next-line react-compiler/react-compiler\n useFragment_,\n useApolloClient(options.client)\n )(options);\n}\n\nfunction useFragment_<TData, TVariables extends OperationVariables>(\n options: useFragment.Options<TData, TVariables>\n): useFragment.Result<TData> | useFragment.Result<Array<TData | null>> {\n const client = useApolloClient(options.client);\n const { from, ...rest } = options;\n const { cache } = client;\n\n // We calculate the cache id seperately because we don't want changes to non\n // key fields in the `from` property to recreate the observable. If the cache\n // identifier stays the same between renders, we want to reuse the existing\n // subscription.\n const ids = useDeepMemo(() => {\n const fromArray = Array.isArray(from) ? from : [from];\n\n const ids = fromArray.map((value) =>\n typeof value === \"string\" ? value\n : value === null ? null\n : cache.identify(value)\n );\n\n return Array.isArray(from) ? ids : ids[0];\n }, [cache, from]);\n\n const stableOptions = useDeepMemo(\n () => ({ ...rest, from: ids as any }),\n [rest, ids]\n );\n\n const observable = React.useMemo(\n () => client.watchFragment(stableOptions),\n [client, stableOptions]\n );\n\n // Unfortunately we forgot to update the use case of `from: null` on\n // useFragment in 4.0 to match `useSuspenseFragment`. As such, we need to\n // fallback to data: {} with complete: false when `from` is `null` to maintain\n // backwards compatibility. We should plan to change this in v5.\n const getSnapshot = React.useCallback(\n () => (from === null ? nullResult : observable.getCurrentResult()),\n [from, observable]\n );\n\n return useSyncExternalStore(\n React.useCallback(\n (update) => {\n let lastTimeout = 0;\n const subscription = observable.subscribe({\n next: () => {\n // If we get another update before we've re-rendered, bail out of\n // the update and try again. This ensures that the relative timing\n // between useQuery and useFragment stays roughly the same as\n // fixed in https://github.com/apollographql/apollo-client/pull/11083\n clearTimeout(lastTimeout);\n lastTimeout = setTimeout(update) as any;\n },\n });\n\n return () => {\n subscription.unsubscribe();\n clearTimeout(lastTimeout);\n };\n },\n [observable]\n ),\n getSnapshot,\n getSnapshot\n );\n}\n\nconst nullResult = Object.freeze({\n data: {},\n dataState: \"partial\",\n complete: false,\n}) as useFragment.Result<any>;\n"],"names":[],"mappings":";AAAA,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,CAAA,CAAA,CAAA,CAAA,EAAA,EAAmB,CAAnB,CAAA,CAAA,CAAA,CAAA,CAAyB,CAAC,CAA1B,CAAA,CAAA,CAAA,CAAA,CAAgC,CAAC;IAC/B,CAAF,CAAA,CAAA,CAAM,EAAE,CAAR,CAAU;IACR,CAAF,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAW,EAAE,CAAb,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAsB;IACpB,CAAF,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAU,EAAE,CAAZ,CAAA,CAAA,CAAA,CAAiB;AACjB,CAAC;"}
|
|
@@ -198,7 +198,19 @@ export declare namespace useMutation {
|
|
|
198
198
|
variables: TVariables;
|
|
199
199
|
}
|
|
200
200
|
]) => Promise<ApolloClient.MutateResult<MaybeMasked<TData>>>;
|
|
201
|
-
type MutationFunctionOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache> = Options<TData, TVariables, TCache
|
|
201
|
+
type MutationFunctionOptions<TData = unknown, TVariables extends OperationVariables = OperationVariables, TCache extends ApolloCache = ApolloCache> = Options<TData, TVariables, TCache> & {
|
|
202
|
+
/**
|
|
203
|
+
* If you're using [Apollo Link](https://www.apollographql.com/docs/react/api/link/introduction/), this object is the initial value of the `context` object that's passed along your link chain.
|
|
204
|
+
*
|
|
205
|
+
* @docGroup 2. Networking options
|
|
206
|
+
*
|
|
207
|
+
*
|
|
208
|
+
* @remarks
|
|
209
|
+
* When provided as a callback function, the function is called with the
|
|
210
|
+
* value of `context` provided to the `useMutation` hook.
|
|
211
|
+
*/
|
|
212
|
+
context?: DefaultContext | ((hookContext: DefaultContext | undefined) => DefaultContext);
|
|
213
|
+
};
|
|
202
214
|
namespace DocumentationTypes {
|
|
203
215
|
/**
|
|
204
216
|
* > Refer to the [Mutations](https://www.apollographql.com/docs/react/data/mutations/) section for a more in-depth overview of `useMutation`.
|
|
@@ -118,6 +118,7 @@ export function useMutation(mutation, options) {
|
|
|
118
118
|
mutation: mutation_0
|
|
119
119
|
};
|
|
120
120
|
const client_0 = executeOptions.client || ref.current.client;
|
|
121
|
+
const context = typeof executeOptions.context === "function" ? executeOptions.context(options_0?.context) : executeOptions.context;
|
|
121
122
|
|
|
122
123
|
if (!ref.current.result.loading && ref.current.isMounted) {
|
|
123
124
|
setResult(ref.current.result = {
|
|
@@ -130,7 +131,10 @@ export function useMutation(mutation, options) {
|
|
|
130
131
|
}
|
|
131
132
|
|
|
132
133
|
const mutationId = ref.current.mutationId = ref.current.mutationId + 1;
|
|
133
|
-
const clientOptions = mergeOptions(baseOptions,
|
|
134
|
+
const clientOptions = mergeOptions(baseOptions, {
|
|
135
|
+
...executeOptions,
|
|
136
|
+
context
|
|
137
|
+
});
|
|
134
138
|
|
|
135
139
|
return preventUnhandledRejection(client_0.mutate(clientOptions).then(response => {
|
|
136
140
|
const {
|
|
@@ -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 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\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, executeOptions 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":";AACA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAE,CAAT,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,EAAsB,CAAtB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAqC;AACrC,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAP,CAAA,EAAY,CAAZ,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAAuB,CAAvB,CAAA,CAAA,CAAA,CAAA,CAAA,CAA8B;AAqB9B,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EACL,CADF,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACc,EACZ,CAFF,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAE2B,EAF3B,EAAA,CAAA,CAAA,CAAA,EAGO,CAHP,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CA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CAAA,CAAA,CAAA,EAA6B,CAA7B,CAAA,CAAA,CAAA,CAAA,GAAA;IACE,CAAF,CAAA,CAAA,CAAA,CAAA,EAAS;QACL,CAAJ,CAAA,CAAA,CAAQ,EAAE,CAAV,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAmB;QACf,CAAJ,CAAA,CAAA,CAAA,CAAS,EAAE,CAAX,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAoB;QAChB,CAAJ,CAAA,CAAA,CAAA,CAAA,CAAU,EAAE,CAAZ,CAAA,CAAA,CAAA,CAAiB;QACb,CAAJ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAW,EAAE,CAAb,CAAA,CAAA,CAAA,CAAkB;QACd,CAAJ,CAAA,CAAA,CAAA,CAAA,CAAU;IACV,CAAG;AACH;"}
|
|
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":";AACA,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAE,CAAT,CAAA,CAAA,CAAA,EAAA,EAAA,CAAA,CAAA,CAAA,EAAsB,CAAtB,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAqC;AACrC,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EAAP,CAAA,EAAY,CAAZ,CAAA,CAAA,CAAA,EAAA,CAAA,CAAA,CAAA,EAAuB,CAAvB,CAAA,CAAA,CAAA,CAAA,CAAA,CAA8B;AAqB9B,CAAA,CAAA,CAAA,CAAA,CAAA,EAAO,EACL,CADF,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CACc,EACZ,CAFF,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAE2B,EAF3B,EAAA,CAAA,CAAA,CAAA,EAGO,CAHP,CAAA,CAAA,C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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;SA6KS,CAAT,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,EAA6B,CAA7B,CAAA,CAAA,CAAA,CAAA,GAAA;IACE,CAAF,CAAA,CAAA,CAAA,CAAA,EAAS;QACL,CAAJ,CAAA,CAAA,CAAQ,EAAE,CAAV,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAmB;QACf,CAAJ,CAAA,CAAA,CAAA,CAAS,EAAE,CAAX,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAA,CAAoB;QAChB,CAAJ,CAAA,CAAA,CAAA,CAAA,CAAU,EAAE,CAAZ,CAAA,CAAA,CAAA,CAAiB;QACb,CAAJ,CAAA,CAAA,CAAA,CAAA,CAAA,CAAW,EAAE,CAAb,CAAA,CAAA,CAAA,CAAkB;QACd,CAAJ,CAAA,CAAA,CAAA,CAAA,CAAU;IACV,CAAG;AACH;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import type { ApolloClient, DataValue, DocumentNode, OperationVariables,
|
|
2
|
-
import type {
|
|
1
|
+
import type { ApolloClient, DataValue, DocumentNode, OperationVariables, TypedDocumentNode } from "@apollo/client";
|
|
2
|
+
import type { ApolloCache } from "@apollo/client/cache";
|
|
3
|
+
import type { MaybeMasked } from "@apollo/client/masking";
|
|
3
4
|
import type { DocumentationTypes as UtilityDocumentationTypes, NoInfer, VariablesOption } from "@apollo/client/utilities/internal";
|
|
4
|
-
type From<TData> = StoreObject | Reference | FragmentType<NoInfer<TData>> | string | null;
|
|
5
5
|
export declare namespace useSuspenseFragment {
|
|
6
6
|
import _self = useSuspenseFragment;
|
|
7
7
|
namespace Base {
|
|
@@ -19,7 +19,12 @@ export declare namespace useSuspenseFragment {
|
|
|
19
19
|
* `fragment` document then that fragment will be used.
|
|
20
20
|
*/
|
|
21
21
|
fragmentName?: string;
|
|
22
|
-
|
|
22
|
+
/**
|
|
23
|
+
* An object or array containing a `__typename` and primary key fields
|
|
24
|
+
* (such as `id`) identifying the entity object from which the fragment will
|
|
25
|
+
* be retrieved, or a `{ __ref: "..." }` reference, or a `string` ID (uncommon).
|
|
26
|
+
*/
|
|
27
|
+
from: useSuspenseFragment.FromValue<TData> | Array<useSuspenseFragment.FromValue<TData>>;
|
|
23
28
|
optimistic?: boolean;
|
|
24
29
|
/**
|
|
25
30
|
* The instance of `ApolloClient` to use to look up the fragment.
|
|
@@ -39,6 +44,10 @@ export declare namespace useSuspenseFragment {
|
|
|
39
44
|
}
|
|
40
45
|
}
|
|
41
46
|
}
|
|
47
|
+
/**
|
|
48
|
+
* Acceptable values provided to the `from` option.
|
|
49
|
+
*/
|
|
50
|
+
type FromValue<TData> = ApolloCache.WatchFragmentFromValue<TData>;
|
|
42
51
|
interface Result<TData> {
|
|
43
52
|
data: DataValue.Complete<MaybeMasked<TData>>;
|
|
44
53
|
}
|
|
@@ -56,8 +65,26 @@ export declare namespace useSuspenseFragment {
|
|
|
56
65
|
}
|
|
57
66
|
}
|
|
58
67
|
/** #TODO documentation */
|
|
68
|
+
export declare function useSuspenseFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: useSuspenseFragment.Options<TData, TVariables> & {
|
|
69
|
+
from: Array<NonNullable<useSuspenseFragment.FromValue<TData>>>;
|
|
70
|
+
}): useSuspenseFragment.Result<Array<TData>>;
|
|
71
|
+
/**
|
|
72
|
+
* #TODO documentation
|
|
73
|
+
*/
|
|
74
|
+
export declare function useSuspenseFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: useSuspenseFragment.Options<TData, TVariables> & {
|
|
75
|
+
from: Array<null>;
|
|
76
|
+
}): useSuspenseFragment.Result<Array<null>>;
|
|
77
|
+
/**
|
|
78
|
+
* #TODO documentation
|
|
79
|
+
*/
|
|
80
|
+
export declare function useSuspenseFragment<TData = unknown, TVariables extends OperationVariables = OperationVariables>(options: useSuspenseFragment.Options<TData, TVariables> & {
|
|
81
|
+
from: Array<useSuspenseFragment.FromValue<TData>>;
|
|
82
|
+
}): useSuspenseFragment.Result<Array<TData | null>>;
|
|
83
|
+
/**
|
|
84
|
+
* #TODO documentation
|
|
85
|
+
*/
|
|
59
86
|
export declare function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: useSuspenseFragment.Options<TData, TVariables> & {
|
|
60
|
-
from: NonNullable<
|
|
87
|
+
from: NonNullable<useSuspenseFragment.FromValue<TData>>;
|
|
61
88
|
}): useSuspenseFragment.Result<TData>;
|
|
62
89
|
/**
|
|
63
90
|
* #TODO documentation
|
|
@@ -69,11 +96,10 @@ export declare function useSuspenseFragment<TData, TVariables extends OperationV
|
|
|
69
96
|
* #TODO documentation
|
|
70
97
|
*/
|
|
71
98
|
export declare function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: useSuspenseFragment.Options<TData, TVariables> & {
|
|
72
|
-
from:
|
|
99
|
+
from: useSuspenseFragment.FromValue<TData>;
|
|
73
100
|
}): useSuspenseFragment.Result<TData | null>;
|
|
74
101
|
/**
|
|
75
102
|
* #TODO documentation
|
|
76
103
|
*/
|
|
77
104
|
export declare function useSuspenseFragment<TData, TVariables extends OperationVariables = OperationVariables>(options: useSuspenseFragment.Options<TData, TVariables>): useSuspenseFragment.Result<TData>;
|
|
78
|
-
export {};
|
|
79
105
|
//# sourceMappingURL=useSuspenseFragment.d.ts.map
|
|
@@ -2,9 +2,8 @@ import * as React from "react";
|
|
|
2
2
|
import { canonicalStringify } from "@apollo/client/cache";
|
|
3
3
|
import { getSuspenseCache } from "@apollo/client/react/internal";
|
|
4
4
|
import { __use } from "./internal/__use.js";
|
|
5
|
-
import { wrapHook } from "./internal/index.js";
|
|
5
|
+
import { useDeepMemo, wrapHook } from "./internal/index.js";
|
|
6
6
|
import { useApolloClient } from "./useApolloClient.js";
|
|
7
|
-
const NULL_PLACEHOLDER = [];
|
|
8
7
|
export function useSuspenseFragment(options) {
|
|
9
8
|
"use no memo";
|
|
10
9
|
return wrapHook("useSuspenseFragment",
|
|
@@ -15,15 +14,15 @@ function useSuspenseFragment_(options) {
|
|
|
15
14
|
const client = useApolloClient(options.client);
|
|
16
15
|
const { from, variables } = options;
|
|
17
16
|
const { cache } = client;
|
|
18
|
-
const
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
17
|
+
const ids = useDeepMemo(() => {
|
|
18
|
+
return Array.isArray(from) ?
|
|
19
|
+
from.map((id) => toStringId(cache, id))
|
|
20
|
+
: toStringId(cache, from);
|
|
21
|
+
}, [cache, from]);
|
|
22
|
+
const idString = React.useMemo(() => (Array.isArray(ids) ? ids.join(",") : ids), [ids]);
|
|
23
|
+
const fragmentRef = getSuspenseCache(client).getFragmentRef([options.fragment, canonicalStringify(variables), idString], client, { ...options, variables: variables, from: ids });
|
|
24
|
+
let [current, setPromise] = React.useState([fragmentRef.key, fragmentRef.promise]);
|
|
23
25
|
React.useEffect(() => {
|
|
24
|
-
if (fragmentRef === null) {
|
|
25
|
-
return;
|
|
26
|
-
}
|
|
27
26
|
const dispose = fragmentRef.retain();
|
|
28
27
|
const removeListener = fragmentRef.listen((promise) => {
|
|
29
28
|
setPromise([fragmentRef.key, promise]);
|
|
@@ -33,9 +32,6 @@ function useSuspenseFragment_(options) {
|
|
|
33
32
|
removeListener();
|
|
34
33
|
};
|
|
35
34
|
}, [fragmentRef]);
|
|
36
|
-
if (fragmentRef === null) {
|
|
37
|
-
return { data: null };
|
|
38
|
-
}
|
|
39
35
|
if (current[0] !== fragmentRef.key) {
|
|
40
36
|
// eslint-disable-next-line react-compiler/react-compiler
|
|
41
37
|
current[0] = fragmentRef.key;
|
|
@@ -44,4 +40,9 @@ function useSuspenseFragment_(options) {
|
|
|
44
40
|
const data = __use(current[1]);
|
|
45
41
|
return { data };
|
|
46
42
|
}
|
|
43
|
+
function toStringId(cache, from) {
|
|
44
|
+
return (typeof from === "string" ? from
|
|
45
|
+
: from === null ? null
|
|
46
|
+
: cache.identify(from));
|
|
47
|
+
}
|
|
47
48
|
//# sourceMappingURL=useSuspenseFragment.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useSuspenseFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useSuspenseFragment.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAW/B,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAG1D,OAAO,EAAE,gBAAgB,EAAE,MAAM,+BAA+B,CAAC;AAOjE,OAAO,EAAE,KAAK,EAAE,MAAM,qBAAqB,CAAC;AAC5C,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AA4EvD,MAAM,gBAAgB,GAAG,EAGxB,CAAC;AAwCF,MAAM,UAAU,mBAAmB,CAIjC,OAAuD;IAEvD,aAAa,CAAC;IACd,OAAO,QAAQ,CACb,qBAAqB;IACrB,yDAAyD;IACzD,oBAAoB,EACpB,eAAe,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAC1E,CAAC,OAAO,CAAC,CAAC;AACb,CAAC;AAED,SAAS,oBAAoB,CAI3B,OAAuD;IAEvD,MAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/C,MAAM,EAAE,IAAI,EAAE,SAAS,EAAE,GAAG,OAAO,CAAC;IACpC,MAAM,EAAE,KAAK,EAAE,GAAG,MAAM,CAAC;IAEzB,MAAM,EAAE,GAAG,KAAK,CAAC,OAAO,CACtB,GAAG,EAAE,CACH,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI;QAC/B,CAAC,CAAC,IA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ACxB,CAAC;IAED,IAAI,OAAO,CAAC,CAAC,CAAC,KAAK,WAAW,CAAC,GAAG,EAAE,CAAC;QACnC,yDAAyD;QACzD,OAAO,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC;QAC7B,OAAO,CAAC,CAAC,CAAC,GAAG,WAAW,CAAC,OAAO,CAAC;IACnC,CAAC;IAED,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAE/B,OAAO,EAAE,IAAI,EAAE,CAAC;AAClB,CAAC","sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataValue,\n DocumentNode,\n OperationVariables,\n Reference,\n StoreObject,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport { canonicalStringify } from \"@apollo/client/cache\";\nimport type { FragmentType, MaybeMasked } from \"@apollo/client/masking\";\nimport type { FragmentKey } from \"@apollo/client/react/internal\";\nimport { getSuspenseCache } from \"@apollo/client/react/internal\";\nimport type {\n DocumentationTypes as UtilityDocumentationTypes,\n NoInfer,\n VariablesOption,\n} from \"@apollo/client/utilities/internal\";\n\nimport { __use } from \"./internal/__use.js\";\nimport { wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\n\ntype From<TData> =\n | StoreObject\n | Reference\n | FragmentType<NoInfer<TData>>\n | string\n | null;\n\nexport declare namespace useSuspenseFragment {\n import _self = useSuspenseFragment;\n export namespace Base {\n export type Options<TData, TVariables extends OperationVariables> = {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to select a single.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n from: From<TData>;\n // Override this field to make it optional (default: true).\n optimistic?: boolean;\n /**\n * The instance of `ApolloClient` to use to look up the fragment.\n *\n * By default, the instance that's passed down via context is used, but you\n * can provide a different instance here.\n *\n * @docGroup 1. Operation options\n */\n client?: ApolloClient;\n };\n }\n export type Options<\n TData,\n TVariables extends OperationVariables,\n > = Base.Options<TData, TVariables> & VariablesOption<NoInfer<TVariables>>;\n\n export namespace DocumentationTypes {\n export namespace useSuspenseFragment {\n export interface Options<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Options<TData, TVariables>,\n UtilityDocumentationTypes.VariableOptions<TVariables> {}\n }\n }\n\n export interface Result<TData> {\n data: DataValue.Complete<MaybeMasked<TData>>;\n }\n export namespace DocumentationTypes {\n export namespace useSuspenseFragment {\n export interface Result<TData = unknown> extends _self.Result<TData> {}\n }\n }\n\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\n export function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n >(\n options: useSuspenseFragment.Options<TData, TVariables>\n ): useSuspenseFragment.Result<TData>;\n }\n}\n\nconst NULL_PLACEHOLDER = [] as unknown as [\n FragmentKey,\n Promise<MaybeMasked<any> | null>,\n];\n\n/** #TODO documentation */\nexport function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: NonNullable<From<TData>>;\n }\n): useSuspenseFragment.Result<TData>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: null;\n }\n): useSuspenseFragment.Result<null>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: From<TData>;\n }\n): useSuspenseFragment.Result<TData | null>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables>\n): useSuspenseFragment.Result<TData>;\n\nexport function useSuspenseFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables>\n): useSuspenseFragment.Result<TData | null> {\n \"use no memo\";\n return wrapHook(\n \"useSuspenseFragment\",\n // eslint-disable-next-line react-compiler/react-compiler\n useSuspenseFragment_,\n useApolloClient(typeof options === \"object\" ? options.client : undefined)\n )(options);\n}\n\nfunction useSuspenseFragment_<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables>\n): useSuspenseFragment.Result<TData | null> {\n const client = useApolloClient(options.client);\n const { from, variables } = options;\n const { cache } = client;\n\n const id = React.useMemo(\n () =>\n typeof from === \"string\" ? from\n : from === null ? null\n : cache.identify(from),\n [cache, from]\n ) as string | null;\n\n const fragmentRef =\n id === null ? null : (\n getSuspenseCache(client).getFragmentRef(\n [id, options.fragment, canonicalStringify(variables)],\n client,\n { ...options, variables: variables as TVariables, from: id }\n )\n );\n\n let [current, setPromise] = React.useState<\n [FragmentKey, Promise<MaybeMasked<TData> | null>]\n >(\n fragmentRef === null ? NULL_PLACEHOLDER : (\n [fragmentRef.key, fragmentRef.promise]\n )\n );\n\n React.useEffect(() => {\n if (fragmentRef === null) {\n return;\n }\n\n const dispose = fragmentRef.retain();\n const removeListener = fragmentRef.listen((promise) => {\n setPromise([fragmentRef.key, promise]);\n });\n\n return () => {\n dispose();\n removeListener();\n };\n }, [fragmentRef]);\n\n if (fragmentRef === null) {\n return { data: null };\n }\n\n if (current[0] !== fragmentRef.key) {\n // eslint-disable-next-line react-compiler/react-compiler\n current[0] = fragmentRef.key;\n current[1] = fragmentRef.promise;\n }\n\n const data = __use(current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G,WAAW,CAAC,OAAO,CAAC;IACnC,CAAC;IAED,MAAM,IAAI,GAAG,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC,CAAC;IAE/B,OAAO,EAAE,IAAI,EAAE,CAAC;AAClB,CAAC;AAED,SAAS,UAAU,CACjB,KAAkB,EAClB,IAAwC;IAExC,OAAO,CACL,OAAO,IAAI,KAAK,QAAQ,CAAC,CAAC,CAAC,IAAI;QAC/B,CAAC,CAAC,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,IAAI;YACtB,CAAC,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,CAAkB,CAAC;AAC7C,CAAC","sourcesContent":["import * as React from \"react\";\n\nimport type {\n ApolloClient,\n DataValue,\n DocumentNode,\n OperationVariables,\n TypedDocumentNode,\n} from \"@apollo/client\";\nimport type { ApolloCache } from \"@apollo/client/cache\";\nimport { canonicalStringify } from \"@apollo/client/cache\";\nimport type { MaybeMasked } from \"@apollo/client/masking\";\nimport type { FragmentKey } from \"@apollo/client/react/internal\";\nimport { getSuspenseCache } from \"@apollo/client/react/internal\";\nimport type {\n DocumentationTypes as UtilityDocumentationTypes,\n NoInfer,\n VariablesOption,\n} from \"@apollo/client/utilities/internal\";\n\nimport { __use } from \"./internal/__use.js\";\nimport { useDeepMemo, wrapHook } from \"./internal/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\n\nexport declare namespace useSuspenseFragment {\n import _self = useSuspenseFragment;\n export namespace Base {\n export type Options<TData, TVariables extends OperationVariables> = {\n /**\n * A GraphQL document created using the `gql` template string tag from\n * `graphql-tag` with one or more fragments which will be used to determine\n * the shape of data to read. If you provide more than one fragment in this\n * document then you must also specify `fragmentName` to select a single.\n */\n fragment: DocumentNode | TypedDocumentNode<TData, TVariables>;\n\n /**\n * The name of the fragment in your GraphQL document to be used. If you do\n * not provide a `fragmentName` and there is only one fragment in your\n * `fragment` document then that fragment will be used.\n */\n fragmentName?: string;\n\n /**\n * An object or array containing a `__typename` and primary key fields\n * (such as `id`) identifying the entity object from which the fragment will\n * be retrieved, or a `{ __ref: \"...\" }` reference, or a `string` ID (uncommon).\n */\n from:\n | useSuspenseFragment.FromValue<TData>\n | Array<useSuspenseFragment.FromValue<TData>>;\n\n // Override this field to make it optional (default: true).\n optimistic?: boolean;\n /**\n * The instance of `ApolloClient` to use to look up the fragment.\n *\n * By default, the instance that's passed down via context is used, but you\n * can provide a different instance here.\n *\n * @docGroup 1. Operation options\n */\n client?: ApolloClient;\n };\n }\n export type Options<\n TData,\n TVariables extends OperationVariables,\n > = Base.Options<TData, TVariables> & VariablesOption<NoInfer<TVariables>>;\n\n export namespace DocumentationTypes {\n export namespace useSuspenseFragment {\n export interface Options<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n > extends Base.Options<TData, TVariables>,\n UtilityDocumentationTypes.VariableOptions<TVariables> {}\n }\n }\n\n /**\n * Acceptable values provided to the `from` option.\n */\n export type FromValue<TData> = ApolloCache.WatchFragmentFromValue<TData>;\n\n export interface Result<TData> {\n data: DataValue.Complete<MaybeMasked<TData>>;\n }\n export namespace DocumentationTypes {\n export namespace useSuspenseFragment {\n export interface Result<TData = unknown> extends _self.Result<TData> {}\n }\n }\n\n export namespace DocumentationTypes {\n /** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\n export function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n >(\n options: useSuspenseFragment.Options<TData, TVariables>\n ): useSuspenseFragment.Result<TData>;\n }\n}\n\n/** #TODO documentation */\nexport function useSuspenseFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: Array<NonNullable<useSuspenseFragment.FromValue<TData>>>;\n }\n): useSuspenseFragment.Result<Array<TData>>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: Array<null>;\n }\n): useSuspenseFragment.Result<Array<null>>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: Array<useSuspenseFragment.FromValue<TData>>;\n }\n): useSuspenseFragment.Result<Array<TData | null>>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: NonNullable<useSuspenseFragment.FromValue<TData>>;\n }\n): useSuspenseFragment.Result<TData>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: null;\n }\n): useSuspenseFragment.Result<null>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables> & {\n from: useSuspenseFragment.FromValue<TData>;\n }\n): useSuspenseFragment.Result<TData | null>;\n\n/** {@inheritDoc @apollo/client/react!useSuspenseFragment:function(1)} */\nexport function useSuspenseFragment<\n TData,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables>\n): useSuspenseFragment.Result<TData>;\n\nexport function useSuspenseFragment<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables>\n): useSuspenseFragment.Result<TData | null> {\n \"use no memo\";\n return wrapHook(\n \"useSuspenseFragment\",\n // eslint-disable-next-line react-compiler/react-compiler\n useSuspenseFragment_,\n useApolloClient(typeof options === \"object\" ? options.client : undefined)\n )(options);\n}\n\nfunction useSuspenseFragment_<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n options: useSuspenseFragment.Options<TData, TVariables>\n): useSuspenseFragment.Result<TData | null> {\n const client = useApolloClient(options.client);\n const { from, variables } = options;\n const { cache } = client;\n\n const ids = useDeepMemo(() => {\n return Array.isArray(from) ?\n from.map((id) => toStringId(cache, id))\n : toStringId(cache, from);\n }, [cache, from]);\n const idString = React.useMemo(\n () => (Array.isArray(ids) ? ids.join(\",\") : ids),\n [ids]\n );\n\n const fragmentRef = getSuspenseCache(client).getFragmentRef(\n [options.fragment, canonicalStringify(variables), idString],\n client,\n { ...options, variables: variables as TVariables, from: ids }\n );\n\n let [current, setPromise] = React.useState<\n [FragmentKey, Promise<MaybeMasked<TData> | null>]\n >([fragmentRef.key, fragmentRef.promise]);\n\n React.useEffect(() => {\n const dispose = fragmentRef.retain();\n const removeListener = fragmentRef.listen((promise) => {\n setPromise([fragmentRef.key, promise]);\n });\n\n return () => {\n dispose();\n removeListener();\n };\n }, [fragmentRef]);\n\n if (current[0] !== fragmentRef.key) {\n // eslint-disable-next-line react-compiler/react-compiler\n current[0] = fragmentRef.key;\n current[1] = fragmentRef.promise;\n }\n\n const data = __use(current[1]);\n\n return { data };\n}\n\nfunction toStringId(\n cache: ApolloCache,\n from: useSuspenseFragment.FromValue<any>\n) {\n return (\n typeof from === \"string\" ? from\n : from === null ? null\n : cache.identify(from)) as string | null;\n}\n"]}
|