@apollo/client 3.5.5 → 3.5.6
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/apollo-client.cjs +66 -71
- package/apollo-client.cjs.map +1 -1
- package/apollo-client.min.cjs +1 -1
- package/core/core.cjs +1 -1
- package/core/core.cjs.map +1 -1
- package/invariantErrorCodes.js +1 -1
- package/package.json +7 -7
- package/react/hooks/hooks.cjs +64 -69
- package/react/hooks/hooks.cjs.map +1 -1
- package/react/hooks/useMutation.d.ts.map +1 -1
- package/react/hooks/useMutation.js +59 -68
- package/react/hooks/useMutation.js.map +1 -1
- package/react/hooks/useQuery.d.ts.map +1 -1
- package/react/hooks/useQuery.js +6 -2
- package/react/hooks/useQuery.js.map +1 -1
- package/utilities/globals/global.d.ts.map +1 -1
- package/utilities/globals/global.js +1 -1
- package/utilities/globals/global.js.map +1 -1
- package/utilities/globals/globals.cjs +1 -1
- package/utilities/globals/globals.cjs.map +1 -1
- package/version.js +1 -1
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useMutation.js","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,
|
|
1
|
+
{"version":3,"file":"useMutation.js","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAUjE,OAAO,EAGL,YAAY,GAEb,MAAM,YAAY,CAAC;AACpB,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AACtC,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,UAAU,WAAW,CAMzB,QAA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K;oBACd,KAAK,OAAA;oBACL,IAAI,EAAE,KAAK,CAAC;oBACZ,MAAM,EAAE,IAAI;oBACZ,MAAM,QAAA;iBACP,CAAC;gBAEF,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,QAAM,CAAC,EAAE;oBACtC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,QAAM,CAAC,CAAC;iBACxC;aACF;YAED,IAAI,WAAW,CAAC,OAAO,IAAI,aAAa,CAAC,OAAO,EAAE;gBAChD,MAAA,WAAW,CAAC,OAAO,+CAAnB,WAAW,EAAW,KAAK,CAAC,CAAC;gBAC7B,MAAA,cAAc,CAAC,OAAO,+CAAtB,cAAc,EAAW,KAAK,CAAC,CAAC;gBAEhC,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;aACxC;YAED,MAAM,KAAK,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,IAAM,KAAK,GAAG,WAAW,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;IACvD,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,CAAC,cAAM,OAAA;QACd,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;IAChC,CAAC,EAFe,CAEf,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,aAAI,KAAK,OAAA,IAAK,MAAM,EAAG,CAAC;AACzC,CAAC","sourcesContent":["import { useCallback, useEffect, useRef, useState } from 'react';\nimport { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport {\n MutationFunctionOptions,\n MutationHookOptions,\n MutationResult,\n MutationTuple,\n} from '../types/types';\n\nimport {\n ApolloCache,\n DefaultContext,\n mergeOptions,\n OperationVariables,\n} from '../../core';\nimport { equal } from '@wry/equality';\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { ApolloError } from '../../errors';\nimport { useApolloClient } from './useApolloClient';\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<TData, TVariables, TContext>,\n): MutationTuple<TData, TVariables, TContext, TCache> {\n const client = useApolloClient(options?.client);\n verifyDocumentType(mutation, DocumentType.Mutation);\n const [result, setResult] = useState<Omit<MutationResult, 'reset'>>({\n called: false,\n loading: false,\n client,\n });\n\n const ref = useRef({\n result,\n mutationId: 0,\n isMounted: true,\n client,\n mutation,\n options,\n });\n\n // TODO: Trying to assign these in a useEffect or useLayoutEffect breaks\n // higher-order components.\n {\n Object.assign(ref.current, { client, options, mutation });\n }\n\n const execute = useCallback((\n executeOptions: MutationFunctionOptions<\n TData,\n TVariables,\n TContext,\n TCache\n > = {}\n ) => {\n const {client, options, mutation} = ref.current;\n const baseOptions = { ...options, mutation };\n if (!ref.current.result.loading && !baseOptions.ignoreResults) {\n setResult(ref.current.result = {\n loading: true,\n error: void 0,\n data: void 0,\n called: true,\n client,\n });\n }\n\n const mutationId = ++ref.current.mutationId;\n const clientOptions = mergeOptions(\n baseOptions,\n executeOptions as any,\n );\n\n return client.mutate(clientOptions).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 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 baseOptions.onCompleted?.(response.data!);\n executeOptions.onCompleted?.(response.data!);\n return response;\n }).catch((error) => {\n if (\n mutationId === ref.current.mutationId &&\n ref.current.isMounted\n ) {\n const result = {\n loading: false,\n error,\n data: void 0,\n called: true,\n client,\n };\n\n if (!equal(ref.current.result, result)) {\n setResult(ref.current.result = result);\n }\n }\n\n if (baseOptions.onError || clientOptions.onError) {\n baseOptions.onError?.(error);\n executeOptions.onError?.(error);\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 const reset = useCallback(() => {\n setResult({ called: false, loading: false, client });\n }, []);\n\n useEffect(() => () => {\n ref.current.isMounted = false;\n }, []);\n\n return [execute, { reset, ...result }];\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGhD,OAAO,EAIL,YAAY,EACZ,iBAAiB,EAElB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,gBAAgB,EAChB,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAKxB,wBAAgB,QAAQ,CACtB,KAAK,GAAG,GAAG,EACX,UAAU,GAAG,kBAAkB,EAE/B,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,GAC5C,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC,
|
|
1
|
+
{"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGhD,OAAO,EAIL,YAAY,EACZ,iBAAiB,EAElB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,gBAAgB,EAChB,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAKxB,wBAAgB,QAAQ,CACtB,KAAK,GAAG,GAAG,EACX,UAAU,GAAG,kBAAkB,EAE/B,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,GAC5C,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC,CAuShC"}
|
package/react/hooks/useQuery.js
CHANGED
|
@@ -102,7 +102,7 @@ export function useQuery(query, options) {
|
|
|
102
102
|
}
|
|
103
103
|
}
|
|
104
104
|
}
|
|
105
|
-
Object.assign(ref.current, { client: client, query: query
|
|
105
|
+
Object.assign(ref.current, { client: client, query: query });
|
|
106
106
|
}, [obsQuery, client, query, options]);
|
|
107
107
|
useEffect(function () {
|
|
108
108
|
if (context.renderPromises) {
|
|
@@ -172,6 +172,7 @@ export function useQuery(query, options) {
|
|
|
172
172
|
result.loading) {
|
|
173
173
|
obsQuery.setOptions(createWatchQueryOptions(query, options)).catch(function () { });
|
|
174
174
|
}
|
|
175
|
+
Object.assign(ref.current, { options: options });
|
|
175
176
|
}
|
|
176
177
|
if ((context.renderPromises || client.disableNetworkFetches) &&
|
|
177
178
|
(options === null || options === void 0 ? void 0 : options.ssr) === false) {
|
|
@@ -201,7 +202,7 @@ export function useQuery(query, options) {
|
|
|
201
202
|
stopPolling: obsQuery.stopPolling.bind(obsQuery),
|
|
202
203
|
subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
|
|
203
204
|
}); }, [obsQuery]);
|
|
204
|
-
return __assign(__assign(__assign({}, obsQueryFields), { variables:
|
|
205
|
+
return __assign(__assign(__assign({}, obsQueryFields), { variables: createWatchQueryOptions(query, options).variables, client: client, called: true, previousData: ref.current.previousData }), result);
|
|
205
206
|
}
|
|
206
207
|
function createWatchQueryOptions(query, options) {
|
|
207
208
|
var _a;
|
|
@@ -218,6 +219,9 @@ function createWatchQueryOptions(query, options) {
|
|
|
218
219
|
else if (!watchQueryOptions.fetchPolicy) {
|
|
219
220
|
watchQueryOptions.fetchPolicy = 'cache-first';
|
|
220
221
|
}
|
|
222
|
+
if (!watchQueryOptions.variables) {
|
|
223
|
+
watchQueryOptions.variables = {};
|
|
224
|
+
}
|
|
221
225
|
return __assign({ query: query }, watchQueryOptions);
|
|
222
226
|
}
|
|
223
227
|
//# sourceMappingURL=useQuery.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAEL,aAAa,GAKd,MAAM,YAAY,CAAC;AAMpB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,UAAU,QAAQ,CAItB,KAA0D,EAC1D,OAA6C;;IAE7C,IAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAC/C,IAAM,MAAM,GAAG,eAAe,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC,CAAC;IAChD,kBAAkB,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IACxC,IAAA,KAA0B,QAAQ,CAAC;QACvC,IAAM,iBAAiB,GAAG,uBAAuB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAIlE,IAAI,QAAQ,GAA8C,IAAI,CAAC;QAC/D,IAAI,OAAO,CAAC,cAAc,EAAE;YAC1B,QAAQ,GAAG,OAAO,CAAC,cAAc,CAAC,gBAAgB,CAAC,iBAAiB,CAAC,C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;QAChD,eAAe,EAAE,QAAQ,CAAC,eAAe,CAAC,IAAI,CAAC,QAAQ,CAAC;KACzD,CAAC,EAPmC,CAOnC,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC;IAEhB,sCACK,cAAc,KACjB,SAAS,EAAE,QAAQ,CAAC,SAAS,EAC7B,MAAM,QAAA,EACN,MAAM,EAAE,IAAI,EACZ,YAAY,EAAE,GAAG,CAAC,OAAO,CAAC,YAAY,KACnC,MAAM,EACT;AACJ,CAAC;AAED,SAAS,uBAAuB,CAC9B,KAA0D,EAC1D,OAAiD;;IAAjD,wBAAA,EAAA,YAAiD;IAM/C,IAAA,IAAI,GAMF,OAAO,KANL,EACJ,GAAG,GAKD,OAAO,IALN,EACH,WAAW,GAIT,OAAO,YAJE,EACX,OAAO,GAGL,OAAO,QAHF,EACP,WAAW,GAET,OAAO,YAFE,EACR,iBAAiB,UAClB,OAAO,EAPL,wDAOL,CADqB,CACV;IAEZ,IAAI,IAAI,EAAE;QACR,iBAAiB,CAAC,WAAW,GAAG,SAAS,CAAC;KAC3C;SAAM,IACL,CAAA,MAAA,iBAAiB,CAAC,OAAO,0CAAE,cAAc;QACzC,CACE,iBAAiB,CAAC,WAAW,KAAK,cAAc;YAChD,iBAAiB,CAAC,WAAW,KAAK,mBAAmB,CACtD,EACD;QAGA,iBAAiB,CAAC,WAAW,GAAG,aAAa,CAAC;KAC/C;SAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW,EAAE;QAGzC,iBAAiB,CAAC,WAAW,GAAG,aAAa,CAAC;KAC/C;IAED,kBAAS,KAAK,OAAA,IAAK,iBAAiB,EAAG;AACzC,CAAC","sourcesContent":["import { useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport { equal } from '@wry/equality';\nimport { OperationVariables } from '../../core';\nimport { getApolloContext } from '../context';\nimport { ApolloError } from '../../errors';\nimport {\n ApolloQueryResult,\n NetworkStatus,\n ObservableQuery,\n DocumentNode,\n TypedDocumentNode,\n WatchQueryOptions,\n} from '../../core';\nimport {\n QueryHookOptions,\n QueryResult,\n} from '../types/types';\n\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { useApolloClient } from './useApolloClient';\n\nexport function useQuery<\n TData = any,\n TVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: QueryHookOptions<TData, TVariables>,\n): QueryResult<TData, TVariables> {\n const context = useContext(getApolloContext());\n const client = useApolloClient(options?.client);\n verifyDocumentType(query, DocumentType.Query);\n const [obsQuery, setObsQuery] = useState(() => {\n const watchQueryOptions = createWatchQueryOptions(query, options);\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 let obsQuery: ObservableQuery<TData, TVariables> | null = null;\n if (context.renderPromises) {\n obsQuery = context.renderPromises.getSSRObservable(watchQueryOptions);\n }\n\n if (!obsQuery) {\n // Is it safe (StrictMode/memory-wise) to call client.watchQuery here?\n obsQuery = client.watchQuery(watchQueryOptions);\n if (context.renderPromises) {\n context.renderPromises.registerSSRObservable(\n obsQuery,\n watchQueryOptions,\n );\n }\n }\n\n if (\n context.renderPromises &&\n options?.ssr !== false &&\n !options?.skip &&\n obsQuery.getCurrentResult().loading\n ) {\n // TODO: This is a legacy API which could probably be cleaned up\n context.renderPromises.addQueryPromise(\n {\n // The only options which seem to actually be used by the\n // RenderPromises class are query and variables.\n getOptions: () => createWatchQueryOptions(query, options),\n fetchData: () => new Promise<void>((resolve) => {\n const sub = obsQuery!.subscribe({\n next(result) {\n if (!result.loading) {\n resolve()\n sub.unsubscribe();\n }\n },\n error() {\n resolve();\n sub.unsubscribe();\n },\n complete() {\n resolve();\n },\n });\n }),\n },\n // This callback never seemed to do anything\n () => null,\n );\n }\n\n return obsQuery;\n });\n\n let [result, setResult] = useState(() => {\n const result = obsQuery.getCurrentResult();\n if (!result.loading && options) {\n if (result.error) {\n options.onError?.(result.error);\n } else if (result.data) {\n options.onCompleted?.(result.data);\n }\n }\n\n return result;\n });\n\n const ref = useRef({\n client,\n query,\n options,\n result,\n previousData: void 0 as TData | undefined,\n watchQueryOptions: createWatchQueryOptions(query, options),\n });\n\n // An effect to recreate the obsQuery whenever the client or query changes.\n // This effect is also responsible for checking and updating the obsQuery\n // options whenever they change.\n useEffect(() => {\n const watchQueryOptions = createWatchQueryOptions(query, options);\n let nextResult: ApolloQueryResult<TData> | undefined;\n if (ref.current.client !== client || !equal(ref.current.query, query)) {\n const obsQuery = client.watchQuery(watchQueryOptions);\n setObsQuery(obsQuery);\n nextResult = obsQuery.getCurrentResult();\n } else if (!equal(ref.current.watchQueryOptions, watchQueryOptions)) {\n obsQuery.setOptions(watchQueryOptions).catch(() => {});\n nextResult = obsQuery.getCurrentResult();\n ref.current.watchQueryOptions = watchQueryOptions;\n }\n\n if (nextResult) {\n const previousResult = ref.current.result;\n if (previousResult.data) {\n ref.current.previousData = previousResult.data;\n }\n\n setResult(ref.current.result = nextResult);\n if (!nextResult.loading && options) {\n if (!result.loading) {\n if (result.error) {\n options.onError?.(result.error);\n } else if (result.data) {\n options.onCompleted?.(result.data);\n }\n }\n }\n }\n\n Object.assign(ref.current, { client, query, options });\n }, [obsQuery, client, query, options]);\n\n // An effect to subscribe to the current observable query\n useEffect(() => {\n if (context.renderPromises) {\n return;\n }\n\n let subscription = obsQuery.subscribe(onNext, onError);\n // We use `getCurrentResult()` instead of the callback 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 function onNext() {\n const previousResult = ref.current.result;\n const result = obsQuery.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 if (previousResult.data) {\n ref.current.previousData = previousResult.data;\n }\n\n setResult(ref.current.result = result);\n if (!result.loading) {\n ref.current.options?.onCompleted?.(result.data);\n }\n }\n\n function onError(error: Error) {\n const last = obsQuery[\"last\"];\n subscription.unsubscribe();\n // Unfortunately, if `lastError` is set in the current\n // `observableQuery` when the subscription is re-created,\n // the subscription will immediately receive the error, which will\n // cause it to terminate again. To avoid this, we first clear\n // the last error/result from the `observableQuery` before re-starting\n // the subscription, and restore it afterwards (so the subscription\n // has a chance to stay open).\n try {\n obsQuery.resetLastResults();\n subscription = obsQuery.subscribe(onNext, onError);\n } finally {\n obsQuery[\"last\"] = last;\n }\n\n if (!error.hasOwnProperty('graphQLErrors')) {\n // The error is not a GraphQL error\n throw error;\n }\n\n const previousResult = ref.current.result;\n if (\n (previousResult && previousResult.loading) ||\n !equal(error, previousResult.error)\n ) {\n setResult(ref.current.result = {\n data: previousResult.data,\n error: error as ApolloError,\n loading: false,\n networkStatus: NetworkStatus.error,\n });\n ref.current.options?.onError?.(error as ApolloError);\n }\n }\n\n return () => subscription.unsubscribe();\n }, [obsQuery, context.renderPromises, client.disableNetworkFetches]);\n\n let partial: boolean | undefined;\n ({ partial, ...result } = result);\n\n {\n // BAD BOY CODE BLOCK WHERE WE PUT SIDE-EFFECTS IN THE RENDER FUNCTION\n //\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 partial &&\n options?.partialRefetch &&\n !result.loading &&\n (!result.data || Object.keys(result.data).length === 0) &&\n obsQuery.options.fetchPolicy !== 'cache-only'\n ) {\n result = {\n ...result,\n loading: true,\n networkStatus: NetworkStatus.refetch,\n };\n\n obsQuery.refetch();\n }\n\n // TODO: This is a hack to make sure useLazyQuery executions update the\n // obsevable query options for ssr.\n if (\n context.renderPromises &&\n options?.ssr !== false &&\n !options?.skip &&\n result.loading\n ) {\n obsQuery.setOptions(createWatchQueryOptions(query, options)).catch(() => {});\n }\n }\n\n if (\n (context.renderPromises || client.disableNetworkFetches) &&\n options?.ssr === false\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 result = ref.current.result = {\n loading: true,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.loading,\n };\n } else if (options?.skip || options?.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 result = {\n loading: false,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.ready,\n };\n }\n\n if (result.errors && result.errors.length) {\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 result = {\n ...result,\n error: result.error || new ApolloError({ graphQLErrors: result.errors }),\n };\n }\n\n const obsQueryFields = useMemo(() => ({\n refetch: obsQuery.refetch.bind(obsQuery),\n fetchMore: obsQuery.fetchMore.bind(obsQuery),\n updateQuery: obsQuery.updateQuery.bind(obsQuery),\n startPolling: obsQuery.startPolling.bind(obsQuery),\n stopPolling: obsQuery.stopPolling.bind(obsQuery),\n subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),\n }), [obsQuery]);\n\n return {\n ...obsQueryFields,\n variables: obsQuery.variables,\n client,\n called: true,\n previousData: ref.current.previousData,\n ...result,\n };\n}\n\nfunction createWatchQueryOptions<TData, TVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<TData, TVariables> = {},\n): WatchQueryOptions<TVariables, TData> {\n // TODO: For some reason, we pass context, which is the React Apollo Context,\n // into observable queries, and test for that.\n // removing hook specific options\n const {\n skip,\n ssr,\n onCompleted,\n onError,\n displayName,\n ...watchQueryOptions\n } = options;\n\n if (skip) {\n watchQueryOptions.fetchPolicy = 'standby';\n } else if (\n watchQueryOptions.context?.renderPromises &&\n (\n watchQueryOptions.fetchPolicy === 'network-only' ||\n watchQueryOptions.fetchPolicy === 'cache-and-network'\n )\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 } else if (!watchQueryOptions.fetchPolicy) {\n // cache-first is the default policy, but we explicitly assign it here so\n // the cache policies computed based on options can be cleared\n watchQueryOptions.fetchPolicy = 'cache-first';\n }\n\n return { query, ...watchQueryOptions };\n}\n"]}
|
|
1
|
+
{"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAEL,aAAa,GAKd,MAAM,YAAY,CAAC;AAMpB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAEpD,MAAM,UAAU,QAAQ,CAItB,KAA0D,EAC1D,OAA6C;;IAE7C,IAAM,OAAO,GAAG,UAAU,CAAC,gBAAgB,EAAE,CAAC,CAAC;IAC/C,IAAM,MAAM,GAAG,eAAe,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC,CAAC;IAChD,kBAAkB,CAAC,KAAK,EAAE,YAAY,CAAC,KAAK,CAAC,CAAC;IACxC,IAAA,KAA0B,QAAQ,CAAC;QACvC,IAAM,iBAAiB,GAAG,uBAAuB,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;QAIlE,IAAI,QAAQ,GAA8C,IAAI,CAAC;QAC/D,I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C,SAAS,GAAG,EAAgB,CAAC;KAChD;IAED,kBAAS,KAAK,OAAA,IAAK,iBAAiB,EAAG;AACzC,CAAC","sourcesContent":["import { useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport { equal } from '@wry/equality';\nimport { OperationVariables } from '../../core';\nimport { getApolloContext } from '../context';\nimport { ApolloError } from '../../errors';\nimport {\n ApolloQueryResult,\n NetworkStatus,\n ObservableQuery,\n DocumentNode,\n TypedDocumentNode,\n WatchQueryOptions,\n} from '../../core';\nimport {\n QueryHookOptions,\n QueryResult,\n} from '../types/types';\n\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { useApolloClient } from './useApolloClient';\n\nexport function useQuery<\n TData = any,\n TVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: QueryHookOptions<TData, TVariables>,\n): QueryResult<TData, TVariables> {\n const context = useContext(getApolloContext());\n const client = useApolloClient(options?.client);\n verifyDocumentType(query, DocumentType.Query);\n const [obsQuery, setObsQuery] = useState(() => {\n const watchQueryOptions = createWatchQueryOptions(query, options);\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 let obsQuery: ObservableQuery<TData, TVariables> | null = null;\n if (context.renderPromises) {\n obsQuery = context.renderPromises.getSSRObservable(watchQueryOptions);\n }\n\n if (!obsQuery) {\n // Is it safe (StrictMode/memory-wise) to call client.watchQuery here?\n obsQuery = client.watchQuery(watchQueryOptions);\n if (context.renderPromises) {\n context.renderPromises.registerSSRObservable(\n obsQuery,\n watchQueryOptions,\n );\n }\n }\n\n if (\n context.renderPromises &&\n options?.ssr !== false &&\n !options?.skip &&\n obsQuery.getCurrentResult().loading\n ) {\n // TODO: This is a legacy API which could probably be cleaned up\n context.renderPromises.addQueryPromise(\n {\n // The only options which seem to actually be used by the\n // RenderPromises class are query and variables.\n getOptions: () => createWatchQueryOptions(query, options),\n fetchData: () => new Promise<void>((resolve) => {\n const sub = obsQuery!.subscribe({\n next(result) {\n if (!result.loading) {\n resolve()\n sub.unsubscribe();\n }\n },\n error() {\n resolve();\n sub.unsubscribe();\n },\n complete() {\n resolve();\n },\n });\n }),\n },\n // This callback never seemed to do anything\n () => null,\n );\n }\n\n return obsQuery;\n });\n\n let [result, setResult] = useState(() => {\n const result = obsQuery.getCurrentResult();\n if (!result.loading && options) {\n if (result.error) {\n options.onError?.(result.error);\n } else if (result.data) {\n options.onCompleted?.(result.data);\n }\n }\n\n return result;\n });\n\n const ref = useRef({\n client,\n query,\n options,\n result,\n previousData: void 0 as TData | undefined,\n watchQueryOptions: createWatchQueryOptions(query, options),\n });\n\n // An effect to recreate the obsQuery whenever the client or query changes.\n // This effect is also responsible for checking and updating the obsQuery\n // options whenever they change.\n useEffect(() => {\n const watchQueryOptions = createWatchQueryOptions(query, options);\n let nextResult: ApolloQueryResult<TData> | undefined;\n if (ref.current.client !== client || !equal(ref.current.query, query)) {\n const obsQuery = client.watchQuery(watchQueryOptions);\n setObsQuery(obsQuery);\n nextResult = obsQuery.getCurrentResult();\n } else if (!equal(ref.current.watchQueryOptions, watchQueryOptions)) {\n obsQuery.setOptions(watchQueryOptions).catch(() => {});\n nextResult = obsQuery.getCurrentResult();\n ref.current.watchQueryOptions = watchQueryOptions;\n }\n\n if (nextResult) {\n const previousResult = ref.current.result;\n if (previousResult.data) {\n ref.current.previousData = previousResult.data;\n }\n\n setResult(ref.current.result = nextResult);\n if (!nextResult.loading && options) {\n if (!result.loading) {\n if (result.error) {\n options.onError?.(result.error);\n } else if (result.data) {\n options.onCompleted?.(result.data);\n }\n }\n }\n }\n\n Object.assign(ref.current, { client, query });\n }, [obsQuery, client, query, options]);\n\n // An effect to subscribe to the current observable query\n useEffect(() => {\n if (context.renderPromises) {\n return;\n }\n\n let subscription = obsQuery.subscribe(onNext, onError);\n // We use `getCurrentResult()` instead of the callback 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 function onNext() {\n const previousResult = ref.current.result;\n const result = obsQuery.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 if (previousResult.data) {\n ref.current.previousData = previousResult.data;\n }\n\n setResult(ref.current.result = result);\n if (!result.loading) {\n ref.current.options?.onCompleted?.(result.data);\n }\n }\n\n function onError(error: Error) {\n const last = obsQuery[\"last\"];\n subscription.unsubscribe();\n // Unfortunately, if `lastError` is set in the current\n // `observableQuery` when the subscription is re-created,\n // the subscription will immediately receive the error, which will\n // cause it to terminate again. To avoid this, we first clear\n // the last error/result from the `observableQuery` before re-starting\n // the subscription, and restore it afterwards (so the subscription\n // has a chance to stay open).\n try {\n obsQuery.resetLastResults();\n subscription = obsQuery.subscribe(onNext, onError);\n } finally {\n obsQuery[\"last\"] = last;\n }\n\n if (!error.hasOwnProperty('graphQLErrors')) {\n // The error is not a GraphQL error\n throw error;\n }\n\n const previousResult = ref.current.result;\n if (\n (previousResult && previousResult.loading) ||\n !equal(error, previousResult.error)\n ) {\n setResult(ref.current.result = {\n data: previousResult.data,\n error: error as ApolloError,\n loading: false,\n networkStatus: NetworkStatus.error,\n });\n ref.current.options?.onError?.(error as ApolloError);\n }\n }\n\n return () => subscription.unsubscribe();\n }, [obsQuery, context.renderPromises, client.disableNetworkFetches]);\n\n let partial: boolean | undefined;\n ({ partial, ...result } = result);\n\n {\n // BAD BOY CODE BLOCK WHERE WE PUT SIDE-EFFECTS IN THE RENDER FUNCTION\n //\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 partial &&\n options?.partialRefetch &&\n !result.loading &&\n (!result.data || Object.keys(result.data).length === 0) &&\n obsQuery.options.fetchPolicy !== 'cache-only'\n ) {\n result = {\n ...result,\n loading: true,\n networkStatus: NetworkStatus.refetch,\n };\n\n obsQuery.refetch();\n }\n\n // TODO: This is a hack to make sure useLazyQuery executions update the\n // obsevable query options for ssr.\n if (\n context.renderPromises &&\n options?.ssr !== false &&\n !options?.skip &&\n result.loading\n ) {\n obsQuery.setOptions(createWatchQueryOptions(query, options)).catch(() => {});\n }\n\n // We assign options during rendering as a guard to make sure that\n // callbacks like onCompleted and onError are not stale.\n Object.assign(ref.current, { options });\n }\n\n if (\n (context.renderPromises || client.disableNetworkFetches) &&\n options?.ssr === false\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 result = ref.current.result = {\n loading: true,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.loading,\n };\n } else if (options?.skip || options?.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 result = {\n loading: false,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.ready,\n };\n }\n\n if (result.errors && result.errors.length) {\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 result = {\n ...result,\n error: result.error || new ApolloError({ graphQLErrors: result.errors }),\n };\n }\n\n const obsQueryFields = useMemo(() => ({\n refetch: obsQuery.refetch.bind(obsQuery),\n fetchMore: obsQuery.fetchMore.bind(obsQuery),\n updateQuery: obsQuery.updateQuery.bind(obsQuery),\n startPolling: obsQuery.startPolling.bind(obsQuery),\n stopPolling: obsQuery.stopPolling.bind(obsQuery),\n subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),\n }), [obsQuery]);\n\n return {\n ...obsQueryFields,\n variables: createWatchQueryOptions(query, options).variables,\n client,\n called: true,\n previousData: ref.current.previousData,\n ...result,\n };\n}\n\n/**\n * A function to massage options before passing them the ObservableQuery.\n */\nfunction createWatchQueryOptions<TData, TVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<TData, TVariables> = {},\n): WatchQueryOptions<TVariables, TData> {\n // TODO: For some reason, we pass context, which is the React Apollo Context,\n // into observable queries, and test for that.\n // removing hook specific options\n const {\n skip,\n ssr,\n onCompleted,\n onError,\n displayName,\n ...watchQueryOptions\n } = options;\n\n if (skip) {\n watchQueryOptions.fetchPolicy = 'standby';\n } else if (\n watchQueryOptions.context?.renderPromises &&\n (\n watchQueryOptions.fetchPolicy === 'network-only' ||\n watchQueryOptions.fetchPolicy === 'cache-and-network'\n )\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 } else if (!watchQueryOptions.fetchPolicy) {\n // cache-first is the default policy, but we explicitly assign it here so\n // the cache policies computed based on options can be cleared\n watchQueryOptions.fetchPolicy = 'cache-first';\n }\n\n if (!watchQueryOptions.variables) {\n watchQueryOptions.variables = {} as TVariables;\n }\n\n return { query, ...watchQueryOptions };\n}\n"]}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../../../src/utilities/globals/global.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;CACpC;;
|
|
1
|
+
{"version":3,"file":"global.d.ts","sourceRoot":"","sources":["../../../src/utilities/globals/global.ts"],"names":[],"mappings":"AAEA,OAAO,CAAC,MAAM,CAAC;IACb,MAAM,OAAO,EAAE,OAAO,GAAG,SAAS,CAAC;CACpC;;aAeU,cAAc;;AAbzB,wBAcE"}
|
|
@@ -3,5 +3,5 @@ export default (maybe(function () { return globalThis; }) ||
|
|
|
3
3
|
maybe(function () { return window; }) ||
|
|
4
4
|
maybe(function () { return self; }) ||
|
|
5
5
|
maybe(function () { return global; }) ||
|
|
6
|
-
maybe(function () { return
|
|
6
|
+
maybe(function () { return maybe.constructor("return this")(); }));
|
|
7
7
|
//# sourceMappingURL=global.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../../src/utilities/globals/global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAMhC,eAAe,CACb,KAAK,CAAC,cAAM,OAAA,UAAU,EAAV,CAAU,CAAC;IACvB,KAAK,CAAC,cAAM,OAAA,MAAM,EAAN,CAAM,CAAC;IACnB,KAAK,CAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC;IACjB,KAAK,CAAC,cAAM,OAAA,MAAM,EAAN,CAAM,CAAC;
|
|
1
|
+
{"version":3,"file":"global.js","sourceRoot":"","sources":["../../../src/utilities/globals/global.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,SAAS,CAAC;AAMhC,eAAe,CACb,KAAK,CAAC,cAAM,OAAA,UAAU,EAAV,CAAU,CAAC;IACvB,KAAK,CAAC,cAAM,OAAA,MAAM,EAAN,CAAM,CAAC;IACnB,KAAK,CAAC,cAAM,OAAA,IAAI,EAAJ,CAAI,CAAC;IACjB,KAAK,CAAC,cAAM,OAAA,MAAM,EAAN,CAAM,CAAC;IAOnB,KAAK,CAAC,cAAa,OAAO,KAAK,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,CAAA,CAAC,CAAC,CAAC,CAGhE,CAAC","sourcesContent":["import { maybe } from \"./maybe\";\n\ndeclare global {\n const __DEV__: boolean | undefined;\n}\n\nexport default (\n maybe(() => globalThis) ||\n maybe(() => window) ||\n maybe(() => self) ||\n maybe(() => global) ||\n // We don't expect the Function constructor ever to be invoked at runtime, as\n // long as at least one of globalThis, window, self, or global is defined, so\n // we are under no obligation to make it easy for static analysis tools to\n // detect syntactic usage of the Function constructor. If you think you can\n // improve your static analysis to detect this obfuscation, think again. This\n // is an arms race you cannot win, at least not in JavaScript.\n maybe(function() { return maybe.constructor(\"return this\")() })\n) as typeof globalThis & {\n __DEV__: typeof __DEV__;\n};\n"]}
|
|
@@ -17,7 +17,7 @@ var global$1 = (maybe(function () { return globalThis; }) ||
|
|
|
17
17
|
maybe(function () { return window; }) ||
|
|
18
18
|
maybe(function () { return self; }) ||
|
|
19
19
|
maybe(function () { return global; }) ||
|
|
20
|
-
maybe(function () { return
|
|
20
|
+
maybe(function () { return maybe.constructor("return this")(); }));
|
|
21
21
|
|
|
22
22
|
var __ = "__";
|
|
23
23
|
var GLOBAL_KEY = [__, __].join("DEV");
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"globals.cjs","sources":["maybe.js","global.js","DEV.js","fix-graphql.js","index.js"],"sourcesContent":["export function maybe(thunk) {\n try {\n return thunk();\n }\n catch (_a) { }\n}\n//# sourceMappingURL=maybe.js.map","import { maybe } from \"./maybe\";\nexport default (maybe(function () { return globalThis; }) ||\n maybe(function () { return window; }) ||\n maybe(function () { return self; }) ||\n maybe(function () { return global; }) ||\n maybe(function () { return
|
|
1
|
+
{"version":3,"file":"globals.cjs","sources":["maybe.js","global.js","DEV.js","fix-graphql.js","index.js"],"sourcesContent":["export function maybe(thunk) {\n try {\n return thunk();\n }\n catch (_a) { }\n}\n//# sourceMappingURL=maybe.js.map","import { maybe } from \"./maybe\";\nexport default (maybe(function () { return globalThis; }) ||\n maybe(function () { return window; }) ||\n maybe(function () { return self; }) ||\n maybe(function () { return global; }) ||\n maybe(function () { return maybe.constructor(\"return this\")(); }));\n//# sourceMappingURL=global.js.map","import global from \"./global\";\nimport { maybe } from \"./maybe\";\nvar __ = \"__\";\nvar GLOBAL_KEY = [__, __].join(\"DEV\");\nfunction getDEV() {\n try {\n return Boolean(__DEV__);\n }\n catch (_a) {\n Object.defineProperty(global, GLOBAL_KEY, {\n value: maybe(function () { return process.env.NODE_ENV; }) !== \"production\",\n enumerable: false,\n configurable: true,\n writable: true,\n });\n return global[GLOBAL_KEY];\n }\n}\nexport default getDEV();\n//# sourceMappingURL=DEV.js.map","import { remove } from 'ts-invariant/process';\nimport { Source } from 'graphql';\nexport function removeTemporaryGlobals() {\n return typeof Source === \"function\" ? remove() : remove();\n}\n//# sourceMappingURL=fix-graphql.js.map","import { invariant, InvariantError } from \"ts-invariant\";\nimport DEV from \"./DEV\";\nexport { DEV };\nexport function checkDEV() {\n __DEV__ ? invariant(\"boolean\" === typeof DEV, DEV) : invariant(\"boolean\" === typeof DEV, 36);\n}\nimport { removeTemporaryGlobals } from \"./fix-graphql\";\nremoveTemporaryGlobals();\nexport { maybe } from \"./maybe\";\nexport { default as global } from \"./global\";\nexport { invariant, InvariantError };\ncheckDEV();\n//# sourceMappingURL=index.js.map"],"names":["global","Source","remove","invariant"],"mappings":";;;;;;;;AAAO,SAAS,KAAK,CAAC,KAAK,EAAE;AAC7B,IAAI,IAAI;AACR,QAAQ,OAAO,KAAK,EAAE,CAAC;AACvB,KAAK;AACL,IAAI,OAAO,EAAE,EAAE,GAAG;AAClB;;ACJA,eAAe,CAAC,KAAK,CAAC,YAAY,EAAE,OAAO,UAAU,CAAC,EAAE,CAAC;AACzD,IAAI,KAAK,CAAC,YAAY,EAAE,OAAO,MAAM,CAAC,EAAE,CAAC;AACzC,IAAI,KAAK,CAAC,YAAY,EAAE,OAAO,IAAI,CAAC,EAAE,CAAC;AACvC,IAAI,KAAK,CAAC,YAAY,EAAE,OAAO,MAAM,CAAC,EAAE,CAAC;AACzC,IAAI,KAAK,CAAC,YAAY,EAAE,OAAO,KAAK,CAAC,WAAW,CAAC,aAAa,CAAC,EAAE,CAAC,EAAE,CAAC;;ACHrE,IAAI,EAAE,GAAG,IAAI,CAAC;AACd,IAAI,UAAU,GAAG,CAAC,EAAE,EAAE,EAAE,CAAC,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC;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