@apollo/client 3.12.6 → 3.12.7
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 +16 -0
- package/apollo-client.cjs +17 -13
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/cache/index.d.ts +1 -1
- package/cache/index.js +0 -1
- package/cache/index.js.map +1 -1
- package/core/core.cjs +1 -1
- package/core/core.cjs.map +1 -1
- package/core/core.cjs.native.js +1 -1
- package/core/index.d.ts +2 -2
- package/core/index.js +0 -2
- package/core/index.js.map +1 -1
- package/dev/dev.cjs +1 -1
- package/dev/dev.cjs.map +1 -1
- package/dev/dev.cjs.native.js +1 -1
- package/errors/index.js.map +1 -1
- package/link/core/index.d.ts +1 -1
- package/link/core/index.js +0 -1
- package/link/core/index.js.map +1 -1
- package/link/core/types.d.ts +2 -2
- package/link/core/types.js.map +1 -1
- package/link/error/error.cjs +17 -8
- package/link/error/error.cjs.map +1 -1
- package/link/error/error.cjs.native.js +17 -8
- package/link/error/index.d.ts +17 -1
- package/link/error/index.js +17 -8
- package/link/error/index.js.map +1 -1
- package/link/persisted-queries/index.d.ts +2 -2
- package/package.json +28 -23
- package/react/components/index.d.ts +1 -1
- package/react/components/index.js +0 -1
- package/react/components/index.js.map +1 -1
- package/react/hoc/index.d.ts +1 -1
- package/react/hoc/index.js +0 -1
- package/react/hoc/index.js.map +1 -1
- package/react/hooks/hooks.cjs +16 -12
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/hooks.cjs.native.js +16 -12
- package/react/hooks/internal/useDeepMemo.js +1 -0
- package/react/hooks/internal/useDeepMemo.js.map +1 -1
- package/react/hooks/useBackgroundQuery.js +4 -2
- package/react/hooks/useBackgroundQuery.js.map +1 -1
- package/react/hooks/useFragment.js +4 -2
- package/react/hooks/useFragment.js.map +1 -1
- package/react/hooks/useMutation.js +1 -0
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.js +5 -2
- package/react/hooks/useQuery.js.map +1 -1
- package/react/hooks/useQueryRefHandlers.js +2 -2
- package/react/hooks/useQueryRefHandlers.js.map +1 -1
- package/react/hooks/useReadQuery.js +2 -2
- package/react/hooks/useReadQuery.js.map +1 -1
- package/react/hooks/useSubscription.js +1 -0
- package/react/hooks/useSubscription.js.map +1 -1
- package/react/hooks/useSuspenseQuery.js +5 -2
- package/react/hooks/useSuspenseQuery.js.map +1 -1
- package/react/index.d.ts +1 -1
- package/react/index.js +0 -1
- package/react/index.js.map +1 -1
- package/react/internal/internal.cjs +1 -1
- package/react/internal/internal.cjs.map +1 -1
- package/react/internal/internal.cjs.native.js +1 -1
- package/testing/internal/incremental.d.ts +23 -0
- package/testing/internal/incremental.js +124 -0
- package/testing/internal/incremental.js.map +1 -0
- package/testing/internal/index.d.ts +1 -0
- package/testing/internal/index.js +1 -0
- package/testing/internal/index.js.map +1 -1
- package/testing/internal/scenarios/index.d.ts +1 -0
- package/testing/internal/scenarios/index.js.map +1 -1
- package/testing/matchers/index.js +4 -0
- package/testing/matchers/index.js.map +1 -1
- package/testing/matchers/toEqualApolloQueryResult.d.ts +6 -0
- package/testing/matchers/toEqualApolloQueryResult.js +20 -0
- package/testing/matchers/toEqualApolloQueryResult.js.map +1 -0
- package/testing/matchers/toEqualQueryResult.d.ts +9 -0
- package/testing/matchers/toEqualQueryResult.js +40 -0
- package/testing/matchers/toEqualQueryResult.js.map +1 -0
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/utilities/globals/globals.cjs.native.js +1 -1
- package/utilities/index.d.ts +1 -1
- package/utilities/index.js +0 -1
- package/utilities/index.js.map +1 -1
- package/version.js +1 -1
|
@@ -148,9 +148,10 @@ function noop() { }
|
|
|
148
148
|
var lastWatchOptions = Symbol();
|
|
149
149
|
function useQuery(query, options) {
|
|
150
150
|
if (options === void 0) { options = Object.create(null); }
|
|
151
|
-
return wrapHook("useQuery",
|
|
151
|
+
return wrapHook("useQuery",
|
|
152
|
+
useQuery_, useApolloClient(options && options.client))(query, options);
|
|
152
153
|
}
|
|
153
|
-
function
|
|
154
|
+
function useQuery_(query, options) {
|
|
154
155
|
var _a = useQueryInternals(query, options), result = _a.result, obsQueryFields = _a.obsQueryFields;
|
|
155
156
|
return React__namespace.useMemo(function () { return (tslib.__assign(tslib.__assign({}, result), obsQueryFields)); }, [result, obsQueryFields]);
|
|
156
157
|
}
|
|
@@ -821,9 +822,10 @@ function useReactiveVar(rv) {
|
|
|
821
822
|
}
|
|
822
823
|
|
|
823
824
|
function useFragment(options) {
|
|
824
|
-
return wrapHook("useFragment",
|
|
825
|
+
return wrapHook("useFragment",
|
|
826
|
+
useFragment_, useApolloClient(options.client))(options);
|
|
825
827
|
}
|
|
826
|
-
function
|
|
828
|
+
function useFragment_(options) {
|
|
827
829
|
var client = useApolloClient(options.client);
|
|
828
830
|
var cache = client.cache;
|
|
829
831
|
var from = options.from, rest = tslib.__rest(options, ["from"]);
|
|
@@ -888,9 +890,10 @@ var skipToken = Symbol.for("apollo.skipToken");
|
|
|
888
890
|
|
|
889
891
|
function useSuspenseQuery(query, options) {
|
|
890
892
|
if (options === void 0) { options = Object.create(null); }
|
|
891
|
-
return wrapHook("useSuspenseQuery",
|
|
893
|
+
return wrapHook("useSuspenseQuery",
|
|
894
|
+
useSuspenseQuery_, useApolloClient(typeof options === "object" ? options.client : undefined))(query, options);
|
|
892
895
|
}
|
|
893
|
-
function
|
|
896
|
+
function useSuspenseQuery_(query, options) {
|
|
894
897
|
var client = useApolloClient(options.client);
|
|
895
898
|
var suspenseCache = internal.getSuspenseCache(client);
|
|
896
899
|
var watchQueryOptions = useWatchQueryOptions({
|
|
@@ -1008,9 +1011,10 @@ function useWatchQueryOptions(_a) {
|
|
|
1008
1011
|
|
|
1009
1012
|
function useBackgroundQuery(query, options) {
|
|
1010
1013
|
if (options === void 0) { options = Object.create(null); }
|
|
1011
|
-
return wrapHook("useBackgroundQuery",
|
|
1014
|
+
return wrapHook("useBackgroundQuery",
|
|
1015
|
+
useBackgroundQuery_, useApolloClient(typeof options === "object" ? options.client : undefined))(query, options);
|
|
1012
1016
|
}
|
|
1013
|
-
function
|
|
1017
|
+
function useBackgroundQuery_(query, options) {
|
|
1014
1018
|
var client = useApolloClient(options.client);
|
|
1015
1019
|
var suspenseCache = internal.getSuspenseCache(client);
|
|
1016
1020
|
var watchQueryOptions = useWatchQueryOptions({ client: client, query: query, options: options });
|
|
@@ -1127,11 +1131,11 @@ function useLoadableQuery(query, options) {
|
|
|
1127
1131
|
|
|
1128
1132
|
function useQueryRefHandlers(queryRef) {
|
|
1129
1133
|
var unwrapped = internal.unwrapQueryRef(queryRef);
|
|
1130
|
-
return wrapHook("useQueryRefHandlers",
|
|
1134
|
+
return wrapHook("useQueryRefHandlers", useQueryRefHandlers_, unwrapped ?
|
|
1131
1135
|
unwrapped["observable"]
|
|
1132
1136
|
: useApolloClient())(queryRef);
|
|
1133
1137
|
}
|
|
1134
|
-
function
|
|
1138
|
+
function useQueryRefHandlers_(queryRef) {
|
|
1135
1139
|
internal.assertWrappedQueryRef(queryRef);
|
|
1136
1140
|
var _a = React__namespace.useState(queryRef), previousQueryRef = _a[0], setPreviousQueryRef = _a[1];
|
|
1137
1141
|
var _b = React__namespace.useState(queryRef), wrappedQueryRef = _b[0], setWrappedQueryRef = _b[1];
|
|
@@ -1162,11 +1166,11 @@ function _useQueryRefHandlers(queryRef) {
|
|
|
1162
1166
|
|
|
1163
1167
|
function useReadQuery(queryRef) {
|
|
1164
1168
|
var unwrapped = internal.unwrapQueryRef(queryRef);
|
|
1165
|
-
return wrapHook("useReadQuery",
|
|
1169
|
+
return wrapHook("useReadQuery", useReadQuery_, unwrapped ?
|
|
1166
1170
|
unwrapped["observable"]
|
|
1167
1171
|
: useApolloClient())(queryRef);
|
|
1168
1172
|
}
|
|
1169
|
-
function
|
|
1173
|
+
function useReadQuery_(queryRef) {
|
|
1170
1174
|
internal.assertWrappedQueryRef(queryRef);
|
|
1171
1175
|
var internalQueryRef = React__namespace.useMemo(function () { return internal.unwrapQueryRef(queryRef); }, [queryRef]);
|
|
1172
1176
|
var getPromise = React__namespace.useCallback(function () { return internal.getWrappedPromise(queryRef); }, [queryRef]);
|
|
@@ -3,6 +3,7 @@ import { equal } from "@wry/equality";
|
|
|
3
3
|
export function useDeepMemo(memoFn, deps) {
|
|
4
4
|
var ref = React.useRef(void 0);
|
|
5
5
|
if (!ref.current || !equal(ref.current.deps, deps)) {
|
|
6
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
6
7
|
ref.current = { value: memoFn(), deps: deps };
|
|
7
8
|
}
|
|
8
9
|
return ref.current.value;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useDeepMemo.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useDeepMemo.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,MAAM,UAAU,WAAW,CACzB,MAAoB,EACpB,IAAoB;IAEpB,IAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAA0C,KAAK,CAAC,CAAC,CAAC;IAE1E,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QACnD,GAAG,CAAC,OAAO,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,MAAA,EAAE,CAAC;IAC1C,CAAC;IAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC;AAC3B,CAAC","sourcesContent":["import type { DependencyList } from \"react\";\nimport * as React from \"rehackt\";\nimport { equal } from \"@wry/equality\";\n\nexport function useDeepMemo<TValue>(\n memoFn: () => TValue,\n deps: DependencyList\n) {\n const ref = React.useRef<{ deps: DependencyList; value: TValue }>(void 0);\n\n if (!ref.current || !equal(ref.current.deps, deps)) {\n ref.current = { value: memoFn(), deps };\n }\n\n return ref.current.value;\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useDeepMemo.js","sourceRoot":"","sources":["../../../../src/react/hooks/internal/useDeepMemo.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,MAAM,UAAU,WAAW,CACzB,MAAoB,EACpB,IAAoB;IAEpB,IAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAA0C,KAAK,CAAC,CAAC,CAAC;IAE1E,IAAI,CAAC,GAAG,CAAC,OAAO,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,IAAI,EAAE,IAAI,CAAC,EAAE,CAAC;QACnD,yDAAyD;QACzD,GAAG,CAAC,OAAO,GAAG,EAAE,KAAK,EAAE,MAAM,EAAE,EAAE,IAAI,MAAA,EAAE,CAAC;IAC1C,CAAC;IAED,OAAO,GAAG,CAAC,OAAO,CAAC,KAAK,CAAC;AAC3B,CAAC","sourcesContent":["import type { DependencyList } from \"react\";\nimport * as React from \"rehackt\";\nimport { equal } from \"@wry/equality\";\n\nexport function useDeepMemo<TValue>(\n memoFn: () => TValue,\n deps: DependencyList\n) {\n const ref = React.useRef<{ deps: DependencyList; value: TValue }>(void 0);\n\n if (!ref.current || !equal(ref.current.deps, deps)) {\n // eslint-disable-next-line react-compiler/react-compiler\n ref.current = { value: memoFn(), deps };\n }\n\n return ref.current.value;\n}\n"]}
|
|
@@ -7,9 +7,11 @@ import { useWatchQueryOptions } from "./useSuspenseQuery.js";
|
|
|
7
7
|
import { canonicalStringify } from "../../cache/index.js";
|
|
8
8
|
export function useBackgroundQuery(query, options) {
|
|
9
9
|
if (options === void 0) { options = Object.create(null); }
|
|
10
|
-
return wrapHook("useBackgroundQuery",
|
|
10
|
+
return wrapHook("useBackgroundQuery",
|
|
11
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
12
|
+
useBackgroundQuery_, useApolloClient(typeof options === "object" ? options.client : undefined))(query, options);
|
|
11
13
|
}
|
|
12
|
-
function
|
|
14
|
+
function useBackgroundQuery_(query, options) {
|
|
13
15
|
var client = useApolloClient(options.client);
|
|
14
16
|
var suspenseCache = getSuspenseCache(client);
|
|
15
17
|
var watchQueryOptions = useWatchQueryOptions({ client: client, query: query, options: options });
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useBackgroundQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useBackgroundQuery.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAQjC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,YAAY,GACb,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAM7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAyJ1D,MAAM,UAAU,kBAAkB,CAIhC,KAA0D,EAC1D,OAG8E;IAH9E,wBAAA,EAAA,UAG2D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IAK9E,OAAO,QAAQ,CACb,oBAAoB,EACpB,mBAAmB,EACnB,eAAe,CAAC,OAAO,OAAO,KAAK,QAAQ,CAAC,CAAC,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,SAAS,CAAC,CAC1E,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;AACpB,CAAC;AAED,SAAS,mBAAmB,CAI1B,KAA0D,EAC1D,OAGwD;IAKxD,IAAM,MAAM,GAAG,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAAC;IAC/C,IAAM,aAAa,GAAG,gBAAgB,CAAC,MAAM,CAAC,CAAC;IAC/C,IA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SACrD;KACF,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type {\n DocumentNode,\n FetchMoreQueryOptions,\n OperationVariables,\n TypedDocumentNode,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport {\n getSuspenseCache,\n unwrapQueryRef,\n updateWrappedQueryRef,\n wrapQueryRef,\n} from \"../internal/index.js\";\nimport type { CacheKey, QueryRef } from \"../internal/index.js\";\nimport type { BackgroundQueryHookOptions, NoInfer } from \"../types/types.js\";\nimport { wrapHook } from \"./internal/index.js\";\nimport { useWatchQueryOptions } from \"./useSuspenseQuery.js\";\nimport type {\n FetchMoreFunction,\n RefetchFunction,\n SubscribeToMoreFunction,\n} from \"./useSuspenseQuery.js\";\nimport { canonicalStringify } from \"../../cache/index.js\";\nimport type { DeepPartial } from \"../../utilities/index.js\";\nimport type { SkipToken } from \"./constants.js\";\n\nexport type UseBackgroundQueryResult<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n> = {\n /** {@inheritDoc @apollo/client!ObservableQuery#subscribeToMore:member(1)} */\n subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;\n /** {@inheritDoc @apollo/client!ObservableQuery#fetchMore:member(1)} */\n fetchMore: FetchMoreFunction<TData, TVariables>;\n /** {@inheritDoc @apollo/client!ObservableQuery#refetch:member(1)} */\n refetch: RefetchFunction<TData, TVariables>;\n};\n\ntype BackgroundQueryHookOptionsNoInfer<\n TData,\n TVariables extends OperationVariables,\n> = BackgroundQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>;\n\nexport function useBackgroundQuery<\n TData,\n TVariables extends OperationVariables,\n TOptions extends Omit<BackgroundQueryHookOptions<TData>, \"variables\">,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & TOptions\n): [\n (\n | QueryRef<\n TOptions[\"errorPolicy\"] extends \"ignore\" | \"all\" ?\n TOptions[\"returnPartialData\"] extends true ?\n DeepPartial<TData> | undefined\n : TData | undefined\n : TOptions[\"returnPartialData\"] extends true ? DeepPartial<TData>\n : TData,\n TVariables\n >\n | (TOptions[\"skip\"] extends boolean ? undefined : never)\n ),\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<DeepPartial<TData> | undefined, TVariables>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<TData | undefined, TVariables>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n skip: boolean;\n returnPartialData: true;\n }\n): [\n QueryRef<DeepPartial<TData>, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n }\n): [\n QueryRef<DeepPartial<TData>, TVariables>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n skip: boolean;\n }\n): [\n QueryRef<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables>\n): [QueryRef<TData, TVariables>, UseBackgroundQueryResult<TData, TVariables>];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken\n): [undefined, UseBackgroundQueryResult<TData, TVariables>];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n })\n): [\n QueryRef<DeepPartial<TData>, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SkipToken | BackgroundQueryHookOptionsNoInfer<TData, TVariables>\n): [\n QueryRef<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken &\n Partial<BackgroundQueryHookOptionsNoInfer<TData, TVariables>>)\n | BackgroundQueryHookOptionsNoInfer<TData, TVariables> = Object.create(null)\n): [\n QueryRef<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n] {\n return wrapHook(\n \"useBackgroundQuery\",\n _useBackgroundQuery,\n useApolloClient(typeof options === \"object\" ? options.client : undefined)\n )(query, options);\n}\n\nfunction _useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken &\n Partial<BackgroundQueryHookOptionsNoInfer<TData, TVariables>>)\n | BackgroundQueryHookOptionsNoInfer<TData, TVariables>\n): [\n QueryRef<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n] {\n const client = useApolloClient(options.client);\n const suspenseCache = getSuspenseCache(client);\n const watchQueryOptions = useWatchQueryOptions({ client, query, options });\n const { fetchPolicy, variables } = watchQueryOptions;\n const { queryKey = [] } = options;\n\n // This ref tracks the first time query execution is enabled to determine\n // whether to return a query ref or `undefined`. When initialized\n // in a skipped state (either via `skip: true` or `skipToken`) we return\n // `undefined` for the `queryRef` until the query has been enabled. Once\n // enabled, a query ref is always returned regardless of whether the query is\n // skipped again later.\n const didFetchResult = React.useRef(fetchPolicy !== \"standby\");\n didFetchResult.current ||= fetchPolicy !== \"standby\";\n\n const cacheKey: CacheKey = [\n query,\n canonicalStringify(variables),\n ...([] as any[]).concat(queryKey),\n ];\n\n const queryRef = suspenseCache.getQueryRef(cacheKey, () =>\n client.watchQuery(watchQueryOptions as WatchQueryOptions<any, any>)\n );\n\n const [wrappedQueryRef, setWrappedQueryRef] = React.useState(\n wrapQueryRef(queryRef)\n );\n if (unwrapQueryRef(wrappedQueryRef) !== queryRef) {\n setWrappedQueryRef(wrapQueryRef(queryRef));\n }\n if (queryRef.didChangeOptions(watchQueryOptions)) {\n const promise = queryRef.applyOptions(watchQueryOptions);\n updateWrappedQueryRef(wrappedQueryRef, promise);\n }\n\n // This prevents issues where rerendering useBackgroundQuery after the\n // queryRef has been disposed would cause the hook to return a new queryRef\n // instance since disposal also removes it from the suspense cache. We add\n // the queryRef back in the suspense cache so that the next render will reuse\n // this queryRef rather than initializing a new instance.\n React.useEffect(() => {\n // Since the queryRef is disposed async via `setTimeout`, we have to wait a\n // tick before checking it and adding back to the suspense cache.\n const id = setTimeout(() => {\n if (queryRef.disposed) {\n suspenseCache.add(cacheKey, queryRef);\n }\n });\n\n return () => clearTimeout(id);\n // Omitting the deps is intentional. This avoids stale closures and the\n // conditional ensures we aren't running the logic on each render.\n });\n\n const fetchMore: FetchMoreFunction<TData, TVariables> = React.useCallback(\n (options) => {\n const promise = queryRef.fetchMore(options as FetchMoreQueryOptions<any>);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n const refetch: RefetchFunction<TData, TVariables> = React.useCallback(\n (variables) => {\n const promise = queryRef.refetch(variables);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n React.useEffect(() => queryRef.softRetain(), [queryRef]);\n\n return [\n didFetchResult.current ? wrappedQueryRef : void 0,\n {\n fetchMore,\n refetch,\n subscribeToMore: queryRef.observable.subscribeToMore,\n },\n ];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useBackgroundQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useBackgroundQuery.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAQjC,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,gBAAgB,EAChB,cAAc,EACd,qBAAqB,EACrB,YAAY,GACb,MAAM,sBAAsB,CAAC;AAG9B,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC/C,OAAO,EAAE,oBAAoB,EAAE,MAAM,uBAAuB,CAAC;AAM7D,OAAO,EAAE,kBAAkB,EAAE,MAAM,sBAAsB,CAAC;AAyJ1D,MAAM,UAAU,kBAAkB,CAIhC,KAA0D,EAC1D,OAG8E;IAH9E,wBAAA,EAAA,UAG2D,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IAK9E,OAAO,QAAQ,CACb,oBAAoB;IACpB,yDAAyD;IACz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AO,OAAO,CAAC;IACjB,CAAC,EACD,CAAC,QAAQ,CAAC,CACX,CAAC;IAEF,KAAK,CAAC,SAAS,CAAC,cAAM,OAAA,QAAQ,CAAC,UAAU,EAAE,EAArB,CAAqB,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEzD,OAAO;QACL,cAAc,CAAC,OAAO,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC,CAAC,KAAK,CAAC;QACjD;YACE,SAAS,WAAA;YACT,OAAO,SAAA;YACP,eAAe,EAAE,QAAQ,CAAC,UAAU,CAAC,eAAe;SACrD;KACF,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type {\n DocumentNode,\n FetchMoreQueryOptions,\n OperationVariables,\n TypedDocumentNode,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport {\n getSuspenseCache,\n unwrapQueryRef,\n updateWrappedQueryRef,\n wrapQueryRef,\n} from \"../internal/index.js\";\nimport type { CacheKey, QueryRef } from \"../internal/index.js\";\nimport type { BackgroundQueryHookOptions, NoInfer } from \"../types/types.js\";\nimport { wrapHook } from \"./internal/index.js\";\nimport { useWatchQueryOptions } from \"./useSuspenseQuery.js\";\nimport type {\n FetchMoreFunction,\n RefetchFunction,\n SubscribeToMoreFunction,\n} from \"./useSuspenseQuery.js\";\nimport { canonicalStringify } from \"../../cache/index.js\";\nimport type { DeepPartial } from \"../../utilities/index.js\";\nimport type { SkipToken } from \"./constants.js\";\n\nexport type UseBackgroundQueryResult<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n> = {\n /** {@inheritDoc @apollo/client!ObservableQuery#subscribeToMore:member(1)} */\n subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;\n /** {@inheritDoc @apollo/client!ObservableQuery#fetchMore:member(1)} */\n fetchMore: FetchMoreFunction<TData, TVariables>;\n /** {@inheritDoc @apollo/client!ObservableQuery#refetch:member(1)} */\n refetch: RefetchFunction<TData, TVariables>;\n};\n\ntype BackgroundQueryHookOptionsNoInfer<\n TData,\n TVariables extends OperationVariables,\n> = BackgroundQueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>;\n\nexport function useBackgroundQuery<\n TData,\n TVariables extends OperationVariables,\n TOptions extends Omit<BackgroundQueryHookOptions<TData>, \"variables\">,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & TOptions\n): [\n (\n | QueryRef<\n TOptions[\"errorPolicy\"] extends \"ignore\" | \"all\" ?\n TOptions[\"returnPartialData\"] extends true ?\n DeepPartial<TData> | undefined\n : TData | undefined\n : TOptions[\"returnPartialData\"] extends true ? DeepPartial<TData>\n : TData,\n TVariables\n >\n | (TOptions[\"skip\"] extends boolean ? undefined : never)\n ),\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<DeepPartial<TData> | undefined, TVariables>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n errorPolicy: \"ignore\" | \"all\";\n }\n): [\n QueryRef<TData | undefined, TVariables>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n skip: boolean;\n returnPartialData: true;\n }\n): [\n QueryRef<DeepPartial<TData>, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n }\n): [\n QueryRef<DeepPartial<TData>, TVariables>,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n skip: boolean;\n }\n): [\n QueryRef<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: BackgroundQueryHookOptionsNoInfer<TData, TVariables>\n): [QueryRef<TData, TVariables>, UseBackgroundQueryResult<TData, TVariables>];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: SkipToken\n): [undefined, UseBackgroundQueryResult<TData, TVariables>];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | SkipToken\n | (BackgroundQueryHookOptionsNoInfer<TData, TVariables> & {\n returnPartialData: true;\n })\n): [\n QueryRef<DeepPartial<TData>, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: SkipToken | BackgroundQueryHookOptionsNoInfer<TData, TVariables>\n): [\n QueryRef<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n];\n\nexport function useBackgroundQuery<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken &\n Partial<BackgroundQueryHookOptionsNoInfer<TData, TVariables>>)\n | BackgroundQueryHookOptionsNoInfer<TData, TVariables> = Object.create(null)\n): [\n QueryRef<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n] {\n return wrapHook(\n \"useBackgroundQuery\",\n // eslint-disable-next-line react-compiler/react-compiler\n useBackgroundQuery_,\n useApolloClient(typeof options === \"object\" ? options.client : undefined)\n )(query, options);\n}\n\nfunction useBackgroundQuery_<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options:\n | (SkipToken &\n Partial<BackgroundQueryHookOptionsNoInfer<TData, TVariables>>)\n | BackgroundQueryHookOptionsNoInfer<TData, TVariables>\n): [\n QueryRef<TData, TVariables> | undefined,\n UseBackgroundQueryResult<TData, TVariables>,\n] {\n const client = useApolloClient(options.client);\n const suspenseCache = getSuspenseCache(client);\n const watchQueryOptions = useWatchQueryOptions({ client, query, options });\n const { fetchPolicy, variables } = watchQueryOptions;\n const { queryKey = [] } = options;\n\n // This ref tracks the first time query execution is enabled to determine\n // whether to return a query ref or `undefined`. When initialized\n // in a skipped state (either via `skip: true` or `skipToken`) we return\n // `undefined` for the `queryRef` until the query has been enabled. Once\n // enabled, a query ref is always returned regardless of whether the query is\n // skipped again later.\n const didFetchResult = React.useRef(fetchPolicy !== \"standby\");\n didFetchResult.current ||= fetchPolicy !== \"standby\";\n\n const cacheKey: CacheKey = [\n query,\n canonicalStringify(variables),\n ...([] as any[]).concat(queryKey),\n ];\n\n const queryRef = suspenseCache.getQueryRef(cacheKey, () =>\n client.watchQuery(watchQueryOptions as WatchQueryOptions<any, any>)\n );\n\n const [wrappedQueryRef, setWrappedQueryRef] = React.useState(\n wrapQueryRef(queryRef)\n );\n if (unwrapQueryRef(wrappedQueryRef) !== queryRef) {\n setWrappedQueryRef(wrapQueryRef(queryRef));\n }\n if (queryRef.didChangeOptions(watchQueryOptions)) {\n const promise = queryRef.applyOptions(watchQueryOptions);\n updateWrappedQueryRef(wrappedQueryRef, promise);\n }\n\n // This prevents issues where rerendering useBackgroundQuery after the\n // queryRef has been disposed would cause the hook to return a new queryRef\n // instance since disposal also removes it from the suspense cache. We add\n // the queryRef back in the suspense cache so that the next render will reuse\n // this queryRef rather than initializing a new instance.\n React.useEffect(() => {\n // Since the queryRef is disposed async via `setTimeout`, we have to wait a\n // tick before checking it and adding back to the suspense cache.\n const id = setTimeout(() => {\n if (queryRef.disposed) {\n suspenseCache.add(cacheKey, queryRef);\n }\n });\n\n return () => clearTimeout(id);\n // Omitting the deps is intentional. This avoids stale closures and the\n // conditional ensures we aren't running the logic on each render.\n });\n\n const fetchMore: FetchMoreFunction<TData, TVariables> = React.useCallback(\n (options) => {\n const promise = queryRef.fetchMore(options as FetchMoreQueryOptions<any>);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n const refetch: RefetchFunction<TData, TVariables> = React.useCallback(\n (variables) => {\n const promise = queryRef.refetch(variables);\n\n setWrappedQueryRef(wrapQueryRef(queryRef));\n\n return promise;\n },\n [queryRef]\n );\n\n React.useEffect(() => queryRef.softRetain(), [queryRef]);\n\n return [\n didFetchResult.current ? wrappedQueryRef : void 0,\n {\n fetchMore,\n refetch,\n subscribeToMore: queryRef.observable.subscribeToMore,\n },\n ];\n}\n"]}
|
|
@@ -6,9 +6,11 @@ import { useSyncExternalStore } from "./useSyncExternalStore.js";
|
|
|
6
6
|
import { useDeepMemo, wrapHook } from "./internal/index.js";
|
|
7
7
|
import equal from "@wry/equality";
|
|
8
8
|
export function useFragment(options) {
|
|
9
|
-
return wrapHook("useFragment",
|
|
9
|
+
return wrapHook("useFragment",
|
|
10
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
11
|
+
useFragment_, useApolloClient(options.client))(options);
|
|
10
12
|
}
|
|
11
|
-
function
|
|
13
|
+
function useFragment_(options) {
|
|
12
14
|
var client = useApolloClient(options.client);
|
|
13
15
|
var cache = client.cache;
|
|
14
16
|
var from = options.from, rest = __rest(options, ["from"]);
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAQ1D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAGjE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,MAAM,eAAe,CAAC;AAsClC,MAAM,UAAU,WAAW,CACzB,OAAyC;IAEzC,OAAO,QAAQ,CACb,aAAa,
|
|
1
|
+
{"version":3,"file":"useFragment.js","sourceRoot":"","sources":["../../../src/react/hooks/useFragment.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAEjC,OAAO,EAAE,cAAc,EAAE,MAAM,0BAA0B,CAAC;AAQ1D,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AAGjE,OAAO,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAC5D,OAAO,KAAK,MAAM,eAAe,CAAC;AAsClC,MAAM,UAAU,WAAW,CACzB,OAAyC;IAEzC,OAAO,QAAQ,CACb,aAAa;IACb,yDAAyD;IACzD,YAAY,EACZ,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,CAChC,CAAC,OAAO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AAC;aACF,CAAC,CAAC;QACP,OAAO;YACL,YAAY,aAAZ,YAAY,uBAAZ,YAAY,CAAE,WAAW,EAAE,CAAC;YAC5B,YAAY,CAAC,WAAW,CAAC,CAAC;QAC5B,CAAC,CAAC;IACJ,CAAC,EACD,CAAC,MAAM,EAAE,aAAa,EAAE,IAAI,CAAC,CAC9B,EACD,WAAW,EACX,WAAW,CACZ,CAAC;AACJ,CAAC;AAED,SAAS,YAAY,CACnB,IAA6B;IAE7B,IAAM,MAAM,GAAG;QACb,IAAI,EAAE,IAAI,CAAC,MAAO;QAClB,QAAQ,EAAE,CAAC,CAAC,IAAI,CAAC,QAAQ;KACE,CAAC;IAE9B,IAAI,IAAI,CAAC,OAAO,EAAE,CAAC;QACjB,MAAM,CAAC,OAAO,GAAG,cAAc,CAAC,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,UAAC,KAAK,IAAK,OAAA,KAAK,CAAC,OAAO,EAAb,CAAa,CAAC,CAAC,CAAC;IAC9E,CAAC;IAED,OAAO,MAAM,CAAC;AAChB,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type { DeepPartial } from \"../../utilities/index.js\";\nimport { mergeDeepArray } from \"../../utilities/index.js\";\nimport type {\n Cache,\n Reference,\n StoreObject,\n MissingTree,\n} from \"../../cache/index.js\";\n\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\nimport type { ApolloClient, OperationVariables } from \"../../core/index.js\";\nimport type { NoInfer } from \"../types/types.js\";\nimport { useDeepMemo, wrapHook } from \"./internal/index.js\";\nimport equal from \"@wry/equality\";\nimport type { FragmentType, MaybeMasked } from \"../../masking/index.js\";\n\nexport interface UseFragmentOptions<TData, TVars>\n extends Omit<\n Cache.DiffOptions<NoInfer<TData>, NoInfer<TVars>>,\n \"id\" | \"query\" | \"optimistic\" | \"previousResult\" | \"returnPartialData\"\n >,\n Omit<\n Cache.ReadFragmentOptions<TData, TVars>,\n \"id\" | \"variables\" | \"returnPartialData\"\n > {\n from: StoreObject | Reference | FragmentType<NoInfer<TData>> | string | null;\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<any>;\n}\n\nexport type UseFragmentResult<TData> =\n | {\n data: MaybeMasked<TData>;\n complete: true;\n missing?: never;\n }\n | {\n data: DeepPartial<MaybeMasked<TData>>;\n complete: false;\n missing?: MissingTree;\n };\n\nexport function useFragment<TData = any, TVars = OperationVariables>(\n options: UseFragmentOptions<TData, TVars>\n): UseFragmentResult<TData> {\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 = any, TVars = OperationVariables>(\n options: UseFragmentOptions<TData, TVars>\n): UseFragmentResult<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: {} as TData,\n complete: false,\n }),\n };\n }\n\n const { cache } = client;\n const diff = cache.diff<TData>({\n ...stableOptions,\n returnPartialData: true,\n id: from,\n query: cache[\"getFragmentDoc\"](fragment, fragmentName),\n optimistic,\n });\n\n return {\n result: diffToResult({\n ...diff,\n result: client[\"queryManager\"].maskFragment({\n fragment,\n fragmentName,\n data: diff.result,\n }),\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 // Since `next` is called async by zen-observable, we want to avoid\n // 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): UseFragmentResult<TData> {\n const result = {\n data: diff.result!,\n complete: !!diff.complete,\n } as UseFragmentResult<TData>;\n\n if (diff.missing) {\n result.missing = mergeDeepArray(diff.missing.map((error) => error.missing));\n }\n\n return result;\n}\n"]}
|
|
@@ -157,6 +157,7 @@ export function useMutation(mutation, options) {
|
|
|
157
157
|
}, []);
|
|
158
158
|
React.useEffect(function () {
|
|
159
159
|
var current = ref.current;
|
|
160
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
160
161
|
current.isMounted = true;
|
|
161
162
|
return function () {
|
|
162
163
|
current.isMounted = false;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutation.js","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAiBjC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0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cAAc,CAAC,OAAO,KAAI,MAAA,GAAG,CAAC,OAAO,CAAC,OAAO,0CAAE,OAAO,CAAA,CAAC;YAEzD,IAAI,OAAO,EAAE,CAAC;gBACZ,OAAO,CACL,KAAK,EACL,aAA2D,CAC5D,CAAC;gBAEF,iDAAiD;gBACjD,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;YACzC,CAAC;YAED,MAAM,KAAK,CAAC;QACd,CAAC,CAAC,CAAC;IACP,CAAC,EACD,EAAE,CACH,CAAC;IAEF,IAAM,KAAK,GAAG,KAAK,CAAC,WAAW,CAAC;QAC9B,IAAI,GAAG,CAAC,OAAO,CAAC,SAAS,EAAE,CAAC;YAC1B,IAAM,QAAM,GAAG;gBACb,MAAM,EAAE,KAAK;gBACb,OAAO,EAAE,KAAK;gBACd,MAAM,EAAE,GAAG,CAAC,OAAO,CAAC,MAAM;aAC3B,CAAC;YACF,MAAM,CAAC,MAAM,CAAC,GAAG,CAAC,OAAO,EAAE,EAAE,UAAU,EAAE,CAAC,EAAE,MAAM,UAAA,EAAE,CAAC,CAAC;YACtD,SAAS,CAAC,QAAM,CAAC,CAAC;QACpB,CAAC;IACH,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,KAAK,CAAC,SAAS,CAAC;QACd,IAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;QAC5B,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;QAEzB,OAAO;YACL,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;QAC5B,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,aAAI,KAAK,OAAA,IAAK,MAAM,EAAG,CAAC;AACzC,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type { DocumentNode } from \"graphql\";\nimport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\nimport type {\n MutationFunctionOptions,\n MutationHookOptions,\n MutationResult,\n MutationTuple,\n NoInfer,\n} from \"../types/types.js\";\n\nimport type {\n ApolloCache,\n DefaultContext,\n MutationOptions,\n OperationVariables,\n} from \"../../core/index.js\";\nimport { mergeOptions } from \"../../utilities/index.js\";\nimport { equal } from \"@wry/equality\";\nimport { DocumentType, verifyDocumentType } from \"../parser/index.js\";\nimport { ApolloError } from \"../../errors/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useIsomorphicLayoutEffect } from \"./internal/useIsomorphicLayoutEffect.js\";\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 * ```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 * @since 3.0.0\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 = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n>(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: MutationHookOptions<\n NoInfer<TData>,\n NoInfer<TVariables>,\n TContext,\n TCache\n >\n): MutationTuple<TData, TVariables, TContext, TCache> {\n const client = useApolloClient(options?.client);\n verifyDocumentType(mutation, DocumentType.Mutation);\n const [result, setResult] = React.useState<Omit<MutationResult, \"reset\">>({\n called: false,\n loading: false,\n client,\n });\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: MutationFunctionOptions<\n TData,\n TVariables,\n TContext,\n TCache\n > = {}\n ) => {\n const { options, mutation } = ref.current;\n const baseOptions = { ...options, mutation };\n const client = executeOptions.client || ref.current.client;\n\n if (\n !ref.current.result.loading &&\n !baseOptions.ignoreResults &&\n ref.current.isMounted\n ) {\n setResult(\n (ref.current.result = {\n loading: true,\n error: void 0,\n data: void 0,\n called: true,\n client,\n })\n );\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(baseOptions, executeOptions);\n\n return client\n .mutate(clientOptions as MutationOptions<TData, OperationVariables>)\n .then((response) => {\n const { data, errors } = response;\n const error =\n errors && errors.length > 0 ?\n new ApolloError({ graphQLErrors: errors })\n : void 0;\n\n const onError =\n executeOptions.onError || ref.current.options?.onError;\n\n if (error && onError) {\n onError(\n error,\n clientOptions as MutationOptions<TData, OperationVariables>\n );\n }\n\n if (\n mutationId === ref.current.mutationId &&\n !clientOptions.ignoreResults\n ) {\n const result = {\n called: true,\n loading: false,\n data,\n error,\n client,\n };\n\n if (ref.current.isMounted && !equal(ref.current.result, result)) {\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?.(\n response.data!,\n clientOptions as MutationOptions<TData, OperationVariables>\n );\n }\n\n return response;\n })\n .catch((error) => {\n if (mutationId === ref.current.mutationId && ref.current.isMounted) {\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(\n error,\n clientOptions as MutationOptions<TData, OperationVariables>\n );\n\n // TODO(brian): why are we returning this here???\n return { data: void 0, errors: error };\n }\n\n throw error;\n });\n },\n []\n );\n\n const reset = React.useCallback(() => {\n if (ref.current.isMounted) {\n const result = {\n called: false,\n loading: false,\n client: ref.current.client,\n };\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, { reset, ...result }];\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useMutation.js","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AAiBjC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AACpD,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,yBAAyB,EAAE,MAAM,yCAAyC,CAAC;AAEpF;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,MAAM,UAAU,WAAW,CAMzB,QAA6D,EAC7D,OAKC;IAED,IAAM,MAAM,GAAG,eAAe,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC,CAAC;IAChD,kBAAkB,CAAC,QAAQ,EAAE,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAA,KAAsB,KAAK,CAAC,QAAQ,CAAgC;QACxE,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,KAAK;QACd,MAAM,QAAA;KACP,CAAC,EAJK,MAAM,QAAA,EAAE,SAAS,QAItB,CAAC;IAEH,IAAM,GAAG,GAAG,KAAK,CAAC,MAAM,CAAC;QACvB,MAAM,QAAA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,CAAC;IAEP,KAAK,CAAC,SAAS,CAAC;QACd,IAAM,OAAO,GAAG,GAAG,CAAC,OAAO,CAAC;QAC5B,yDAAyD;QACzD,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;QAEzB,OAAO;YACL,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;QAC5B,CAAC,CAAC;IACJ,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,aAAI,KAAK,OAAA,IAAK,MAAM,EAAG,CAAC;AACzC,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport type { DocumentNode } from \"graphql\";\nimport type { TypedDocumentNode } from \"@graphql-typed-document-node/core\";\nimport type {\n MutationFunctionOptions,\n MutationHookOptions,\n MutationResult,\n MutationTuple,\n NoInfer,\n} from \"../types/types.js\";\n\nimport type {\n ApolloCache,\n DefaultContext,\n MutationOptions,\n OperationVariables,\n} from \"../../core/index.js\";\nimport { mergeOptions } from \"../../utilities/index.js\";\nimport { equal } from \"@wry/equality\";\nimport { DocumentType, verifyDocumentType } from \"../parser/index.js\";\nimport { ApolloError } from \"../../errors/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { useIsomorphicLayoutEffect } from \"./internal/useIsomorphicLayoutEffect.js\";\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 * ```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 * @since 3.0.0\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 = any,\n TVariables = OperationVariables,\n TContext = DefaultContext,\n TCache extends ApolloCache<any> = ApolloCache<any>,\n>(\n mutation: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: MutationHookOptions<\n NoInfer<TData>,\n NoInfer<TVariables>,\n TContext,\n TCache\n >\n): MutationTuple<TData, TVariables, TContext, TCache> {\n const client = useApolloClient(options?.client);\n verifyDocumentType(mutation, DocumentType.Mutation);\n const [result, setResult] = React.useState<Omit<MutationResult, \"reset\">>({\n called: false,\n loading: false,\n client,\n });\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: MutationFunctionOptions<\n TData,\n TVariables,\n TContext,\n TCache\n > = {}\n ) => {\n const { options, mutation } = ref.current;\n const baseOptions = { ...options, mutation };\n const client = executeOptions.client || ref.current.client;\n\n if (\n !ref.current.result.loading &&\n !baseOptions.ignoreResults &&\n ref.current.isMounted\n ) {\n setResult(\n (ref.current.result = {\n loading: true,\n error: void 0,\n data: void 0,\n called: true,\n client,\n })\n );\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(baseOptions, executeOptions);\n\n return client\n .mutate(clientOptions as MutationOptions<TData, OperationVariables>)\n .then((response) => {\n const { data, errors } = response;\n const error =\n errors && errors.length > 0 ?\n new ApolloError({ graphQLErrors: errors })\n : void 0;\n\n const onError =\n executeOptions.onError || ref.current.options?.onError;\n\n if (error && onError) {\n onError(\n error,\n clientOptions as MutationOptions<TData, OperationVariables>\n );\n }\n\n if (\n mutationId === ref.current.mutationId &&\n !clientOptions.ignoreResults\n ) {\n const result = {\n called: true,\n loading: false,\n data,\n error,\n client,\n };\n\n if (ref.current.isMounted && !equal(ref.current.result, result)) {\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?.(\n response.data!,\n clientOptions as MutationOptions<TData, OperationVariables>\n );\n }\n\n return response;\n })\n .catch((error) => {\n if (mutationId === ref.current.mutationId && ref.current.isMounted) {\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(\n error,\n clientOptions as MutationOptions<TData, OperationVariables>\n );\n\n // TODO(brian): why are we returning this here???\n return { data: void 0, errors: error };\n }\n\n throw error;\n });\n },\n []\n );\n\n const reset = React.useCallback(() => {\n if (ref.current.isMounted) {\n const result = {\n called: false,\n loading: false,\n client: ref.current.client,\n };\n Object.assign(ref.current, { mutationId: 0, result });\n setResult(result);\n }\n }, []);\n\n React.useEffect(() => {\n const current = ref.current;\n // eslint-disable-next-line react-compiler/react-compiler\n current.isMounted = true;\n\n return () => {\n current.isMounted = false;\n };\n }, []);\n\n return [execute, { reset, ...result }];\n}\n"]}
|
package/react/hooks/useQuery.js
CHANGED
|
@@ -69,9 +69,11 @@ export var lastWatchOptions = Symbol();
|
|
|
69
69
|
*/
|
|
70
70
|
export function useQuery(query, options) {
|
|
71
71
|
if (options === void 0) { options = Object.create(null); }
|
|
72
|
-
return wrapHook("useQuery",
|
|
72
|
+
return wrapHook("useQuery",
|
|
73
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
74
|
+
useQuery_, useApolloClient(options && options.client))(query, options);
|
|
73
75
|
}
|
|
74
|
-
function
|
|
76
|
+
function useQuery_(query, options) {
|
|
75
77
|
var _a = useQueryInternals(query, options), result = _a.result, obsQueryFields = _a.obsQueryFields;
|
|
76
78
|
return React.useMemo(function () { return (__assign(__assign({}, result), obsQueryFields)); }, [result, obsQueryFields]);
|
|
77
79
|
}
|
|
@@ -171,6 +173,7 @@ function useObservableSubscriptionResult(resultData, observable, client, options
|
|
|
171
173
|
// Like the forceUpdate method, the versions of these methods inherited from
|
|
172
174
|
// InternalState.prototype are empty no-ops, but we can override them on the
|
|
173
175
|
// base state object (without modifying the prototype).
|
|
176
|
+
// eslint-disable-next-line react-compiler/react-compiler
|
|
174
177
|
callbackRef.current = callbacks;
|
|
175
178
|
});
|
|
176
179
|
var resultOverride = ((isSyncSSR || disableNetworkFetches) &&
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM;AACN,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,CAAC;AAE7D,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,EAAE,oBAAoB,EAAE,MAAM,2BAA2B,CAAC;AACjE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAQtC,OAAO,EAAE,YAAY,EAAE,MAAM,0BAA0B,CAAC;AACxD,OAAO,EAAE,gBAAgB,EAAE,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAC;AAQpD,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AAQpD,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,oBAAoB,CAAC;AACtE,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EACL,OAAO,EACP,eAAe,EACf,eAAe,GAChB,MAAM,0BAA0B,CAAC;AAClC,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAKhC,IAAA,cAAc,GACzB,MAAM,yBADmB,CAClB;AAOX,SAAS,IAAI,KAAI,CAAC;AAClB,MAAM,CAAC,IAAM,g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W,KAAK,YAAY,EAC/C,CAAC;QACD,UAAU,CAAC,OAAO,EAAE,CAAC;QACrB,6BACK,MAAM,KACT,OAAO,EAAE,IAAI,EACb,aAAa,EAAE,aAAa,CAAC,OAAO,IACpC;IACJ,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC;AAED,IAAM,iBAAiB,GAAG,eAAe,CAAC;IACxC,OAAO,EAAE,IAAI;IACb,IAAI,EAAE,KAAK,CAAQ;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,aAAa,EAAE,aAAa,CAAC,OAAO;CACrC,CAAC,CAAC;AAEH,IAAM,iBAAiB,GAAG,eAAe,CAAC;IACxC,OAAO,EAAE,KAAK;IACd,IAAI,EAAE,KAAK,CAAQ;IACnB,KAAK,EAAE,KAAK,CAAC;IACb,aAAa,EAAE,aAAa,CAAC,KAAK;CACnC,CAAC,CAAC;AAEH,SAAS,qBAAqB,CAC5B,UAA8C;IAE9C,OAAO;QACL,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;QAC5C,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC;QAChD,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC;QAChD,WAAW,EAAE,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC;QACpD,YAAY,EAAE,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC;QACtD,WAAW,EAAE,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC;QACpD,eAAe,EAAE,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC;KAC7D,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Function parameters in this file try to follow a common order for the sake of\n * readability and consistency. The order is as follows:\n *\n * resultData\n * observable\n * client\n * query\n * options\n * watchQueryOptions\n * makeWatchQueryOptions\n * isSSRAllowed\n * disableNetworkFetches\n * partialRefetch\n * renderPromises\n * isSyncSSR\n * callbacks\n */\n/** */\nimport { invariant } from \"../../utilities/globals/index.js\";\n\nimport * as React from \"rehackt\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\nimport { equal } from \"@wry/equality\";\n\nimport type {\n ApolloClient,\n DefaultOptions,\n OperationVariables,\n WatchQueryFetchPolicy,\n} from \"../../core/index.js\";\nimport { mergeOptions } from \"../../utilities/index.js\";\nimport { getApolloContext } from \"../context/index.js\";\nimport { ApolloError } from \"../../errors/index.js\";\nimport type {\n ApolloQueryResult,\n ObservableQuery,\n DocumentNode,\n TypedDocumentNode,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport { NetworkStatus } from \"../../core/index.js\";\nimport type {\n QueryHookOptions,\n QueryResult,\n ObservableQueryFields,\n NoInfer,\n} from \"../types/types.js\";\n\nimport { DocumentType, verifyDocumentType } from \"../parser/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport {\n compact,\n isNonEmptyArray,\n maybeDeepFreeze,\n} from \"../../utilities/index.js\";\nimport { wrapHook } from \"./internal/index.js\";\nimport type { RenderPromises } from \"../ssr/RenderPromises.js\";\nimport type { MaybeMasked } from \"../../masking/index.js\";\n\nconst {\n prototype: { hasOwnProperty },\n} = Object;\n\ntype InternalQueryResult<TData, TVariables extends OperationVariables> = Omit<\n QueryResult<TData, TVariables>,\n Exclude<keyof ObservableQueryFields<TData, TVariables>, \"variables\">\n>;\n\nfunction noop() {}\nexport const lastWatchOptions = Symbol();\n\nexport interface ObsQueryWithMeta<TData, TVariables extends OperationVariables>\n extends ObservableQuery<TData, TVariables> {\n [lastWatchOptions]?: WatchQueryOptions<TVariables, TData>;\n}\n\nexport interface InternalResult<TData, TVariables extends OperationVariables> {\n // These members are populated by getCurrentResult and setResult, and it's\n // okay/normal for them to be initially undefined.\n current?: undefined | InternalQueryResult<TData, TVariables>;\n previousData?: undefined | MaybeMasked<TData>;\n}\n\ninterface InternalState<TData, TVariables extends OperationVariables> {\n client: ReturnType<typeof useApolloClient>;\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n observable: ObsQueryWithMeta<TData, TVariables>;\n resultData: InternalResult<TData, TVariables>;\n}\n\nexport type UpdateInternalState<\n TData,\n TVariables extends OperationVariables,\n> = (state: InternalState<TData, TVariables>) => void;\n\ninterface Callbacks<TData> {\n // Defining these methods as no-ops on the prototype allows us to call\n // state.onCompleted and/or state.onError without worrying about whether a\n // callback was provided.\n onCompleted(data: MaybeMasked<TData>): void;\n onError(error: ApolloError): void;\n}\n\n/**\n * A hook for executing queries in an Apollo application.\n *\n * To run a query within a React component, call `useQuery` and pass it a GraphQL query document.\n *\n * When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, and `data` properties you can use to render your UI.\n *\n * > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.\n *\n * @example\n * ```jsx\n * import { gql, useQuery } from '@apollo/client';\n *\n * const GET_GREETING = gql`\n * query GetGreeting($language: String!) {\n * greeting(language: $language) {\n * message\n * }\n * }\n * `;\n *\n * function Hello() {\n * const { loading, error, data } = useQuery(GET_GREETING, {\n * variables: { language: 'english' },\n * });\n * if (loading) return <p>Loading ...</p>;\n * return <h1>Hello {data.greeting.message}!</h1>;\n * }\n * ```\n * @since 3.0.0\n * @param query - A GraphQL query document parsed into an AST by `gql`.\n * @param options - Options to control how the query is executed.\n * @returns Query result object\n */\nexport function useQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<\n NoInfer<TData>,\n NoInfer<TVariables>\n > = Object.create(null)\n): QueryResult<TData, TVariables> {\n return wrapHook(\n \"useQuery\",\n _useQuery,\n useApolloClient(options && options.client)\n )(query, options);\n}\n\nfunction _useQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n) {\n const { result, obsQueryFields } = useQueryInternals(query, options);\n return React.useMemo(\n () => ({ ...result, ...obsQueryFields }),\n [result, obsQueryFields]\n );\n}\n\nfunction useInternalState<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n client: ApolloClient<object>,\n query: DocumentNode | TypedDocumentNode<any, any>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>,\n renderPromises: RenderPromises | undefined,\n makeWatchQueryOptions: () => WatchQueryOptions<TVariables, TData>\n) {\n function createInternalState(previous?: InternalState<TData, TVariables>) {\n verifyDocumentType(query, DocumentType.Query);\n\n const internalState: InternalState<TData, TVariables> = {\n client,\n query,\n observable:\n // See if there is an existing observable that was used to fetch the same\n // data and if so, use it instead since it will contain the proper queryId\n // to fetch the result set. This is used during SSR.\n (renderPromises &&\n renderPromises.getSSRObservable(makeWatchQueryOptions())) ||\n client.watchQuery(\n getObsQueryOptions(void 0, client, options, makeWatchQueryOptions())\n ),\n resultData: {\n // Reuse previousData from previous InternalState (if any) to provide\n // continuity of previousData even if/when the query or client changes.\n previousData: previous?.resultData.current?.data,\n },\n };\n\n return internalState as InternalState<TData, TVariables>;\n }\n\n let [internalState, updateInternalState] =\n React.useState(createInternalState);\n\n /**\n * Used by `useLazyQuery` when a new query is executed.\n * We keep this logic here since it needs to update things in unsafe\n * ways and here we at least can keep track of that in a single place.\n */\n function onQueryExecuted(\n watchQueryOptions: WatchQueryOptions<TVariables, TData>\n ) {\n // this needs to be set to prevent an immediate `resubscribe` in the\n // next rerender of the `useQuery` internals\n Object.assign(internalState.observable, {\n [lastWatchOptions]: watchQueryOptions,\n });\n const resultData = internalState.resultData;\n updateInternalState({\n ...internalState,\n // might be a different query\n query: watchQueryOptions.query,\n resultData: Object.assign(resultData, {\n // We need to modify the previous `resultData` object as we rely on the\n // object reference in other places\n previousData: resultData.current?.data || resultData.previousData,\n current: undefined,\n }),\n });\n }\n\n if (client !== internalState.client || query !== internalState.query) {\n // If the client or query have changed, we need to create a new InternalState.\n // This will trigger a re-render with the new state, but it will also continue\n // to run the current render function to completion.\n // Since we sometimes trigger some side-effects in the render function, we\n // re-assign `state` to the new state to ensure that those side-effects are\n // triggered with the new state.\n const newInternalState = createInternalState(internalState);\n updateInternalState(newInternalState);\n return [newInternalState, onQueryExecuted] as const;\n }\n\n return [internalState, onQueryExecuted] as const;\n}\n\nexport function useQueryInternals<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n) {\n const client = useApolloClient(options.client);\n\n const renderPromises = React.useContext(getApolloContext()).renderPromises;\n const isSyncSSR = !!renderPromises;\n const disableNetworkFetches = client.disableNetworkFetches;\n const ssrAllowed = options.ssr !== false && !options.skip;\n const partialRefetch = options.partialRefetch;\n\n const makeWatchQueryOptions = createMakeWatchQueryOptions(\n client,\n query,\n options,\n isSyncSSR\n );\n\n const [{ observable, resultData }, onQueryExecuted] = useInternalState(\n client,\n query,\n options,\n renderPromises,\n makeWatchQueryOptions\n );\n\n const watchQueryOptions: Readonly<WatchQueryOptions<TVariables, TData>> =\n makeWatchQueryOptions(observable);\n\n useResubscribeIfNecessary<TData, TVariables>(\n resultData, // might get mutated during render\n observable, // might get mutated during render\n client,\n options,\n watchQueryOptions\n );\n\n const obsQueryFields = React.useMemo<\n Omit<ObservableQueryFields<TData, TVariables>, \"variables\">\n >(() => bindObservableMethods(observable), [observable]);\n\n useRegisterSSRObservable(observable, renderPromises, ssrAllowed);\n\n const result = useObservableSubscriptionResult<TData, TVariables>(\n resultData,\n observable,\n client,\n options,\n watchQueryOptions,\n disableNetworkFetches,\n partialRefetch,\n isSyncSSR,\n {\n onCompleted: options.onCompleted || noop,\n onError: options.onError || noop,\n }\n );\n\n return {\n result,\n obsQueryFields,\n observable,\n resultData,\n client,\n onQueryExecuted,\n };\n}\n\nfunction useObservableSubscriptionResult<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n resultData: InternalResult<TData, TVariables>,\n observable: ObservableQuery<TData, TVariables>,\n client: ApolloClient<object>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>,\n watchQueryOptions: Readonly<WatchQueryOptions<TVariables, TData>>,\n disableNetworkFetches: boolean,\n partialRefetch: boolean | undefined,\n isSyncSSR: boolean,\n callbacks: {\n onCompleted: (data: MaybeMasked<TData>) => void;\n onError: (error: ApolloError) => void;\n }\n) {\n const callbackRef = React.useRef<Callbacks<TData>>(callbacks);\n React.useEffect(() => {\n // Make sure state.onCompleted and state.onError always reflect the latest\n // options.onCompleted and options.onError callbacks provided to useQuery,\n // since those functions are often recreated every time useQuery is called.\n // Like the forceUpdate method, the versions of these methods inherited from\n // InternalState.prototype are empty no-ops, but we can override them on the\n // base state object (without modifying the prototype).\n callbackRef.current = callbacks;\n });\n\n const resultOverride =\n (\n (isSyncSSR || disableNetworkFetches) &&\n options.ssr === false &&\n !options.skip\n ) ?\n // If SSR has been explicitly disabled, and this function has been called\n // on the server side, return the default loading state.\n ssrDisabledResult\n : options.skip || watchQueryOptions.fetchPolicy === \"standby\" ?\n // When skipping a query (ie. we're not querying for data but still want to\n // render children), make sure the `data` is cleared out and `loading` is\n // set to `false` (since we aren't loading anything).\n //\n // NOTE: We no longer think this is the correct behavior. Skipping should\n // not automatically set `data` to `undefined`, but instead leave the\n // previous data in place. In other words, skipping should not mandate that\n // previously received data is all of a sudden removed. Unfortunately,\n // changing this is breaking, so we'll have to wait until Apollo Client 4.0\n // to address this.\n skipStandbyResult\n : void 0;\n\n const previousData = resultData.previousData;\n const currentResultOverride = React.useMemo(\n () =>\n resultOverride &&\n toQueryResult(resultOverride, previousData, observable, client),\n [client, observable, resultOverride, previousData]\n );\n\n return useSyncExternalStore(\n React.useCallback(\n (handleStoreChange) => {\n // reference `disableNetworkFetches` here to ensure that the rules of hooks\n // keep it as a dependency of this effect, even though it's not used\n disableNetworkFetches;\n\n if (isSyncSSR) {\n return () => {};\n }\n\n const onNext = () => {\n const previousResult = resultData.current;\n // We use `getCurrentResult()` instead of the onNext argument because\n // the values differ slightly. Specifically, loading results will have\n // an empty object for data instead of `undefined` for some reason.\n const result = observable.getCurrentResult();\n // Make sure we're not attempting to re-render similar results\n if (\n previousResult &&\n previousResult.loading === result.loading &&\n previousResult.networkStatus === result.networkStatus &&\n equal(previousResult.data, result.data)\n ) {\n return;\n }\n\n setResult(\n result,\n resultData,\n observable,\n client,\n partialRefetch,\n handleStoreChange,\n callbackRef.current\n );\n };\n\n const onError = (error: Error) => {\n subscription.current.unsubscribe();\n subscription.current = observable.resubscribeAfterError(\n onNext,\n onError\n );\n\n if (!hasOwnProperty.call(error, \"graphQLErrors\")) {\n // The error is not a GraphQL error\n throw error;\n }\n\n const previousResult = resultData.current;\n if (\n !previousResult ||\n (previousResult && previousResult.loading) ||\n !equal(error, previousResult.error)\n ) {\n setResult(\n {\n data: (previousResult &&\n previousResult.data) as MaybeMasked<TData>,\n error: error as ApolloError,\n loading: false,\n networkStatus: NetworkStatus.error,\n },\n resultData,\n observable,\n client,\n partialRefetch,\n handleStoreChange,\n callbackRef.current\n );\n }\n };\n\n // TODO evaluate if we keep this in\n // React Compiler cannot handle scoped `let` access, but a mutable object\n // like this is fine.\n // was:\n // let subscription = observable.subscribe(onNext, onError);\n const subscription = { current: observable.subscribe(onNext, onError) };\n\n // Do the \"unsubscribe\" with a short delay.\n // This way, an existing subscription can be reused without an additional\n // request if \"unsubscribe\" and \"resubscribe\" to the same ObservableQuery\n // happen in very fast succession.\n return () => {\n setTimeout(() => subscription.current.unsubscribe());\n };\n },\n\n [\n disableNetworkFetches,\n isSyncSSR,\n observable,\n resultData,\n partialRefetch,\n client,\n ]\n ),\n () =>\n currentResultOverride ||\n getCurrentResult(\n resultData,\n observable,\n callbackRef.current,\n partialRefetch,\n client\n ),\n () =>\n currentResultOverride ||\n getCurrentResult(\n resultData,\n observable,\n callbackRef.current,\n partialRefetch,\n client\n )\n );\n}\n\nfunction useRegisterSSRObservable(\n observable: ObsQueryWithMeta<any, any>,\n renderPromises: RenderPromises | undefined,\n ssrAllowed: boolean\n) {\n if (renderPromises && ssrAllowed) {\n renderPromises.registerSSRObservable(observable);\n\n if (observable.getCurrentResult().loading) {\n // TODO: This is a legacy API which could probably be cleaned up\n renderPromises.addObservableQueryPromise(observable);\n }\n }\n}\n\n// this hook is not compatible with any rules of React, and there's no good way to rewrite it.\n// it should stay a separate hook that will not be optimized by the compiler\nfunction useResubscribeIfNecessary<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n /** this hook will mutate properties on `resultData` */\n resultData: InternalResult<TData, TVariables>,\n /** this hook will mutate properties on `observable` */\n observable: ObsQueryWithMeta<TData, TVariables>,\n client: ApolloClient<object>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>,\n watchQueryOptions: Readonly<WatchQueryOptions<TVariables, TData>>\n) {\n if (\n observable[lastWatchOptions] &&\n !equal(observable[lastWatchOptions], watchQueryOptions)\n ) {\n // Though it might be tempting to postpone this reobserve call to the\n // useEffect block, we need getCurrentResult to return an appropriate\n // loading:true result synchronously (later within the same call to\n // useQuery). Since we already have this.observable here (not true for\n // the very first call to useQuery), we are not initiating any new\n // subscriptions, though it does feel less than ideal that reobserve\n // (potentially) kicks off a network request (for example, when the\n // variables have changed), which is technically a side-effect.\n observable.reobserve(\n getObsQueryOptions(observable, client, options, watchQueryOptions)\n );\n\n // Make sure getCurrentResult returns a fresh ApolloQueryResult<TData>,\n // but save the current data as this.previousData, just like setResult\n // usually does.\n resultData.previousData =\n resultData.current?.data || resultData.previousData;\n resultData.current = void 0;\n }\n observable[lastWatchOptions] = watchQueryOptions;\n}\n\n/*\n * A function to massage options before passing them to ObservableQuery.\n * This is two-step curried because we want to reuse the `make` function,\n * but the `observable` might differ between calls to `make`.\n */\nexport function createMakeWatchQueryOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n client: ApolloClient<object>,\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n {\n skip,\n ssr,\n onCompleted,\n onError,\n defaultOptions,\n // The above options are useQuery-specific, so this ...otherOptions spread\n // makes otherOptions almost a WatchQueryOptions object, except for the\n // query property that we add below.\n ...otherOptions\n }: QueryHookOptions<TData, TVariables> = {},\n isSyncSSR: boolean\n) {\n return (\n observable?: ObservableQuery<TData, TVariables>\n ): WatchQueryOptions<TVariables, TData> => {\n // This Object.assign is safe because otherOptions is a fresh ...rest object\n // that did not exist until just now, so modifications are still allowed.\n const watchQueryOptions: WatchQueryOptions<TVariables, TData> =\n Object.assign(otherOptions, { query });\n\n if (\n isSyncSSR &&\n (watchQueryOptions.fetchPolicy === \"network-only\" ||\n watchQueryOptions.fetchPolicy === \"cache-and-network\")\n ) {\n // this behavior was added to react-apollo without explanation in this PR\n // https://github.com/apollographql/react-apollo/pull/1579\n watchQueryOptions.fetchPolicy = \"cache-first\";\n }\n\n if (!watchQueryOptions.variables) {\n watchQueryOptions.variables = {} as TVariables;\n }\n\n if (skip) {\n // When skipping, we set watchQueryOptions.fetchPolicy initially to\n // \"standby\", but we also need/want to preserve the initial non-standby\n // fetchPolicy that would have been used if not skipping.\n watchQueryOptions.initialFetchPolicy =\n watchQueryOptions.initialFetchPolicy ||\n watchQueryOptions.fetchPolicy ||\n getDefaultFetchPolicy(defaultOptions, client.defaultOptions);\n watchQueryOptions.fetchPolicy = \"standby\";\n } else if (!watchQueryOptions.fetchPolicy) {\n watchQueryOptions.fetchPolicy =\n observable?.options.initialFetchPolicy ||\n getDefaultFetchPolicy(defaultOptions, client.defaultOptions);\n }\n\n return watchQueryOptions;\n };\n}\n\nexport function getObsQueryOptions<\n TData,\n TVariables extends OperationVariables,\n>(\n observable: ObservableQuery<TData, TVariables> | undefined,\n client: ApolloClient<object>,\n queryHookOptions: QueryHookOptions<TData, TVariables>,\n watchQueryOptions: Partial<WatchQueryOptions<TVariables, TData>>\n): WatchQueryOptions<TVariables, TData> {\n const toMerge: Array<Partial<WatchQueryOptions<TVariables, TData>>> = [];\n\n const globalDefaults = client.defaultOptions.watchQuery;\n if (globalDefaults) toMerge.push(globalDefaults);\n\n if (queryHookOptions.defaultOptions) {\n toMerge.push(queryHookOptions.defaultOptions);\n }\n\n // We use compact rather than mergeOptions for this part of the merge,\n // because we want watchQueryOptions.variables (if defined) to replace\n // this.observable.options.variables whole. This replacement allows\n // removing variables by removing them from the variables input to\n // useQuery. If the variables were always merged together (rather than\n // replaced), there would be no way to remove existing variables.\n // However, the variables from options.defaultOptions and globalDefaults\n // (if provided) should be merged, to ensure individual defaulted\n // variables always have values, if not otherwise defined in\n // observable.options or watchQueryOptions.\n toMerge.push(compact(observable && observable.options, watchQueryOptions));\n\n return toMerge.reduce(mergeOptions) as WatchQueryOptions<TVariables, TData>;\n}\n\nfunction setResult<TData, TVariables extends OperationVariables>(\n nextResult: ApolloQueryResult<MaybeMasked<TData>>,\n resultData: InternalResult<TData, TVariables>,\n observable: ObservableQuery<TData, TVariables>,\n client: ApolloClient<object>,\n partialRefetch: boolean | undefined,\n forceUpdate: () => void,\n callbacks: Callbacks<TData>\n) {\n const previousResult = resultData.current;\n if (previousResult && previousResult.data) {\n resultData.previousData = previousResult.data;\n }\n\n if (!nextResult.error && isNonEmptyArray(nextResult.errors)) {\n // Until a set naming convention for networkError and graphQLErrors is\n // decided upon, we map errors (graphQLErrors) to the error options.\n // TODO: Is it possible for both result.error and result.errors to be\n // defined here?\n nextResult.error = new ApolloError({ graphQLErrors: nextResult.errors });\n }\n\n resultData.current = toQueryResult(\n unsafeHandlePartialRefetch(nextResult, observable, partialRefetch),\n resultData.previousData,\n observable,\n client\n );\n // Calling state.setResult always triggers an update, though some call sites\n // perform additional equality checks before committing to an update.\n forceUpdate();\n handleErrorOrCompleted(nextResult, previousResult?.networkStatus, callbacks);\n}\n\nfunction handleErrorOrCompleted<TData>(\n result: ApolloQueryResult<MaybeMasked<TData>>,\n previousNetworkStatus: NetworkStatus | undefined,\n callbacks: Callbacks<TData>\n) {\n if (!result.loading) {\n const error = toApolloError(result);\n\n // wait a tick in case we are in the middle of rendering a component\n Promise.resolve()\n .then(() => {\n if (error) {\n callbacks.onError(error);\n } else if (\n result.data &&\n previousNetworkStatus !== result.networkStatus &&\n result.networkStatus === NetworkStatus.ready\n ) {\n callbacks.onCompleted(result.data);\n }\n })\n .catch((error) => {\n invariant.warn(error);\n });\n }\n}\n\nfunction getCurrentResult<TData, TVariables extends OperationVariables>(\n resultData: InternalResult<TData, TVariables>,\n observable: ObservableQuery<TData, TVariables>,\n callbacks: Callbacks<TData>,\n partialRefetch: boolean | undefined,\n client: ApolloClient<object>\n): InternalQueryResult<TData, TVariables> {\n // Using this.result as a cache ensures getCurrentResult continues returning\n // the same (===) result object, unless state.setResult has been called, or\n // we're doing server rendering and therefore override the result below.\n if (!resultData.current) {\n // WARNING: SIDE-EFFECTS IN THE RENDER FUNCTION\n // this could call unsafeHandlePartialRefetch\n setResult(\n observable.getCurrentResult(),\n resultData,\n observable,\n client,\n partialRefetch,\n () => {},\n callbacks\n );\n }\n return resultData.current!;\n}\n\nexport function getDefaultFetchPolicy<\n TData,\n TVariables extends OperationVariables,\n>(\n queryHookDefaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>,\n clientDefaultOptions?: DefaultOptions\n): WatchQueryFetchPolicy {\n return (\n queryHookDefaultOptions?.fetchPolicy ||\n clientDefaultOptions?.watchQuery?.fetchPolicy ||\n \"cache-first\"\n );\n}\n\nexport function toApolloError<TData>(\n result: Pick<ApolloQueryResult<TData>, \"errors\" | \"error\">\n): ApolloError | undefined {\n return isNonEmptyArray(result.errors) ?\n new ApolloError({ graphQLErrors: result.errors })\n : result.error;\n}\n\nexport function toQueryResult<TData, TVariables extends OperationVariables>(\n result: ApolloQueryResult<MaybeMasked<TData>>,\n previousData: MaybeMasked<TData> | undefined,\n observable: ObservableQuery<TData, TVariables>,\n client: ApolloClient<object>\n): InternalQueryResult<TData, TVariables> {\n const { data, partial, ...resultWithoutPartial } = result;\n const queryResult: InternalQueryResult<TData, TVariables> = {\n data, // Ensure always defined, even if result.data is missing.\n ...resultWithoutPartial,\n client: client,\n observable: observable,\n variables: observable.variables,\n called: result !== ssrDisabledResult && result !== skipStandbyResult,\n previousData,\n };\n return queryResult;\n}\n\nfunction unsafeHandlePartialRefetch<\n TData,\n TVariables extends OperationVariables,\n>(\n result: ApolloQueryResult<MaybeMasked<TData>>,\n observable: ObservableQuery<TData, TVariables>,\n partialRefetch: boolean | undefined\n): ApolloQueryResult<MaybeMasked<TData>> {\n // TODO: This code should be removed when the partialRefetch option is\n // removed. I was unable to get this hook to behave reasonably in certain\n // edge cases when this block was put in an effect.\n if (\n result.partial &&\n partialRefetch &&\n !result.loading &&\n (!result.data || Object.keys(result.data).length === 0) &&\n observable.options.fetchPolicy !== \"cache-only\"\n ) {\n observable.refetch();\n return {\n ...result,\n loading: true,\n networkStatus: NetworkStatus.refetch,\n };\n }\n return result;\n}\n\nconst ssrDisabledResult = maybeDeepFreeze({\n loading: true,\n data: void 0 as any,\n error: void 0,\n networkStatus: NetworkStatus.loading,\n});\n\nconst skipStandbyResult = maybeDeepFreeze({\n loading: false,\n data: void 0 as any,\n error: void 0,\n networkStatus: NetworkStatus.ready,\n});\n\nfunction bindObservableMethods<TData, TVariables extends OperationVariables>(\n observable: ObservableQuery<TData, TVariables>\n) {\n return {\n refetch: observable.refetch.bind(observable),\n reobserve: observable.reobserve.bind(observable),\n fetchMore: observable.fetchMore.bind(observable),\n updateQuery: observable.updateQuery.bind(observable),\n startPolling: observable.startPolling.bind(observable),\n stopPolling: observable.stopPolling.bind(observable),\n subscribeToMore: observable.subscribeToMore.bind(observable),\n };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":";AAAA;;;;;;;;;;;;;;;;;GAiBG;AACH,MAAM;AACN,OAAO,EAAE,SAAS,EAAE,MAAM,kCAAkC,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AAa,CAAC,KAAK;CACnC,CAAC,CAAC;AAEH,SAAS,qBAAqB,CAC5B,UAA8C;IAE9C,OAAO;QACL,OAAO,EAAE,UAAU,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;QAC5C,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC;QAChD,SAAS,EAAE,UAAU,CAAC,SAAS,CAAC,IAAI,CAAC,UAAU,CAAC;QAChD,WAAW,EAAE,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC;QACpD,YAAY,EAAE,UAAU,CAAC,YAAY,CAAC,IAAI,CAAC,UAAU,CAAC;QACtD,WAAW,EAAE,UAAU,CAAC,WAAW,CAAC,IAAI,CAAC,UAAU,CAAC;QACpD,eAAe,EAAE,UAAU,CAAC,eAAe,CAAC,IAAI,CAAC,UAAU,CAAC;KAC7D,CAAC;AACJ,CAAC","sourcesContent":["/**\n * Function parameters in this file try to follow a common order for the sake of\n * readability and consistency. The order is as follows:\n *\n * resultData\n * observable\n * client\n * query\n * options\n * watchQueryOptions\n * makeWatchQueryOptions\n * isSSRAllowed\n * disableNetworkFetches\n * partialRefetch\n * renderPromises\n * isSyncSSR\n * callbacks\n */\n/** */\nimport { invariant } from \"../../utilities/globals/index.js\";\n\nimport * as React from \"rehackt\";\nimport { useSyncExternalStore } from \"./useSyncExternalStore.js\";\nimport { equal } from \"@wry/equality\";\n\nimport type {\n ApolloClient,\n DefaultOptions,\n OperationVariables,\n WatchQueryFetchPolicy,\n} from \"../../core/index.js\";\nimport { mergeOptions } from \"../../utilities/index.js\";\nimport { getApolloContext } from \"../context/index.js\";\nimport { ApolloError } from \"../../errors/index.js\";\nimport type {\n ApolloQueryResult,\n ObservableQuery,\n DocumentNode,\n TypedDocumentNode,\n WatchQueryOptions,\n} from \"../../core/index.js\";\nimport { NetworkStatus } from \"../../core/index.js\";\nimport type {\n QueryHookOptions,\n QueryResult,\n ObservableQueryFields,\n NoInfer,\n} from \"../types/types.js\";\n\nimport { DocumentType, verifyDocumentType } from \"../parser/index.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport {\n compact,\n isNonEmptyArray,\n maybeDeepFreeze,\n} from \"../../utilities/index.js\";\nimport { wrapHook } from \"./internal/index.js\";\nimport type { RenderPromises } from \"../ssr/RenderPromises.js\";\nimport type { MaybeMasked } from \"../../masking/index.js\";\n\nconst {\n prototype: { hasOwnProperty },\n} = Object;\n\ntype InternalQueryResult<TData, TVariables extends OperationVariables> = Omit<\n QueryResult<TData, TVariables>,\n Exclude<keyof ObservableQueryFields<TData, TVariables>, \"variables\">\n>;\n\nfunction noop() {}\nexport const lastWatchOptions = Symbol();\n\nexport interface ObsQueryWithMeta<TData, TVariables extends OperationVariables>\n extends ObservableQuery<TData, TVariables> {\n [lastWatchOptions]?: WatchQueryOptions<TVariables, TData>;\n}\n\nexport interface InternalResult<TData, TVariables extends OperationVariables> {\n // These members are populated by getCurrentResult and setResult, and it's\n // okay/normal for them to be initially undefined.\n current?: undefined | InternalQueryResult<TData, TVariables>;\n previousData?: undefined | MaybeMasked<TData>;\n}\n\ninterface InternalState<TData, TVariables extends OperationVariables> {\n client: ReturnType<typeof useApolloClient>;\n query: DocumentNode | TypedDocumentNode<TData, TVariables>;\n observable: ObsQueryWithMeta<TData, TVariables>;\n resultData: InternalResult<TData, TVariables>;\n}\n\nexport type UpdateInternalState<\n TData,\n TVariables extends OperationVariables,\n> = (state: InternalState<TData, TVariables>) => void;\n\ninterface Callbacks<TData> {\n // Defining these methods as no-ops on the prototype allows us to call\n // state.onCompleted and/or state.onError without worrying about whether a\n // callback was provided.\n onCompleted(data: MaybeMasked<TData>): void;\n onError(error: ApolloError): void;\n}\n\n/**\n * A hook for executing queries in an Apollo application.\n *\n * To run a query within a React component, call `useQuery` and pass it a GraphQL query document.\n *\n * When your component renders, `useQuery` returns an object from Apollo Client that contains `loading`, `error`, and `data` properties you can use to render your UI.\n *\n * > Refer to the [Queries](https://www.apollographql.com/docs/react/data/queries) section for a more in-depth overview of `useQuery`.\n *\n * @example\n * ```jsx\n * import { gql, useQuery } from '@apollo/client';\n *\n * const GET_GREETING = gql`\n * query GetGreeting($language: String!) {\n * greeting(language: $language) {\n * message\n * }\n * }\n * `;\n *\n * function Hello() {\n * const { loading, error, data } = useQuery(GET_GREETING, {\n * variables: { language: 'english' },\n * });\n * if (loading) return <p>Loading ...</p>;\n * return <h1>Hello {data.greeting.message}!</h1>;\n * }\n * ```\n * @since 3.0.0\n * @param query - A GraphQL query document parsed into an AST by `gql`.\n * @param options - Options to control how the query is executed.\n * @returns Query result object\n */\nexport function useQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<\n NoInfer<TData>,\n NoInfer<TVariables>\n > = Object.create(null)\n): QueryResult<TData, TVariables> {\n return wrapHook(\n \"useQuery\",\n // eslint-disable-next-line react-compiler/react-compiler\n useQuery_,\n useApolloClient(options && options.client)\n )(query, options);\n}\n\nfunction useQuery_<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n) {\n const { result, obsQueryFields } = useQueryInternals(query, options);\n return React.useMemo(\n () => ({ ...result, ...obsQueryFields }),\n [result, obsQueryFields]\n );\n}\n\nfunction useInternalState<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n client: ApolloClient<object>,\n query: DocumentNode | TypedDocumentNode<any, any>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>,\n renderPromises: RenderPromises | undefined,\n makeWatchQueryOptions: () => WatchQueryOptions<TVariables, TData>\n) {\n function createInternalState(previous?: InternalState<TData, TVariables>) {\n verifyDocumentType(query, DocumentType.Query);\n\n const internalState: InternalState<TData, TVariables> = {\n client,\n query,\n observable:\n // See if there is an existing observable that was used to fetch the same\n // data and if so, use it instead since it will contain the proper queryId\n // to fetch the result set. This is used during SSR.\n (renderPromises &&\n renderPromises.getSSRObservable(makeWatchQueryOptions())) ||\n client.watchQuery(\n getObsQueryOptions(void 0, client, options, makeWatchQueryOptions())\n ),\n resultData: {\n // Reuse previousData from previous InternalState (if any) to provide\n // continuity of previousData even if/when the query or client changes.\n previousData: previous?.resultData.current?.data,\n },\n };\n\n return internalState as InternalState<TData, TVariables>;\n }\n\n let [internalState, updateInternalState] =\n React.useState(createInternalState);\n\n /**\n * Used by `useLazyQuery` when a new query is executed.\n * We keep this logic here since it needs to update things in unsafe\n * ways and here we at least can keep track of that in a single place.\n */\n function onQueryExecuted(\n watchQueryOptions: WatchQueryOptions<TVariables, TData>\n ) {\n // this needs to be set to prevent an immediate `resubscribe` in the\n // next rerender of the `useQuery` internals\n Object.assign(internalState.observable, {\n [lastWatchOptions]: watchQueryOptions,\n });\n const resultData = internalState.resultData;\n updateInternalState({\n ...internalState,\n // might be a different query\n query: watchQueryOptions.query,\n resultData: Object.assign(resultData, {\n // We need to modify the previous `resultData` object as we rely on the\n // object reference in other places\n previousData: resultData.current?.data || resultData.previousData,\n current: undefined,\n }),\n });\n }\n\n if (client !== internalState.client || query !== internalState.query) {\n // If the client or query have changed, we need to create a new InternalState.\n // This will trigger a re-render with the new state, but it will also continue\n // to run the current render function to completion.\n // Since we sometimes trigger some side-effects in the render function, we\n // re-assign `state` to the new state to ensure that those side-effects are\n // triggered with the new state.\n const newInternalState = createInternalState(internalState);\n updateInternalState(newInternalState);\n return [newInternalState, onQueryExecuted] as const;\n }\n\n return [internalState, onQueryExecuted] as const;\n}\n\nexport function useQueryInternals<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>\n) {\n const client = useApolloClient(options.client);\n\n const renderPromises = React.useContext(getApolloContext()).renderPromises;\n const isSyncSSR = !!renderPromises;\n const disableNetworkFetches = client.disableNetworkFetches;\n const ssrAllowed = options.ssr !== false && !options.skip;\n const partialRefetch = options.partialRefetch;\n\n const makeWatchQueryOptions = createMakeWatchQueryOptions(\n client,\n query,\n options,\n isSyncSSR\n );\n\n const [{ observable, resultData }, onQueryExecuted] = useInternalState(\n client,\n query,\n options,\n renderPromises,\n makeWatchQueryOptions\n );\n\n const watchQueryOptions: Readonly<WatchQueryOptions<TVariables, TData>> =\n makeWatchQueryOptions(observable);\n\n useResubscribeIfNecessary<TData, TVariables>(\n resultData, // might get mutated during render\n observable, // might get mutated during render\n client,\n options,\n watchQueryOptions\n );\n\n const obsQueryFields = React.useMemo<\n Omit<ObservableQueryFields<TData, TVariables>, \"variables\">\n >(() => bindObservableMethods(observable), [observable]);\n\n useRegisterSSRObservable(observable, renderPromises, ssrAllowed);\n\n const result = useObservableSubscriptionResult<TData, TVariables>(\n resultData,\n observable,\n client,\n options,\n watchQueryOptions,\n disableNetworkFetches,\n partialRefetch,\n isSyncSSR,\n {\n onCompleted: options.onCompleted || noop,\n onError: options.onError || noop,\n }\n );\n\n return {\n result,\n obsQueryFields,\n observable,\n resultData,\n client,\n onQueryExecuted,\n };\n}\n\nfunction useObservableSubscriptionResult<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n resultData: InternalResult<TData, TVariables>,\n observable: ObservableQuery<TData, TVariables>,\n client: ApolloClient<object>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>,\n watchQueryOptions: Readonly<WatchQueryOptions<TVariables, TData>>,\n disableNetworkFetches: boolean,\n partialRefetch: boolean | undefined,\n isSyncSSR: boolean,\n callbacks: {\n onCompleted: (data: MaybeMasked<TData>) => void;\n onError: (error: ApolloError) => void;\n }\n) {\n const callbackRef = React.useRef<Callbacks<TData>>(callbacks);\n React.useEffect(() => {\n // Make sure state.onCompleted and state.onError always reflect the latest\n // options.onCompleted and options.onError callbacks provided to useQuery,\n // since those functions are often recreated every time useQuery is called.\n // Like the forceUpdate method, the versions of these methods inherited from\n // InternalState.prototype are empty no-ops, but we can override them on the\n // base state object (without modifying the prototype).\n // eslint-disable-next-line react-compiler/react-compiler\n callbackRef.current = callbacks;\n });\n\n const resultOverride =\n (\n (isSyncSSR || disableNetworkFetches) &&\n options.ssr === false &&\n !options.skip\n ) ?\n // If SSR has been explicitly disabled, and this function has been called\n // on the server side, return the default loading state.\n ssrDisabledResult\n : options.skip || watchQueryOptions.fetchPolicy === \"standby\" ?\n // When skipping a query (ie. we're not querying for data but still want to\n // render children), make sure the `data` is cleared out and `loading` is\n // set to `false` (since we aren't loading anything).\n //\n // NOTE: We no longer think this is the correct behavior. Skipping should\n // not automatically set `data` to `undefined`, but instead leave the\n // previous data in place. In other words, skipping should not mandate that\n // previously received data is all of a sudden removed. Unfortunately,\n // changing this is breaking, so we'll have to wait until Apollo Client 4.0\n // to address this.\n skipStandbyResult\n : void 0;\n\n const previousData = resultData.previousData;\n const currentResultOverride = React.useMemo(\n () =>\n resultOverride &&\n toQueryResult(resultOverride, previousData, observable, client),\n [client, observable, resultOverride, previousData]\n );\n\n return useSyncExternalStore(\n React.useCallback(\n (handleStoreChange) => {\n // reference `disableNetworkFetches` here to ensure that the rules of hooks\n // keep it as a dependency of this effect, even though it's not used\n disableNetworkFetches;\n\n if (isSyncSSR) {\n return () => {};\n }\n\n const onNext = () => {\n const previousResult = resultData.current;\n // We use `getCurrentResult()` instead of the onNext argument because\n // the values differ slightly. Specifically, loading results will have\n // an empty object for data instead of `undefined` for some reason.\n const result = observable.getCurrentResult();\n // Make sure we're not attempting to re-render similar results\n if (\n previousResult &&\n previousResult.loading === result.loading &&\n previousResult.networkStatus === result.networkStatus &&\n equal(previousResult.data, result.data)\n ) {\n return;\n }\n\n setResult(\n result,\n resultData,\n observable,\n client,\n partialRefetch,\n handleStoreChange,\n callbackRef.current\n );\n };\n\n const onError = (error: Error) => {\n subscription.current.unsubscribe();\n subscription.current = observable.resubscribeAfterError(\n onNext,\n onError\n );\n\n if (!hasOwnProperty.call(error, \"graphQLErrors\")) {\n // The error is not a GraphQL error\n throw error;\n }\n\n const previousResult = resultData.current;\n if (\n !previousResult ||\n (previousResult && previousResult.loading) ||\n !equal(error, previousResult.error)\n ) {\n setResult(\n {\n data: (previousResult &&\n previousResult.data) as MaybeMasked<TData>,\n error: error as ApolloError,\n loading: false,\n networkStatus: NetworkStatus.error,\n },\n resultData,\n observable,\n client,\n partialRefetch,\n handleStoreChange,\n callbackRef.current\n );\n }\n };\n\n // TODO evaluate if we keep this in\n // React Compiler cannot handle scoped `let` access, but a mutable object\n // like this is fine.\n // was:\n // let subscription = observable.subscribe(onNext, onError);\n const subscription = { current: observable.subscribe(onNext, onError) };\n\n // Do the \"unsubscribe\" with a short delay.\n // This way, an existing subscription can be reused without an additional\n // request if \"unsubscribe\" and \"resubscribe\" to the same ObservableQuery\n // happen in very fast succession.\n return () => {\n setTimeout(() => subscription.current.unsubscribe());\n };\n },\n\n [\n disableNetworkFetches,\n isSyncSSR,\n observable,\n resultData,\n partialRefetch,\n client,\n ]\n ),\n () =>\n currentResultOverride ||\n getCurrentResult(\n resultData,\n observable,\n callbackRef.current,\n partialRefetch,\n client\n ),\n () =>\n currentResultOverride ||\n getCurrentResult(\n resultData,\n observable,\n callbackRef.current,\n partialRefetch,\n client\n )\n );\n}\n\nfunction useRegisterSSRObservable(\n observable: ObsQueryWithMeta<any, any>,\n renderPromises: RenderPromises | undefined,\n ssrAllowed: boolean\n) {\n if (renderPromises && ssrAllowed) {\n renderPromises.registerSSRObservable(observable);\n\n if (observable.getCurrentResult().loading) {\n // TODO: This is a legacy API which could probably be cleaned up\n renderPromises.addObservableQueryPromise(observable);\n }\n }\n}\n\n// this hook is not compatible with any rules of React, and there's no good way to rewrite it.\n// it should stay a separate hook that will not be optimized by the compiler\nfunction useResubscribeIfNecessary<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n /** this hook will mutate properties on `resultData` */\n resultData: InternalResult<TData, TVariables>,\n /** this hook will mutate properties on `observable` */\n observable: ObsQueryWithMeta<TData, TVariables>,\n client: ApolloClient<object>,\n options: QueryHookOptions<NoInfer<TData>, NoInfer<TVariables>>,\n watchQueryOptions: Readonly<WatchQueryOptions<TVariables, TData>>\n) {\n if (\n observable[lastWatchOptions] &&\n !equal(observable[lastWatchOptions], watchQueryOptions)\n ) {\n // Though it might be tempting to postpone this reobserve call to the\n // useEffect block, we need getCurrentResult to return an appropriate\n // loading:true result synchronously (later within the same call to\n // useQuery). Since we already have this.observable here (not true for\n // the very first call to useQuery), we are not initiating any new\n // subscriptions, though it does feel less than ideal that reobserve\n // (potentially) kicks off a network request (for example, when the\n // variables have changed), which is technically a side-effect.\n observable.reobserve(\n getObsQueryOptions(observable, client, options, watchQueryOptions)\n );\n\n // Make sure getCurrentResult returns a fresh ApolloQueryResult<TData>,\n // but save the current data as this.previousData, just like setResult\n // usually does.\n resultData.previousData =\n resultData.current?.data || resultData.previousData;\n resultData.current = void 0;\n }\n observable[lastWatchOptions] = watchQueryOptions;\n}\n\n/*\n * A function to massage options before passing them to ObservableQuery.\n * This is two-step curried because we want to reuse the `make` function,\n * but the `observable` might differ between calls to `make`.\n */\nexport function createMakeWatchQueryOptions<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n client: ApolloClient<object>,\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n {\n skip,\n ssr,\n onCompleted,\n onError,\n defaultOptions,\n // The above options are useQuery-specific, so this ...otherOptions spread\n // makes otherOptions almost a WatchQueryOptions object, except for the\n // query property that we add below.\n ...otherOptions\n }: QueryHookOptions<TData, TVariables> = {},\n isSyncSSR: boolean\n) {\n return (\n observable?: ObservableQuery<TData, TVariables>\n ): WatchQueryOptions<TVariables, TData> => {\n // This Object.assign is safe because otherOptions is a fresh ...rest object\n // that did not exist until just now, so modifications are still allowed.\n const watchQueryOptions: WatchQueryOptions<TVariables, TData> =\n Object.assign(otherOptions, { query });\n\n if (\n isSyncSSR &&\n (watchQueryOptions.fetchPolicy === \"network-only\" ||\n watchQueryOptions.fetchPolicy === \"cache-and-network\")\n ) {\n // this behavior was added to react-apollo without explanation in this PR\n // https://github.com/apollographql/react-apollo/pull/1579\n watchQueryOptions.fetchPolicy = \"cache-first\";\n }\n\n if (!watchQueryOptions.variables) {\n watchQueryOptions.variables = {} as TVariables;\n }\n\n if (skip) {\n // When skipping, we set watchQueryOptions.fetchPolicy initially to\n // \"standby\", but we also need/want to preserve the initial non-standby\n // fetchPolicy that would have been used if not skipping.\n watchQueryOptions.initialFetchPolicy =\n watchQueryOptions.initialFetchPolicy ||\n watchQueryOptions.fetchPolicy ||\n getDefaultFetchPolicy(defaultOptions, client.defaultOptions);\n watchQueryOptions.fetchPolicy = \"standby\";\n } else if (!watchQueryOptions.fetchPolicy) {\n watchQueryOptions.fetchPolicy =\n observable?.options.initialFetchPolicy ||\n getDefaultFetchPolicy(defaultOptions, client.defaultOptions);\n }\n\n return watchQueryOptions;\n };\n}\n\nexport function getObsQueryOptions<\n TData,\n TVariables extends OperationVariables,\n>(\n observable: ObservableQuery<TData, TVariables> | undefined,\n client: ApolloClient<object>,\n queryHookOptions: QueryHookOptions<TData, TVariables>,\n watchQueryOptions: Partial<WatchQueryOptions<TVariables, TData>>\n): WatchQueryOptions<TVariables, TData> {\n const toMerge: Array<Partial<WatchQueryOptions<TVariables, TData>>> = [];\n\n const globalDefaults = client.defaultOptions.watchQuery;\n if (globalDefaults) toMerge.push(globalDefaults);\n\n if (queryHookOptions.defaultOptions) {\n toMerge.push(queryHookOptions.defaultOptions);\n }\n\n // We use compact rather than mergeOptions for this part of the merge,\n // because we want watchQueryOptions.variables (if defined) to replace\n // this.observable.options.variables whole. This replacement allows\n // removing variables by removing them from the variables input to\n // useQuery. If the variables were always merged together (rather than\n // replaced), there would be no way to remove existing variables.\n // However, the variables from options.defaultOptions and globalDefaults\n // (if provided) should be merged, to ensure individual defaulted\n // variables always have values, if not otherwise defined in\n // observable.options or watchQueryOptions.\n toMerge.push(compact(observable && observable.options, watchQueryOptions));\n\n return toMerge.reduce(mergeOptions) as WatchQueryOptions<TVariables, TData>;\n}\n\nfunction setResult<TData, TVariables extends OperationVariables>(\n nextResult: ApolloQueryResult<MaybeMasked<TData>>,\n resultData: InternalResult<TData, TVariables>,\n observable: ObservableQuery<TData, TVariables>,\n client: ApolloClient<object>,\n partialRefetch: boolean | undefined,\n forceUpdate: () => void,\n callbacks: Callbacks<TData>\n) {\n const previousResult = resultData.current;\n if (previousResult && previousResult.data) {\n resultData.previousData = previousResult.data;\n }\n\n if (!nextResult.error && isNonEmptyArray(nextResult.errors)) {\n // Until a set naming convention for networkError and graphQLErrors is\n // decided upon, we map errors (graphQLErrors) to the error options.\n // TODO: Is it possible for both result.error and result.errors to be\n // defined here?\n nextResult.error = new ApolloError({ graphQLErrors: nextResult.errors });\n }\n\n resultData.current = toQueryResult(\n unsafeHandlePartialRefetch(nextResult, observable, partialRefetch),\n resultData.previousData,\n observable,\n client\n );\n // Calling state.setResult always triggers an update, though some call sites\n // perform additional equality checks before committing to an update.\n forceUpdate();\n handleErrorOrCompleted(nextResult, previousResult?.networkStatus, callbacks);\n}\n\nfunction handleErrorOrCompleted<TData>(\n result: ApolloQueryResult<MaybeMasked<TData>>,\n previousNetworkStatus: NetworkStatus | undefined,\n callbacks: Callbacks<TData>\n) {\n if (!result.loading) {\n const error = toApolloError(result);\n\n // wait a tick in case we are in the middle of rendering a component\n Promise.resolve()\n .then(() => {\n if (error) {\n callbacks.onError(error);\n } else if (\n result.data &&\n previousNetworkStatus !== result.networkStatus &&\n result.networkStatus === NetworkStatus.ready\n ) {\n callbacks.onCompleted(result.data);\n }\n })\n .catch((error) => {\n invariant.warn(error);\n });\n }\n}\n\nfunction getCurrentResult<TData, TVariables extends OperationVariables>(\n resultData: InternalResult<TData, TVariables>,\n observable: ObservableQuery<TData, TVariables>,\n callbacks: Callbacks<TData>,\n partialRefetch: boolean | undefined,\n client: ApolloClient<object>\n): InternalQueryResult<TData, TVariables> {\n // Using this.result as a cache ensures getCurrentResult continues returning\n // the same (===) result object, unless state.setResult has been called, or\n // we're doing server rendering and therefore override the result below.\n if (!resultData.current) {\n // WARNING: SIDE-EFFECTS IN THE RENDER FUNCTION\n // this could call unsafeHandlePartialRefetch\n setResult(\n observable.getCurrentResult(),\n resultData,\n observable,\n client,\n partialRefetch,\n () => {},\n callbacks\n );\n }\n return resultData.current!;\n}\n\nexport function getDefaultFetchPolicy<\n TData,\n TVariables extends OperationVariables,\n>(\n queryHookDefaultOptions?: Partial<WatchQueryOptions<TVariables, TData>>,\n clientDefaultOptions?: DefaultOptions\n): WatchQueryFetchPolicy {\n return (\n queryHookDefaultOptions?.fetchPolicy ||\n clientDefaultOptions?.watchQuery?.fetchPolicy ||\n \"cache-first\"\n );\n}\n\nexport function toApolloError<TData>(\n result: Pick<ApolloQueryResult<TData>, \"errors\" | \"error\">\n): ApolloError | undefined {\n return isNonEmptyArray(result.errors) ?\n new ApolloError({ graphQLErrors: result.errors })\n : result.error;\n}\n\nexport function toQueryResult<TData, TVariables extends OperationVariables>(\n result: ApolloQueryResult<MaybeMasked<TData>>,\n previousData: MaybeMasked<TData> | undefined,\n observable: ObservableQuery<TData, TVariables>,\n client: ApolloClient<object>\n): InternalQueryResult<TData, TVariables> {\n const { data, partial, ...resultWithoutPartial } = result;\n const queryResult: InternalQueryResult<TData, TVariables> = {\n data, // Ensure always defined, even if result.data is missing.\n ...resultWithoutPartial,\n client: client,\n observable: observable,\n variables: observable.variables,\n called: result !== ssrDisabledResult && result !== skipStandbyResult,\n previousData,\n };\n return queryResult;\n}\n\nfunction unsafeHandlePartialRefetch<\n TData,\n TVariables extends OperationVariables,\n>(\n result: ApolloQueryResult<MaybeMasked<TData>>,\n observable: ObservableQuery<TData, TVariables>,\n partialRefetch: boolean | undefined\n): ApolloQueryResult<MaybeMasked<TData>> {\n // TODO: This code should be removed when the partialRefetch option is\n // removed. I was unable to get this hook to behave reasonably in certain\n // edge cases when this block was put in an effect.\n if (\n result.partial &&\n partialRefetch &&\n !result.loading &&\n (!result.data || Object.keys(result.data).length === 0) &&\n observable.options.fetchPolicy !== \"cache-only\"\n ) {\n observable.refetch();\n return {\n ...result,\n loading: true,\n networkStatus: NetworkStatus.refetch,\n };\n }\n return result;\n}\n\nconst ssrDisabledResult = maybeDeepFreeze({\n loading: true,\n data: void 0 as any,\n error: void 0,\n networkStatus: NetworkStatus.loading,\n});\n\nconst skipStandbyResult = maybeDeepFreeze({\n loading: false,\n data: void 0 as any,\n error: void 0,\n networkStatus: NetworkStatus.ready,\n});\n\nfunction bindObservableMethods<TData, TVariables extends OperationVariables>(\n observable: ObservableQuery<TData, TVariables>\n) {\n return {\n refetch: observable.refetch.bind(observable),\n reobserve: observable.reobserve.bind(observable),\n fetchMore: observable.fetchMore.bind(observable),\n updateQuery: observable.updateQuery.bind(observable),\n startPolling: observable.startPolling.bind(observable),\n stopPolling: observable.stopPolling.bind(observable),\n subscribeToMore: observable.subscribeToMore.bind(observable),\n };\n}\n"]}
|
|
@@ -23,7 +23,7 @@ import { wrapHook } from "./internal/index.js";
|
|
|
23
23
|
*/
|
|
24
24
|
export function useQueryRefHandlers(queryRef) {
|
|
25
25
|
var unwrapped = unwrapQueryRef(queryRef);
|
|
26
|
-
return wrapHook("useQueryRefHandlers",
|
|
26
|
+
return wrapHook("useQueryRefHandlers", useQueryRefHandlers_, unwrapped ?
|
|
27
27
|
unwrapped["observable"]
|
|
28
28
|
// in the case of a "transported" queryRef object, we need to use the
|
|
29
29
|
// client that's available to us at the current position in the React tree
|
|
@@ -35,7 +35,7 @@ export function useQueryRefHandlers(queryRef) {
|
|
|
35
35
|
// eslint-disable-next-line react-hooks/rules-of-hooks
|
|
36
36
|
: useApolloClient())(queryRef);
|
|
37
37
|
}
|
|
38
|
-
function
|
|
38
|
+
function useQueryRefHandlers_(queryRef) {
|
|
39
39
|
assertWrappedQueryRef(queryRef);
|
|
40
40
|
var _a = React.useState(queryRef), previousQueryRef = _a[0], setPreviousQueryRef = _a[1];
|
|
41
41
|
var _b = React.useState(queryRef), wrappedQueryRef = _b[0], setWrappedQueryRef = _b[1];
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQueryRefHandlers.js","sourceRoot":"","sources":["../../../src/react/hooks/useQueryRefHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,YAAY,GACb,MAAM,sBAAsB,CAAC;AAS9B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAc/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,MAAM,UAAU,mBAAmB,CAIjC,QAAqC;IAErC,IAAM,SAAS,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAE3C,OAAO,QAAQ,CACb,qBAAqB,EACrB,oBAAoB,EACpB,SAAS,CAAC,CAAC;QACT,SAAS,CAAC,YAAY,CAAC;QACvB,qEAAqE;QACrE,0EAA0E;QAC1E,4EAA4E;QAC5E,yBAAyB;QACzB,oEAAoE;QACpE,mEAAmE;QACnE,yDAAyD;QACzD,sDAAsD;QACxD,CAAC,CAAC,eAAe,EAAE,CACpB,CAAC,QAAQ,CAAC,CAAC;AACd,CAAC;AAED,SAAS,oBAAoB,CAI3B,QAAqC;IAErC,qBAAqB,CAAC,QAAQ,CAAC,CAAC;IAC1B,IAAA,KAA0C,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAAjE,gBAAgB,QAAA,EAAE,mBAAmB,QAA4B,CAAC;IACnE,IAAA,KAAwC,KAAK,CAAC,QAAQ,CAAC,QAAQ,CAAC,EAA/D,eAAe,QAAA,EAAE,kBAAkB,QAA4B,CAAC;IACvE,IAAM,gBAAgB,GAAG,cAAc,CAAC,QAAQ,CAAC,CAAC;IAElD,4EAA4E;IAC5E,2EAA2E;IAC3E,gEAAgE;IAChE,IAAI,gBAAgB,KAAK,QAAQ,EAAE,CAAC;QAClC,mBAAmB,CAAC,QAAQ,CAAC,CAAC;QAC9B,kBAAkB,CAAC,QAAQ,CAAC,CAAC;IAC/B,CAAC;SAAM,CAAC;QACN,qBAAqB,CAAC,QAAQ,EAAE,iBAAiB,CAAC,eAAe,CAAC,CAAC,CAAC;IACtE,CAAC;IAED,IAAM,OAAO,GAAuC,KAAK,CAAC,WAAW,CACnE,UAAC,SAAS;QACR,IAAM,OAAO,GAAG,gBAAgB,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;QAEpD,kBAAkB,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAEnD,OAAO,OAAO,CAAC;IACjB,CAAC,EACD,CAAC,gBAAgB,CAAC,CACnB,CAAC;IAEF,IAAM,SAAS,GAAyC,KAAK,CAAC,WAAW,CACvE,UAAC,OAAO;QACN,IAAM,OAAO,GAAG,gBAAgB,CAAC,SAAS,CACxC,OAA0C,CAC3C,CAAC;QAEF,kBAAkB,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAEnD,OAAO,OAAO,CAAC;IACjB,CAAC,EACD,CAAC,gBAAgB,CAAC,CACnB,CAAC;IAEF,OAAO;QACL,OAAO,SAAA;QACP,SAAS,WAAA;QACT,eAAe,EAAE,gBAAgB,CAAC,UAAU,CAAC,eAAe;KAC7D,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport {\n assertWrappedQueryRef,\n getWrappedPromise,\n unwrapQueryRef,\n updateWrappedQueryRef,\n wrapQueryRef,\n} from \"../internal/index.js\";\nimport type { QueryRef } from \"../internal/index.js\";\nimport type { OperationVariables } from \"../../core/types.js\";\nimport type {\n RefetchFunction,\n FetchMoreFunction,\n SubscribeToMoreFunction,\n} from \"./useSuspenseQuery.js\";\nimport type { FetchMoreQueryOptions } from \"../../core/watchQueryOptions.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { wrapHook } from \"./internal/index.js\";\n\nexport interface UseQueryRefHandlersResult<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n> {\n /** {@inheritDoc @apollo/client!ObservableQuery#refetch:member(1)} */\n refetch: RefetchFunction<TData, TVariables>;\n /** {@inheritDoc @apollo/client!ObservableQuery#fetchMore:member(1)} */\n fetchMore: FetchMoreFunction<TData, TVariables>;\n /** {@inheritDoc @apollo/client!ObservableQuery#subscribeToMore:member(1)} */\n subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;\n}\n\n/**\n * A React hook that returns a `refetch` and `fetchMore` function for a given\n * `queryRef`.\n *\n * This is useful to get access to handlers for a `queryRef` that was created by\n * `createQueryPreloader` or when the handlers for a `queryRef` produced in\n * a different component are inaccessible.\n *\n * @example\n * ```tsx\n * const MyComponent({ queryRef }) {\n * const { refetch, fetchMore } = useQueryRefHandlers(queryRef);\n *\n * // ...\n * }\n * ```\n * @since 3.9.0\n * @param queryRef - A `QueryRef` returned from `useBackgroundQuery`, `useLoadableQuery`, or `createQueryPreloader`.\n */\nexport function useQueryRefHandlers<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n queryRef: QueryRef<TData, TVariables>\n): UseQueryRefHandlersResult<TData, TVariables> {\n const unwrapped = unwrapQueryRef(queryRef);\n\n return wrapHook(\n \"useQueryRefHandlers\",\n
|
|
1
|
+
{"version":3,"file":"useQueryRefHandlers.js","sourceRoot":"","sources":["../../../src/react/hooks/useQueryRefHandlers.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,SAAS,CAAC;AACjC,OAAO,EACL,qBAAqB,EACrB,iBAAiB,EACjB,cAAc,EACd,qBAAqB,EACrB,YAAY,GACb,MAAM,sBAAsB,CAAC;AAS9B,OAAO,EAAE,eAAe,EAAE,MAAM,sBAAsB,CAAC;AACvD,OAAO,EAAE,QAAQ,EAAE,MAAM,qBAAqB,CAAC;AAc/C;;;;;;;;;;;;;;;;;;GAkBG;AACH,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ACD,CAAC,gBAAgB,CAAC,CACnB,CAAC;IAEF,IAAM,SAAS,GAAyC,KAAK,CAAC,WAAW,CACvE,UAAC,OAAO;QACN,IAAM,OAAO,GAAG,gBAAgB,CAAC,SAAS,CACxC,OAA0C,CAC3C,CAAC;QAEF,kBAAkB,CAAC,YAAY,CAAC,gBAAgB,CAAC,CAAC,CAAC;QAEnD,OAAO,OAAO,CAAC;IACjB,CAAC,EACD,CAAC,gBAAgB,CAAC,CACnB,CAAC;IAEF,OAAO;QACL,OAAO,SAAA;QACP,SAAS,WAAA;QACT,eAAe,EAAE,gBAAgB,CAAC,UAAU,CAAC,eAAe;KAC7D,CAAC;AACJ,CAAC","sourcesContent":["import * as React from \"rehackt\";\nimport {\n assertWrappedQueryRef,\n getWrappedPromise,\n unwrapQueryRef,\n updateWrappedQueryRef,\n wrapQueryRef,\n} from \"../internal/index.js\";\nimport type { QueryRef } from \"../internal/index.js\";\nimport type { OperationVariables } from \"../../core/types.js\";\nimport type {\n RefetchFunction,\n FetchMoreFunction,\n SubscribeToMoreFunction,\n} from \"./useSuspenseQuery.js\";\nimport type { FetchMoreQueryOptions } from \"../../core/watchQueryOptions.js\";\nimport { useApolloClient } from \"./useApolloClient.js\";\nimport { wrapHook } from \"./internal/index.js\";\n\nexport interface UseQueryRefHandlersResult<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n> {\n /** {@inheritDoc @apollo/client!ObservableQuery#refetch:member(1)} */\n refetch: RefetchFunction<TData, TVariables>;\n /** {@inheritDoc @apollo/client!ObservableQuery#fetchMore:member(1)} */\n fetchMore: FetchMoreFunction<TData, TVariables>;\n /** {@inheritDoc @apollo/client!ObservableQuery#subscribeToMore:member(1)} */\n subscribeToMore: SubscribeToMoreFunction<TData, TVariables>;\n}\n\n/**\n * A React hook that returns a `refetch` and `fetchMore` function for a given\n * `queryRef`.\n *\n * This is useful to get access to handlers for a `queryRef` that was created by\n * `createQueryPreloader` or when the handlers for a `queryRef` produced in\n * a different component are inaccessible.\n *\n * @example\n * ```tsx\n * const MyComponent({ queryRef }) {\n * const { refetch, fetchMore } = useQueryRefHandlers(queryRef);\n *\n * // ...\n * }\n * ```\n * @since 3.9.0\n * @param queryRef - A `QueryRef` returned from `useBackgroundQuery`, `useLoadableQuery`, or `createQueryPreloader`.\n */\nexport function useQueryRefHandlers<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n queryRef: QueryRef<TData, TVariables>\n): UseQueryRefHandlersResult<TData, TVariables> {\n const unwrapped = unwrapQueryRef(queryRef);\n\n return wrapHook(\n \"useQueryRefHandlers\",\n useQueryRefHandlers_,\n unwrapped ?\n unwrapped[\"observable\"]\n // in the case of a \"transported\" queryRef object, we need to use the\n // client that's available to us at the current position in the React tree\n // that ApolloClient will then have the job to recreate a real queryRef from\n // the transported object\n // This is just a context read - it's fine to do this conditionally.\n // This hook wrapper also shouldn't be optimized by React Compiler.\n // eslint-disable-next-line react-compiler/react-compiler\n // eslint-disable-next-line react-hooks/rules-of-hooks\n : useApolloClient()\n )(queryRef);\n}\n\nfunction useQueryRefHandlers_<\n TData = unknown,\n TVariables extends OperationVariables = OperationVariables,\n>(\n queryRef: QueryRef<TData, TVariables>\n): UseQueryRefHandlersResult<TData, TVariables> {\n assertWrappedQueryRef(queryRef);\n const [previousQueryRef, setPreviousQueryRef] = React.useState(queryRef);\n const [wrappedQueryRef, setWrappedQueryRef] = React.useState(queryRef);\n const internalQueryRef = unwrapQueryRef(queryRef);\n\n // To ensure we can support React transitions, this hook needs to manage the\n // queryRef state and apply React's state value immediately to the existing\n // queryRef since this hook doesn't return the queryRef directly\n if (previousQueryRef !== queryRef) {\n setPreviousQueryRef(queryRef);\n setWrappedQueryRef(queryRef);\n } else {\n updateWrappedQueryRef(queryRef, getWrappedPromise(wrappedQueryRef));\n }\n\n const refetch: RefetchFunction<TData, TVariables> = React.useCallback(\n (variables) => {\n const promise = internalQueryRef.refetch(variables);\n\n setWrappedQueryRef(wrapQueryRef(internalQueryRef));\n\n return promise;\n },\n [internalQueryRef]\n );\n\n const fetchMore: FetchMoreFunction<TData, TVariables> = React.useCallback(\n (options) => {\n const promise = internalQueryRef.fetchMore(\n options as FetchMoreQueryOptions<any, any>\n );\n\n setWrappedQueryRef(wrapQueryRef(internalQueryRef));\n\n return promise;\n },\n [internalQueryRef]\n );\n\n return {\n refetch,\n fetchMore,\n subscribeToMore: internalQueryRef.observable.subscribeToMore,\n };\n}\n"]}
|