@apollo/client 3.7.10 → 3.7.12

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.
Files changed (66) hide show
  1. package/apollo-client.cjs +182 -145
  2. package/apollo-client.cjs.map +1 -1
  3. package/apollo-client.min.cjs +1 -1
  4. package/core/ApolloClient.d.ts.map +1 -1
  5. package/core/ApolloClient.js.map +1 -1
  6. package/core/ObservableQuery.d.ts +2 -1
  7. package/core/ObservableQuery.d.ts.map +1 -1
  8. package/core/ObservableQuery.js +8 -5
  9. package/core/ObservableQuery.js.map +1 -1
  10. package/core/QueryManager.d.ts +1 -0
  11. package/core/QueryManager.d.ts.map +1 -1
  12. package/core/QueryManager.js +52 -43
  13. package/core/QueryManager.js.map +1 -1
  14. package/core/core.cjs +63 -52
  15. package/core/core.cjs.map +1 -1
  16. package/core/core.cjs.native.js +63 -52
  17. package/errors/errors.cjs +17 -17
  18. package/errors/errors.cjs.map +1 -1
  19. package/errors/errors.cjs.native.js +17 -17
  20. package/errors/index.d.ts +24 -8
  21. package/errors/index.d.ts.map +1 -1
  22. package/errors/index.js +17 -19
  23. package/errors/index.js.map +1 -1
  24. package/invariantErrorCodes.js +1 -1
  25. package/link/core/types.d.ts +4 -0
  26. package/link/core/types.d.ts.map +1 -1
  27. package/link/core/types.js.map +1 -1
  28. package/link/http/createHttpLink.d.ts.map +1 -1
  29. package/link/http/createHttpLink.js +19 -3
  30. package/link/http/createHttpLink.js.map +1 -1
  31. package/link/http/http.cjs +57 -15
  32. package/link/http/http.cjs.map +1 -1
  33. package/link/http/http.cjs.native.js +57 -15
  34. package/link/http/parseAndCheckHttpResponse.d.ts.map +1 -1
  35. package/link/http/parseAndCheckHttpResponse.js +34 -14
  36. package/link/http/parseAndCheckHttpResponse.js.map +1 -1
  37. package/link/subscriptions/index.d.ts.map +1 -1
  38. package/link/subscriptions/index.js +8 -3
  39. package/link/subscriptions/index.js.map +1 -1
  40. package/link/subscriptions/subscriptions.cjs +8 -3
  41. package/link/subscriptions/subscriptions.cjs.map +1 -1
  42. package/link/subscriptions/subscriptions.cjs.native.js +8 -3
  43. package/package.json +22 -23
  44. package/react/hooks/hooks.cjs +36 -44
  45. package/react/hooks/hooks.cjs.map +1 -1
  46. package/react/hooks/hooks.cjs.native.js +36 -44
  47. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  48. package/react/hooks/useLazyQuery.js +11 -20
  49. package/react/hooks/useLazyQuery.js.map +1 -1
  50. package/react/hooks/useQuery.d.ts +1 -3
  51. package/react/hooks/useQuery.d.ts.map +1 -1
  52. package/react/hooks/useQuery.js +27 -26
  53. package/react/hooks/useQuery.js.map +1 -1
  54. package/testing/core/itAsync.js.map +1 -1
  55. package/testing/core/mocking/mockSubscriptionLink.d.ts +1 -1
  56. package/testing/react/MockedProvider.js +5 -4
  57. package/testing/react/MockedProvider.js.map +1 -1
  58. package/testing/testing.cjs +4 -2
  59. package/testing/testing.cjs.map +1 -1
  60. package/testing/testing.cjs.native.js +4 -2
  61. package/utilities/common/incrementalResult.d.ts +2 -1
  62. package/utilities/common/incrementalResult.d.ts.map +1 -1
  63. package/utilities/common/incrementalResult.js +4 -0
  64. package/utilities/common/incrementalResult.js.map +1 -1
  65. package/utilities/utilities.cjs.map +1 -1
  66. package/version.js +1 -1
@@ -9,7 +9,7 @@ import { ApolloError } from "../../errors/index.js";
9
9
  import { NetworkStatus, } from "../../core/index.js";
10
10
  import { DocumentType, verifyDocumentType } from "../parser/index.js";
11
11
  import { useApolloClient } from "./useApolloClient.js";
12
- import { canUseWeakMap, canUseWeakSet, compact, isNonEmptyArray, maybeDeepFreeze } from "../../utilities/index.js";
12
+ import { canUseWeakMap, compact, isNonEmptyArray, maybeDeepFreeze } from "../../utilities/index.js";
13
13
  var hasOwnProperty = Object.prototype.hasOwnProperty;
14
14
  export function useQuery(query, options) {
15
15
  if (options === void 0) { options = Object.create(null); }
@@ -33,8 +33,6 @@ var InternalState = (function () {
33
33
  function InternalState(client, query, previous) {
34
34
  this.client = client;
35
35
  this.query = query;
36
- this.asyncResolveFns = new Set();
37
- this.optionsToIgnoreOnce = new (canUseWeakSet ? WeakSet : Set)();
38
36
  this.ssrDisabledResult = maybeDeepFreeze({
39
37
  loading: true,
40
38
  data: void 0,
@@ -58,20 +56,30 @@ var InternalState = (function () {
58
56
  InternalState.prototype.forceUpdate = function () {
59
57
  __DEV__ && invariant.warn("Calling default no-op implementation of InternalState#forceUpdate");
60
58
  };
61
- InternalState.prototype.asyncUpdate = function (signal) {
59
+ InternalState.prototype.executeQuery = function (options) {
62
60
  var _this = this;
63
- return new Promise(function (resolve, reject) {
64
- var watchQueryOptions = _this.watchQueryOptions;
65
- var handleAborted = function () {
66
- _this.asyncResolveFns.delete(resolve);
67
- _this.optionsToIgnoreOnce.delete(watchQueryOptions);
68
- signal.removeEventListener('abort', handleAborted);
69
- reject(signal.reason);
70
- };
71
- _this.asyncResolveFns.add(resolve);
72
- _this.optionsToIgnoreOnce.add(watchQueryOptions);
73
- signal.addEventListener('abort', handleAborted);
74
- _this.forceUpdate();
61
+ var _a;
62
+ if (options.query) {
63
+ Object.assign(this, { query: options.query });
64
+ }
65
+ this.watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
66
+ var concast = this.observable.reobserveAsConcast(this.getObsQueryOptions());
67
+ this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
68
+ this.result = void 0;
69
+ this.forceUpdate();
70
+ return new Promise(function (resolve) {
71
+ var result;
72
+ concast.subscribe({
73
+ next: function (value) {
74
+ result = value;
75
+ },
76
+ error: function () {
77
+ resolve(_this.toQueryResult(_this.observable.getCurrentResult()));
78
+ },
79
+ complete: function () {
80
+ resolve(_this.toQueryResult(result));
81
+ }
82
+ });
75
83
  });
76
84
  };
77
85
  InternalState.prototype.useQuery = function (options) {
@@ -120,29 +128,22 @@ var InternalState = (function () {
120
128
  }
121
129
  };
122
130
  var subscription = obsQuery.subscribe(onNext, onError);
123
- return function () { return subscription.unsubscribe(); };
131
+ return function () { return setTimeout(function () { return subscription.unsubscribe(); }); };
124
132
  }, [
125
133
  obsQuery,
126
134
  this.renderPromises,
127
135
  this.client.disableNetworkFetches,
128
136
  ]), function () { return _this.getCurrentResult(); }, function () { return _this.getCurrentResult(); });
129
137
  this.unsafeHandlePartialRefetch(result);
130
- var queryResult = this.toQueryResult(result);
131
- if (!queryResult.loading && this.asyncResolveFns.size) {
132
- this.asyncResolveFns.forEach(function (resolve) { return resolve(queryResult); });
133
- this.asyncResolveFns.clear();
134
- }
135
- return queryResult;
138
+ return this.toQueryResult(result);
136
139
  };
137
140
  InternalState.prototype.useOptions = function (options) {
138
141
  var _a;
139
142
  var watchQueryOptions = this.createWatchQueryOptions(this.queryHookOptions = options);
140
143
  var currentWatchQueryOptions = this.watchQueryOptions;
141
- if (this.optionsToIgnoreOnce.has(currentWatchQueryOptions) ||
142
- !equal(watchQueryOptions, currentWatchQueryOptions)) {
144
+ if (!equal(watchQueryOptions, currentWatchQueryOptions)) {
143
145
  this.watchQueryOptions = watchQueryOptions;
144
146
  if (currentWatchQueryOptions && this.observable) {
145
- this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);
146
147
  this.observable.reobserve(this.getObsQueryOptions());
147
148
  this.previousData = ((_a = this.result) === null || _a === void 0 ? void 0 : _a.data) || this.previousData;
148
149
  this.result = void 0;
@@ -1 +1 @@
1
- {"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EACL,WAAW,EACX,UAAU,EACV,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,YAAY,EAA6C,MAAM,YAAY,C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,EAAE,CAAC,CAAC;SACvE;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;IAEO,kDAA0B,GAAlC,UAAmC,MAAgC;QAMjE,IACE,MAAM,CAAC,OAAO;YACd,IAAI,CAAC,gBAAgB,CAAC,cAAc;YACpC,CAAC,MAAM,CAAC,OAAO;YACf,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;YACvD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,WAAW,KAAK,YAAY,EACpD;YACA,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;gBACpB,OAAO,EAAE,IAAI;gBACb,aAAa,EAAE,aAAa,CAAC,OAAO;aACrC,CAAC,CAAC;YACH,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;SAC3B;IACH,CAAC;IACH,oBAAC;AAAD,CAAC,AA5gBD,IA4gBC","sourcesContent":["import { invariant } from '../../utilities/globals';\n\nimport {\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { useSyncExternalStore } from './useSyncExternalStore';\nimport { equal } from '@wry/equality';\n\nimport { mergeOptions, OperationVariables, WatchQueryFetchPolicy } from '../../core';\nimport { ApolloContextValue, getApolloContext } from '../context';\nimport { ApolloError } from '../../errors';\nimport {\n ApolloClient,\n ApolloQueryResult,\n NetworkStatus,\n ObservableQuery,\n DocumentNode,\n TypedDocumentNode,\n WatchQueryOptions,\n} from '../../core';\nimport {\n QueryHookOptions,\n QueryResult,\n ObservableQueryFields,\n} from '../types/types';\n\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { useApolloClient } from './useApolloClient';\nimport { canUseWeakMap, canUseWeakSet, compact, isNonEmptyArray, maybeDeepFreeze } from '../../utilities';\n\nconst {\n prototype: {\n hasOwnProperty,\n },\n} = Object;\n\nexport function useQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<TData, TVariables> = Object.create(null),\n): QueryResult<TData, TVariables> {\n return useInternalState(\n useApolloClient(options.client),\n query,\n ).useQuery(options);\n}\n\nexport function useInternalState<TData, TVariables extends OperationVariables>(\n client: ApolloClient<any>,\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n): InternalState<TData, TVariables> {\n const stateRef = useRef<InternalState<TData, TVariables>>();\n if (\n !stateRef.current ||\n client !== stateRef.current.client ||\n query !== stateRef.current.query\n ) {\n stateRef.current = new InternalState(client, query, stateRef.current);\n }\n const state = stateRef.current;\n\n // By default, InternalState.prototype.forceUpdate is an empty function, but\n // we replace it here (before anyone has had a chance to see this state yet)\n // with a function that unconditionally forces an update, using the latest\n // setTick function. Updating this state by calling state.forceUpdate is the\n // only way we trigger React component updates (no other useState calls within\n // the InternalState class).\n const [_tick, setTick] = useState(0);\n state.forceUpdate = () => {\n setTick(tick => tick + 1);\n };\n\n return state;\n}\n\nclass InternalState<TData, TVariables extends OperationVariables> {\n constructor(\n public readonly client: ReturnType<typeof useApolloClient>,\n public readonly query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n previous?: InternalState<TData, TVariables>,\n ) {\n verifyDocumentType(query, DocumentType.Query);\n\n // Reuse previousData from previous InternalState (if any) to provide\n // continuity of previousData even if/when the query or client changes.\n const previousResult = previous && previous.result;\n const previousData = previousResult && previousResult.data;\n if (previousData) {\n this.previousData = previousData;\n }\n }\n\n forceUpdate() {\n // Replaced (in useInternalState) with a method that triggers an update.\n invariant.warn(\"Calling default no-op implementation of InternalState#forceUpdate\");\n }\n\n asyncUpdate(signal: AbortSignal) {\n return new Promise<QueryResult<TData, TVariables>>((resolve, reject) => {\n const watchQueryOptions = this.watchQueryOptions;\n\n const handleAborted = () => {\n this.asyncResolveFns.delete(resolve)\n this.optionsToIgnoreOnce.delete(watchQueryOptions);\n signal.removeEventListener('abort', handleAborted)\n reject(signal.reason);\n };\n\n this.asyncResolveFns.add(resolve);\n this.optionsToIgnoreOnce.add(watchQueryOptions);\n signal.addEventListener('abort', handleAborted)\n this.forceUpdate();\n });\n }\n\n private asyncResolveFns = new Set<\n (result: QueryResult<TData, TVariables>) => void\n >();\n\n private optionsToIgnoreOnce = new (canUseWeakSet ? WeakSet : Set)<\n WatchQueryOptions<TVariables, TData>\n >();\n\n // Methods beginning with use- should be called according to the standard\n // rules of React hooks: only at the top level of the calling function, and\n // without any dynamic conditional logic.\n useQuery(options: QueryHookOptions<TData, TVariables>) {\n // The renderPromises field gets initialized here in the useQuery method, at\n // the beginning of everything (for a given component rendering, at least),\n // so we can safely use this.renderPromises in other/later InternalState\n // methods without worrying it might be uninitialized. Even after\n // initialization, this.renderPromises is usually undefined (unless SSR is\n // happening), but that's fine as long as it has been initialized that way,\n // rather than left uninitialized.\n this.renderPromises = useContext(getApolloContext()).renderPromises;\n\n this.useOptions(options);\n\n const obsQuery = this.useObservableQuery();\n\n const result = useSyncExternalStore(\n useCallback(() => {\n if (this.renderPromises) {\n return () => {};\n }\n\n const onNext = () => {\n const previousResult = this.result;\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 = 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 this.setResult(result);\n };\n\n const 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 (!hasOwnProperty.call(error, 'graphQLErrors')) {\n // The error is not a GraphQL error\n throw error;\n }\n\n const previousResult = this.result;\n if (\n !previousResult ||\n (previousResult && previousResult.loading) ||\n !equal(error, previousResult.error)\n ) {\n this.setResult({\n data: (previousResult && previousResult.data) as TData,\n error: error as ApolloError,\n loading: false,\n networkStatus: NetworkStatus.error,\n });\n }\n };\n\n let subscription = obsQuery.subscribe(onNext, onError);\n\n return () => subscription.unsubscribe();\n }, [\n // We memoize the subscribe function using useCallback and the following\n // dependency keys, because the subscribe function reference is all that\n // useSyncExternalStore uses internally as a dependency key for the\n // useEffect ultimately responsible for the subscription, so we are\n // effectively passing this dependency array to that useEffect buried\n // inside useSyncExternalStore, as desired.\n obsQuery,\n this.renderPromises,\n this.client.disableNetworkFetches,\n ]),\n\n () => this.getCurrentResult(),\n () => this.getCurrentResult(),\n );\n\n // TODO Remove this method when we remove support for options.partialRefetch.\n this.unsafeHandlePartialRefetch(result);\n\n const queryResult = this.toQueryResult(result);\n\n if (!queryResult.loading && this.asyncResolveFns.size) {\n this.asyncResolveFns.forEach(resolve => resolve(queryResult));\n this.asyncResolveFns.clear();\n }\n\n return queryResult;\n }\n\n // These members (except for renderPromises) are all populated by the\n // useOptions method, which is called unconditionally at the beginning of the\n // useQuery method, so we can safely use these members in other/later methods\n // without worrying they might be uninitialized.\n private renderPromises: ApolloContextValue[\"renderPromises\"];\n private queryHookOptions: QueryHookOptions<TData, TVariables>;\n private watchQueryOptions: WatchQueryOptions<TVariables, TData>;\n\n private useOptions(\n options: QueryHookOptions<TData, TVariables>,\n ) {\n const watchQueryOptions = this.createWatchQueryOptions(\n this.queryHookOptions = options,\n );\n\n // Update this.watchQueryOptions, but only when they have changed, which\n // allows us to depend on the referential stability of\n // this.watchQueryOptions elsewhere.\n const currentWatchQueryOptions = this.watchQueryOptions;\n\n // To force this equality test to \"fail,\" thereby reliably triggering\n // observable.reobserve, add any current WatchQueryOptions object(s) you\n // want to be ignored to this.optionsToIgnoreOnce. A similar effect could be\n // achieved by nullifying this.watchQueryOptions so the equality test\n // immediately fails because currentWatchQueryOptions is null, but this way\n // we can promise a truthy this.watchQueryOptions at all times.\n if (\n this.optionsToIgnoreOnce.has(currentWatchQueryOptions) ||\n !equal(watchQueryOptions, currentWatchQueryOptions)\n ) {\n this.watchQueryOptions = watchQueryOptions;\n\n if (currentWatchQueryOptions && this.observable) {\n // As advertised in the -Once of this.optionsToIgnoreOnce, this trick is\n // only good for one forced execution of observable.reobserve per\n // ignored WatchQueryOptions object, though it is unlikely we will ever\n // see this exact currentWatchQueryOptions object again here, since we\n // just replaced this.watchQueryOptions with watchQueryOptions.\n this.optionsToIgnoreOnce.delete(currentWatchQueryOptions);\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 this.observable.reobserve(this.getObsQueryOptions());\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 this.previousData = this.result?.data || this.previousData;\n this.result = void 0;\n }\n }\n\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 this.onCompleted = options.onCompleted || InternalState.prototype.onCompleted;\n this.onError = options.onError || InternalState.prototype.onError;\n\n if (\n (this.renderPromises || this.client.disableNetworkFetches) &&\n this.queryHookOptions.ssr === false &&\n !this.queryHookOptions.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 this.result = this.ssrDisabledResult;\n } else if (\n this.queryHookOptions.skip ||\n this.watchQueryOptions.fetchPolicy === 'standby'\n ) {\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 this.result = this.skipStandbyResult;\n } else if (\n this.result === this.ssrDisabledResult ||\n this.result === this.skipStandbyResult\n ) {\n this.result = void 0;\n }\n }\n\n private getObsQueryOptions(): WatchQueryOptions<TVariables, TData> {\n const toMerge: Array<\n Partial<WatchQueryOptions<TVariables, TData>>\n > = [];\n\n const globalDefaults = this.client.defaultOptions.watchQuery;\n if (globalDefaults) toMerge.push(globalDefaults);\n\n if (this.queryHookOptions.defaultOptions) {\n toMerge.push(this.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(\n this.observable && this.observable.options,\n this.watchQueryOptions,\n ));\n\n return toMerge.reduce(\n mergeOptions\n ) as WatchQueryOptions<TVariables, TData>;\n }\n\n private ssrDisabledResult = maybeDeepFreeze({\n loading: true,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.loading,\n });\n\n private skipStandbyResult = maybeDeepFreeze({\n loading: false,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.ready,\n });\n\n // A function to massage options before passing them to ObservableQuery.\n private createWatchQueryOptions({\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> = {}): 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: this.query });\n\n if (\n this.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 }\n\n if (!watchQueryOptions.variables) {\n watchQueryOptions.variables = {} as TVariables;\n }\n\n if (skip) {\n const {\n fetchPolicy = this.getDefaultFetchPolicy(),\n initialFetchPolicy = fetchPolicy,\n } = watchQueryOptions;\n\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 Object.assign(watchQueryOptions, {\n initialFetchPolicy,\n fetchPolicy: 'standby',\n });\n } else if (!watchQueryOptions.fetchPolicy) {\n watchQueryOptions.fetchPolicy =\n this.observable?.options.initialFetchPolicy ||\n this.getDefaultFetchPolicy();\n }\n\n return watchQueryOptions;\n }\n\n getDefaultFetchPolicy(): WatchQueryFetchPolicy {\n return (\n this.queryHookOptions.defaultOptions?.fetchPolicy ||\n this.client.defaultOptions.watchQuery?.fetchPolicy ||\n \"cache-first\"\n );\n }\n\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 private onCompleted(data: TData) {}\n private onError(error: ApolloError) {}\n\n private observable: ObservableQuery<TData, TVariables>;\n private obsQueryFields: Omit<\n ObservableQueryFields<TData, TVariables>,\n \"variables\"\n >;\n\n private useObservableQuery() {\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 const obsQuery = this.observable =\n this.renderPromises\n && this.renderPromises.getSSRObservable(this.watchQueryOptions)\n || this.observable // Reuse this.observable if possible (and not SSR)\n || this.client.watchQuery(this.getObsQueryOptions());\n\n this.obsQueryFields = useMemo(() => ({\n refetch: obsQuery.refetch.bind(obsQuery),\n reobserve: obsQuery.reobserve.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 const ssrAllowed = !(\n this.queryHookOptions.ssr === false ||\n this.queryHookOptions.skip\n );\n\n if (this.renderPromises && ssrAllowed) {\n this.renderPromises.registerSSRObservable(obsQuery);\n\n if (obsQuery.getCurrentResult().loading) {\n // TODO: This is a legacy API which could probably be cleaned up\n this.renderPromises.addObservableQueryPromise(obsQuery);\n }\n }\n\n return obsQuery;\n }\n\n // These members are populated by getCurrentResult and setResult, and it's\n // okay/normal for them to be initially undefined.\n private result: undefined | ApolloQueryResult<TData>;\n private previousData: undefined | TData;\n\n private setResult(nextResult: ApolloQueryResult<TData>) {\n const previousResult = this.result;\n if (previousResult && previousResult.data) {\n this.previousData = previousResult.data;\n }\n this.result = nextResult;\n // Calling state.setResult always triggers an update, though some call sites\n // perform additional equality checks before committing to an update.\n this.forceUpdate();\n this.handleErrorOrCompleted(nextResult);\n }\n\n private handleErrorOrCompleted(result: ApolloQueryResult<TData>) {\n if (!result.loading) {\n const error = this.toApolloError(result);\n\n // wait a tick in case we are in the middle of rendering a component\n Promise.resolve().then(() => {\n if (error) {\n this.onError(error);\n } else if (result.data) {\n this.onCompleted(result.data);\n }\n }).catch(error => {\n invariant.warn(error);\n });\n }\n }\n\n private toApolloError(result: ApolloQueryResult<TData>): ApolloError | undefined {\n return isNonEmptyArray(result.errors)\n ? new ApolloError({ graphQLErrors: result.errors })\n : result.error\n }\n\n private getCurrentResult(): ApolloQueryResult<TData> {\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 (!this.result) {\n this.handleErrorOrCompleted(\n this.result = this.observable.getCurrentResult()\n );\n }\n return this.result;\n }\n\n // This cache allows the referential stability of this.result (as returned by\n // getCurrentResult) to translate into referential stability of the resulting\n // QueryResult object returned by toQueryResult.\n private toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)<\n ApolloQueryResult<TData>,\n QueryResult<TData, TVariables>\n >();\n\n toQueryResult(\n result: ApolloQueryResult<TData>,\n ): QueryResult<TData, TVariables> {\n let queryResult = this.toQueryResultCache.get(result);\n if (queryResult) return queryResult;\n\n const { data, partial, ...resultWithoutPartial } = result;\n this.toQueryResultCache.set(result, queryResult = {\n data, // Ensure always defined, even if result.data is missing.\n ...resultWithoutPartial,\n ...this.obsQueryFields,\n client: this.client,\n observable: this.observable,\n variables: this.observable.variables,\n called: !this.queryHookOptions.skip,\n previousData: this.previousData,\n });\n\n if (!queryResult.error && isNonEmptyArray(result.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 queryResult.error = new ApolloError({ graphQLErrors: result.errors });\n }\n\n return queryResult;\n }\n\n private unsafeHandlePartialRefetch(result: ApolloQueryResult<TData>) {\n // WARNING: 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 result.partial &&\n this.queryHookOptions.partialRefetch &&\n !result.loading &&\n (!result.data || Object.keys(result.data).length === 0) &&\n this.observable.options.fetchPolicy !== 'cache-only'\n ) {\n Object.assign(result, {\n loading: true,\n networkStatus: NetworkStatus.refetch,\n });\n this.observable.refetch();\n }\n }\n}\n"]}
1
+ {"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,SAAS,EAAE,MAAM,yBAAyB,CAAC;AAEpD,OAAO,EACL,WAAW,EACX,UAAU,EACV,OAAO,EACP,MAAM,EACN,QAAQ,GACT,MAAM,OAAO,CAAC;AACf,OAAO,EAAE,oBAAoB,EAAE,MAAM,wBAAwB,CAAC;AAC9D,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,YAAY,EAA6C,MAAM,YAAY,CAAC;AACrF,OAAO,EAAsB,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAClE,OAAO,EAAE,WAAW,EAAE,MAAM,cAAc,CAAC;AAC3C,OAAO,EAGL,aAAa,GAKd,MAAM,YAAY,CAAC;AAOpB,OAAO,EAAE,YAAY,EAAE,kBAAkB,EAAE,MAAM,WAAW,CAAC;AAC7D,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AACpD,OAAO,EAAE,aAAa,EAAE,OAAO,EAAE,eAAe,EAAE,eAAe,EAAE,MAAM,iBAAiB,CAAC;AAIvF,IAAA,cAAc,GAEd,MAAM,yBAFQ,CAEP;AAEX,MAAM,UAAU,QAAQ,CAItB,KAA0D,EAC1D,OAAkE;IAAlE,wBAAA,EAAA,UAA+C,MAAM,CAAC,MAAM,CAAC,IAAI,CAAC;IAElE,OAAO,gBAAgB,CACrB,eAAe,CAAC,OAAO,CAAC,MAAM,CAAC,EAC/B,KAAK,CACN,CAAC,QAAQ,CAAC,OAAO,CAAC,CAAC;AACtB,CAAC;AAED,MAAM,UAAU,gBAAgB,CAC9B,MAAyB,EACzB,KAA0D;IAE1D,IAAM,QAAQ,GAAG,MAAM,EAAoC,CAAC;IAC5D,IACE,CAAC,QAAQ,CAAC,OAAO;QACjB,MAAM,KAAK,QAAQ,CAAC,OAAO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EACnC,YAAY,EAAE,IAAI,CAAC,YAAY,GAChC,CAAC,CAAC;QAEH,IAAI,CAAC,WAAW,CAAC,KAAK,IAAI,eAAe,CAAC,MAAM,CAAC,MAAM,CAAC,EAAE;YAKxD,WAAW,CAAC,KAAK,GAAG,IAAI,WAAW,CAAC,EAAE,aAAa,EAAE,MAAM,CAAC,MAAM,EAAE,CAAC,CAAC;SACvE;QAED,OAAO,WAAW,CAAC;IACrB,CAAC;IAEO,kDAA0B,GAAlC,UAAmC,MAAgC;QAMjE,IACE,MAAM,CAAC,OAAO;YACd,IAAI,CAAC,gBAAgB,CAAC,cAAc;YACpC,CAAC,MAAM,CAAC,OAAO;YACf,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,MAAM,CAAC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,CAAC;YACvD,IAAI,CAAC,UAAU,CAAC,OAAO,CAAC,WAAW,KAAK,YAAY,EACpD;YACA,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE;gBACpB,OAAO,EAAE,IAAI;gBACb,aAAa,EAAE,aAAa,CAAC,OAAO;aACrC,CAAC,CAAC;YACH,IAAI,CAAC,UAAU,CAAC,OAAO,EAAE,CAAC;SAC3B;IACH,CAAC;IACH,oBAAC;AAAD,CAAC,AAxgBD,IAwgBC","sourcesContent":["import { invariant } from '../../utilities/globals';\n\nimport {\n useCallback,\n useContext,\n useMemo,\n useRef,\n useState,\n} from 'react';\nimport { useSyncExternalStore } from './useSyncExternalStore';\nimport { equal } from '@wry/equality';\n\nimport { mergeOptions, OperationVariables, WatchQueryFetchPolicy } from '../../core';\nimport { ApolloContextValue, getApolloContext } from '../context';\nimport { ApolloError } from '../../errors';\nimport {\n ApolloClient,\n ApolloQueryResult,\n NetworkStatus,\n ObservableQuery,\n DocumentNode,\n TypedDocumentNode,\n WatchQueryOptions,\n} from '../../core';\nimport {\n QueryHookOptions,\n QueryResult,\n ObservableQueryFields,\n} from '../types/types';\n\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { useApolloClient } from './useApolloClient';\nimport { canUseWeakMap, compact, isNonEmptyArray, maybeDeepFreeze } from '../../utilities';\n\nconst {\n prototype: {\n hasOwnProperty,\n },\n} = Object;\n\nexport function useQuery<\n TData = any,\n TVariables extends OperationVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<TData, TVariables> = Object.create(null),\n): QueryResult<TData, TVariables> {\n return useInternalState(\n useApolloClient(options.client),\n query,\n ).useQuery(options);\n}\n\nexport function useInternalState<TData, TVariables extends OperationVariables>(\n client: ApolloClient<any>,\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n): InternalState<TData, TVariables> {\n const stateRef = useRef<InternalState<TData, TVariables>>();\n if (\n !stateRef.current ||\n client !== stateRef.current.client ||\n query !== stateRef.current.query\n ) {\n stateRef.current = new InternalState(client, query, stateRef.current);\n }\n const state = stateRef.current;\n\n // By default, InternalState.prototype.forceUpdate is an empty function, but\n // we replace it here (before anyone has had a chance to see this state yet)\n // with a function that unconditionally forces an update, using the latest\n // setTick function. Updating this state by calling state.forceUpdate is the\n // only way we trigger React component updates (no other useState calls within\n // the InternalState class).\n const [_tick, setTick] = useState(0);\n state.forceUpdate = () => {\n setTick(tick => tick + 1);\n };\n\n return state;\n}\n\nclass InternalState<TData, TVariables extends OperationVariables> {\n constructor(\n public readonly client: ReturnType<typeof useApolloClient>,\n public readonly query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n previous?: InternalState<TData, TVariables>,\n ) {\n verifyDocumentType(query, DocumentType.Query);\n\n // Reuse previousData from previous InternalState (if any) to provide\n // continuity of previousData even if/when the query or client changes.\n const previousResult = previous && previous.result;\n const previousData = previousResult && previousResult.data;\n if (previousData) {\n this.previousData = previousData;\n }\n }\n\n forceUpdate() {\n // Replaced (in useInternalState) with a method that triggers an update.\n invariant.warn(\"Calling default no-op implementation of InternalState#forceUpdate\");\n }\n\n executeQuery(options: QueryHookOptions<TData, TVariables>) {\n if (options.query) {\n Object.assign(this, { query: options.query })\n }\n\n this.watchQueryOptions = this.createWatchQueryOptions(\n this.queryHookOptions = options,\n );\n\n const concast = this.observable.reobserveAsConcast(\n this.getObsQueryOptions()\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 this.previousData = this.result?.data || this.previousData;\n this.result = void 0;\n this.forceUpdate();\n\n return new Promise<QueryResult<TData, TVariables>>((resolve) => {\n let result: ApolloQueryResult<TData>;\n\n // Subscribe to the concast independently of the ObservableQuery in case \n // the component gets unmounted before the promise resolves. This prevents\n // the concast from terminating early and resolving with `undefined` when\n // there are no more subscribers for the concast.\n concast.subscribe({\n next: (value) => {\n result = value;\n },\n error: () => {\n resolve(this.toQueryResult(this.observable.getCurrentResult()));\n },\n complete: () => {\n resolve(this.toQueryResult(result));\n }\n });\n });\n }\n\n // Methods beginning with use- should be called according to the standard\n // rules of React hooks: only at the top level of the calling function, and\n // without any dynamic conditional logic.\n useQuery(options: QueryHookOptions<TData, TVariables>) {\n // The renderPromises field gets initialized here in the useQuery method, at\n // the beginning of everything (for a given component rendering, at least),\n // so we can safely use this.renderPromises in other/later InternalState\n // methods without worrying it might be uninitialized. Even after\n // initialization, this.renderPromises is usually undefined (unless SSR is\n // happening), but that's fine as long as it has been initialized that way,\n // rather than left uninitialized.\n this.renderPromises = useContext(getApolloContext()).renderPromises;\n\n this.useOptions(options);\n\n const obsQuery = this.useObservableQuery();\n\n const result = useSyncExternalStore(\n useCallback(() => {\n if (this.renderPromises) {\n return () => {};\n }\n\n const onNext = () => {\n const previousResult = this.result;\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 = 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 this.setResult(result);\n };\n\n const 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 (!hasOwnProperty.call(error, 'graphQLErrors')) {\n // The error is not a GraphQL error\n throw error;\n }\n\n const previousResult = this.result;\n if (\n !previousResult ||\n (previousResult && previousResult.loading) ||\n !equal(error, previousResult.error)\n ) {\n this.setResult({\n data: (previousResult && previousResult.data) as TData,\n error: error as ApolloError,\n loading: false,\n networkStatus: NetworkStatus.error,\n });\n }\n };\n\n let subscription = obsQuery.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 () => setTimeout(() => subscription.unsubscribe());\n }, [\n // We memoize the subscribe function using useCallback and the following\n // dependency keys, because the subscribe function reference is all that\n // useSyncExternalStore uses internally as a dependency key for the\n // useEffect ultimately responsible for the subscription, so we are\n // effectively passing this dependency array to that useEffect buried\n // inside useSyncExternalStore, as desired.\n obsQuery,\n this.renderPromises,\n this.client.disableNetworkFetches,\n ]),\n\n () => this.getCurrentResult(),\n () => this.getCurrentResult(),\n );\n\n // TODO Remove this method when we remove support for options.partialRefetch.\n this.unsafeHandlePartialRefetch(result);\n\n return this.toQueryResult(result);\n }\n\n // These members (except for renderPromises) are all populated by the\n // useOptions method, which is called unconditionally at the beginning of the\n // useQuery method, so we can safely use these members in other/later methods\n // without worrying they might be uninitialized.\n private renderPromises: ApolloContextValue[\"renderPromises\"];\n private queryHookOptions: QueryHookOptions<TData, TVariables>;\n private watchQueryOptions: WatchQueryOptions<TVariables, TData>;\n\n private useOptions(\n options: QueryHookOptions<TData, TVariables>,\n ) {\n const watchQueryOptions = this.createWatchQueryOptions(\n this.queryHookOptions = options,\n );\n\n // Update this.watchQueryOptions, but only when they have changed, which\n // allows us to depend on the referential stability of\n // this.watchQueryOptions elsewhere.\n const currentWatchQueryOptions = this.watchQueryOptions;\n\n if (!equal(watchQueryOptions, currentWatchQueryOptions)) {\n this.watchQueryOptions = watchQueryOptions;\n\n if (currentWatchQueryOptions && this.observable) {\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 this.observable.reobserve(this.getObsQueryOptions());\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 this.previousData = this.result?.data || this.previousData;\n this.result = void 0;\n }\n }\n\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 this.onCompleted = options.onCompleted || InternalState.prototype.onCompleted;\n this.onError = options.onError || InternalState.prototype.onError;\n\n if (\n (this.renderPromises || this.client.disableNetworkFetches) &&\n this.queryHookOptions.ssr === false &&\n !this.queryHookOptions.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 this.result = this.ssrDisabledResult;\n } else if (\n this.queryHookOptions.skip ||\n this.watchQueryOptions.fetchPolicy === 'standby'\n ) {\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 this.result = this.skipStandbyResult;\n } else if (\n this.result === this.ssrDisabledResult ||\n this.result === this.skipStandbyResult\n ) {\n this.result = void 0;\n }\n }\n\n private getObsQueryOptions(): WatchQueryOptions<TVariables, TData> {\n const toMerge: Array<\n Partial<WatchQueryOptions<TVariables, TData>>\n > = [];\n\n const globalDefaults = this.client.defaultOptions.watchQuery;\n if (globalDefaults) toMerge.push(globalDefaults);\n\n if (this.queryHookOptions.defaultOptions) {\n toMerge.push(this.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(\n this.observable && this.observable.options,\n this.watchQueryOptions,\n ));\n\n return toMerge.reduce(\n mergeOptions\n ) as WatchQueryOptions<TVariables, TData>;\n }\n\n private ssrDisabledResult = maybeDeepFreeze({\n loading: true,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.loading,\n });\n\n private skipStandbyResult = maybeDeepFreeze({\n loading: false,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.ready,\n });\n\n // A function to massage options before passing them to ObservableQuery.\n private createWatchQueryOptions({\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> = {}): 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: this.query });\n\n if (\n this.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 }\n\n if (!watchQueryOptions.variables) {\n watchQueryOptions.variables = {} as TVariables;\n }\n\n if (skip) {\n const {\n fetchPolicy = this.getDefaultFetchPolicy(),\n initialFetchPolicy = fetchPolicy,\n } = watchQueryOptions;\n\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 Object.assign(watchQueryOptions, {\n initialFetchPolicy,\n fetchPolicy: 'standby',\n });\n } else if (!watchQueryOptions.fetchPolicy) {\n watchQueryOptions.fetchPolicy =\n this.observable?.options.initialFetchPolicy ||\n this.getDefaultFetchPolicy();\n }\n\n return watchQueryOptions;\n }\n\n getDefaultFetchPolicy(): WatchQueryFetchPolicy {\n return (\n this.queryHookOptions.defaultOptions?.fetchPolicy ||\n this.client.defaultOptions.watchQuery?.fetchPolicy ||\n \"cache-first\"\n );\n }\n\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 private onCompleted(data: TData) {}\n private onError(error: ApolloError) {}\n\n private observable: ObservableQuery<TData, TVariables>;\n private obsQueryFields: Omit<\n ObservableQueryFields<TData, TVariables>,\n \"variables\"\n >;\n\n private useObservableQuery() {\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 const obsQuery = this.observable =\n this.renderPromises\n && this.renderPromises.getSSRObservable(this.watchQueryOptions)\n || this.observable // Reuse this.observable if possible (and not SSR)\n || this.client.watchQuery(this.getObsQueryOptions());\n\n this.obsQueryFields = useMemo(() => ({\n refetch: obsQuery.refetch.bind(obsQuery),\n reobserve: obsQuery.reobserve.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 const ssrAllowed = !(\n this.queryHookOptions.ssr === false ||\n this.queryHookOptions.skip\n );\n\n if (this.renderPromises && ssrAllowed) {\n this.renderPromises.registerSSRObservable(obsQuery);\n\n if (obsQuery.getCurrentResult().loading) {\n // TODO: This is a legacy API which could probably be cleaned up\n this.renderPromises.addObservableQueryPromise(obsQuery);\n }\n }\n\n return obsQuery;\n }\n\n // These members are populated by getCurrentResult and setResult, and it's\n // okay/normal for them to be initially undefined.\n private result: undefined | ApolloQueryResult<TData>;\n private previousData: undefined | TData;\n\n private setResult(nextResult: ApolloQueryResult<TData>) {\n const previousResult = this.result;\n if (previousResult && previousResult.data) {\n this.previousData = previousResult.data;\n }\n this.result = nextResult;\n // Calling state.setResult always triggers an update, though some call sites\n // perform additional equality checks before committing to an update.\n this.forceUpdate();\n this.handleErrorOrCompleted(nextResult);\n }\n\n private handleErrorOrCompleted(result: ApolloQueryResult<TData>) {\n if (!result.loading) {\n const error = this.toApolloError(result);\n\n // wait a tick in case we are in the middle of rendering a component\n Promise.resolve().then(() => {\n if (error) {\n this.onError(error);\n } else if (result.data) {\n this.onCompleted(result.data);\n }\n }).catch(error => {\n invariant.warn(error);\n });\n }\n }\n\n private toApolloError(result: ApolloQueryResult<TData>): ApolloError | undefined {\n return isNonEmptyArray(result.errors)\n ? new ApolloError({ graphQLErrors: result.errors })\n : result.error\n }\n\n private getCurrentResult(): ApolloQueryResult<TData> {\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 (!this.result) {\n this.handleErrorOrCompleted(\n this.result = this.observable.getCurrentResult()\n );\n }\n return this.result;\n }\n\n // This cache allows the referential stability of this.result (as returned by\n // getCurrentResult) to translate into referential stability of the resulting\n // QueryResult object returned by toQueryResult.\n private toQueryResultCache = new (canUseWeakMap ? WeakMap : Map)<\n ApolloQueryResult<TData>,\n QueryResult<TData, TVariables>\n >();\n\n toQueryResult(\n result: ApolloQueryResult<TData>,\n ): QueryResult<TData, TVariables> {\n let queryResult = this.toQueryResultCache.get(result);\n if (queryResult) return queryResult;\n\n const { data, partial, ...resultWithoutPartial } = result;\n this.toQueryResultCache.set(result, queryResult = {\n data, // Ensure always defined, even if result.data is missing.\n ...resultWithoutPartial,\n ...this.obsQueryFields,\n client: this.client,\n observable: this.observable,\n variables: this.observable.variables,\n called: !this.queryHookOptions.skip,\n previousData: this.previousData,\n });\n\n if (!queryResult.error && isNonEmptyArray(result.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 queryResult.error = new ApolloError({ graphQLErrors: result.errors });\n }\n\n return queryResult;\n }\n\n private unsafeHandlePartialRefetch(result: ApolloQueryResult<TData>) {\n // WARNING: 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 result.partial &&\n this.queryHookOptions.partialRefetch &&\n !result.loading &&\n (!result.data || Object.keys(result.data).length === 0) &&\n this.observable.options.fetchPolicy !== 'cache-only'\n ) {\n Object.assign(result, {\n loading: true,\n networkStatus: NetworkStatus.refetch,\n });\n this.observable.refetch();\n }\n }\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"itAsync.js","sourceRoot":"","sources":["../../../src/testing/core/itAsync.ts"],"names":[],"mappings":"AAAA,SAAS,IAAI,CAAU,GAA8B;IACnD,OAAO,UACL,OAAe,EACf,QAGQ,EACR,OAAgB,IACb,OAAA,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE;QAAA,iBAIlC;QAHC,OAAO,IAAI,OAAO,CAChB,UAAC,OAAO,EAAE,MAAM,IAAK,OAAA,QAAQ,CAAC,IAAI,CAAC,KAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAApC,CAAoC,CAC1D,CAAC;IACJ,CAAC,EAAE,OAAO,CAAC,EAJN,CAIM,CAAC;AACd,CAAC;AAED,IAAM,SAAS,GAAG,IAAI,EAAE,CAAC;AAEzB,MAAM,CAAC,IAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;IACnC,cAAqC;SAArC,UAAqC,EAArC,qBAAqC,EAArC,IAAqC;QAArC,yBAAqC;;IAErC,OAAO,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC,EAAE;IACD,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;IAClB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;IAClB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;CACnB,CAAC,CAAC","sourcesContent":["function wrap<TResult>(key?: \"only\" | \"skip\" | \"todo\") {\n return (\n message: string,\n callback: (\n resolve: (result?: any) => void,\n reject: (reason?: any) => void,\n ) => any,\n timeout?: number,\n ) => (key ? it[key] : it)(message, function () {\n return new Promise(\n (resolve, reject) => callback.call(this, resolve, reject),\n );\n }, timeout);\n}\n\nconst wrappedIt = wrap();\n\nexport const itAsync = Object.assign(function (\n ...args: Parameters<typeof wrappedIt>\n) {\n return wrappedIt.apply(this, args);\n}, {\n only: wrap(\"only\"),\n skip: wrap(\"skip\"),\n todo: wrap(\"todo\"),\n});\n"]}
1
+ {"version":3,"file":"itAsync.js","sourceRoot":"","sources":["../../../src/testing/core/itAsync.ts"],"names":[],"mappings":"AAAA,SAAS,IAAI,CAAC,GAA8B;IAC1C,OAAO,UACL,OAAe,EACf,QAGQ,EACR,OAAgB,IACb,OAAA,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,OAAO,EAAE;QAAA,iBAIlC;QAHC,OAAO,IAAI,OAAO,CAChB,UAAC,OAAO,EAAE,MAAM,IAAK,OAAA,QAAQ,CAAC,IAAI,CAAC,KAAI,EAAE,OAAO,EAAE,MAAM,CAAC,EAApC,CAAoC,CAC1D,CAAC;IACJ,CAAC,EAAE,OAAO,CAAC,EAJN,CAIM,CAAC;AACd,CAAC;AAED,IAAM,SAAS,GAAG,IAAI,EAAE,CAAC;AAEzB,MAAM,CAAC,IAAM,OAAO,GAAG,MAAM,CAAC,MAAM,CAAC;IACnC,cAAqC;SAArC,UAAqC,EAArC,qBAAqC,EAArC,IAAqC;QAArC,yBAAqC;;IAErC,OAAO,SAAS,CAAC,KAAK,CAAC,IAAI,EAAE,IAAI,CAAC,CAAC;AACrC,CAAC,EAAE;IACD,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;IAClB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;IAClB,IAAI,EAAE,IAAI,CAAC,MAAM,CAAC;CACnB,CAAC,CAAC","sourcesContent":["function wrap(key?: \"only\" | \"skip\" | \"todo\") {\n return (\n message: string,\n callback: (\n resolve: (result?: any) => void,\n reject: (reason?: any) => void,\n ) => any,\n timeout?: number,\n ) => (key ? it[key] : it)(message, function () {\n return new Promise(\n (resolve, reject) => callback.call(this, resolve, reject),\n );\n }, timeout);\n}\n\nconst wrappedIt = wrap();\n\nexport const itAsync = Object.assign(function (\n ...args: Parameters<typeof wrappedIt>\n) {\n return wrappedIt.apply(this, args);\n}, {\n only: wrap(\"only\"),\n skip: wrap(\"skip\"),\n todo: wrap(\"todo\"),\n});\n"]}
@@ -14,7 +14,7 @@ export declare class MockSubscriptionLink extends ApolloLink {
14
14
  operation: Operation;
15
15
  private observers;
16
16
  constructor();
17
- request(operation: Operation): Observable<FetchResult<Record<string, any>, Record<string, any>, Record<string, any>>>;
17
+ request(operation: Operation): Observable<FetchResult>;
18
18
  simulateResult(result: MockedSubscriptionResult, complete?: boolean): void;
19
19
  simulateComplete(): void;
20
20
  onSetup(listener: any): void;
@@ -4,11 +4,12 @@ import { ApolloClient } from "../../core/index.js";
4
4
  import { InMemoryCache as Cache } from "../../cache/index.js";
5
5
  import { ApolloProvider } from "../../react/context/index.js";
6
6
  import { MockLink } from "../core/index.js";
7
- var MockedProvider = (function (_super) {
7
+ export var MockedProvider = (function (_super) {
8
8
  __extends(MockedProvider, _super);
9
9
  function MockedProvider(props) {
10
+ var _a;
10
11
  var _this = _super.call(this, props) || this;
11
- var _a = _this.props, mocks = _a.mocks, addTypename = _a.addTypename, defaultOptions = _a.defaultOptions, cache = _a.cache, resolvers = _a.resolvers, link = _a.link, showWarnings = _a.showWarnings;
12
+ var mocks = (_a = _this.props, _a.mocks), addTypename = _a.addTypename, defaultOptions = _a.defaultOptions, cache = _a.cache, resolvers = _a.resolvers, link = _a.link, showWarnings = _a.showWarnings;
12
13
  var client = new ApolloClient({
13
14
  cache: cache || new Cache({ addTypename: addTypename }),
14
15
  defaultOptions: defaultOptions,
@@ -19,7 +20,8 @@ var MockedProvider = (function (_super) {
19
20
  return _this;
20
21
  }
21
22
  MockedProvider.prototype.render = function () {
22
- var _a = this.props, children = _a.children, childProps = _a.childProps;
23
+ var _a;
24
+ var children = (_a = this.props, _a.children), childProps = _a.childProps;
23
25
  return React.isValidElement(children) ? (React.createElement(ApolloProvider, { client: this.state.client }, React.cloneElement(React.Children.only(children), __assign({}, childProps)))) : null;
24
26
  };
25
27
  MockedProvider.prototype.componentWillUnmount = function () {
@@ -30,5 +32,4 @@ var MockedProvider = (function (_super) {
30
32
  };
31
33
  return MockedProvider;
32
34
  }(React.Component));
33
- export { MockedProvider };
34
35
  //# sourceMappingURL=MockedProvider.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"MockedProvider.js","sourceRoot":"","sources":["../../../src/testing/react/MockedProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAkB,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,aAAa,IAAI,KAAK,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAkB,MAAM,SAAS,CAAC;AAqBnD;IAAoC,kCAGnC;IAKC,wBAAY,KAA0B;QAAtC,YACE,kBAAM,KAAK,CAAC,SAuBb;QArBO,IAAA,KAQF,KAAI,CAAC,KAAK,EAPZ,KAAK,WAAA,EACL,WAAW,iBAAA,EACX,cAAc,oBAAA,EACd,KAAK,WAAA,EACL,SAAS,eAAA,EACT,IAAI,UAAA,EACJ,YAAY,kBACA,CAAC;QACf,IAAM,MAAM,GAAG,IAAI,YAAY,CAAC;YAC9B,KAAK,EAAE,KAAK,IAAI,IAAI,KAAK,CAAC,EAAE,WAAW,aAAA,EAAE,CAAC;YAC1C,cAAc,gBAAA;YACd,IAAI,EAAE,IAAI,IAAI,IAAI,QAAQ,CACxB,KAAK,IAAI,EAAE,EACX,WAAW,EACX,EAAE,YAAY,cAAA,EAAE,CACjB;YACD,SAAS,WAAA;SACV,CAAC,CAAC;QAEH,KAAI,CAAC,KAAK,GAAG,EAAE,MAAM,QAAA,EAAE,CAAC;;IAC1B,CAAC;IAEM,+BAAM,GAAb;QACQ,IAAA,KAA2B,IAAI,CAAC,KAAK,EAAnC,QAAQ,cAAA,EAAE,UAAU,gBAAe,CAAC;QAC5C,OAAO,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CACtC,oBAAC,cAAc,IAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,IACtC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAO,UAAU,EAAG,CACtD,CAClB,CAAC,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;IAEM,6CAAoB,GAA3B;QAGE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;IA3Ca,2BAAY,GAAwB;QAChD,WAAW,EAAE,IAAI;KAClB,CAAC;IA0CJ,qBAAC;CAAA,AAhDD,CAAoC,KAAK,CAAC,SAAS,GAgDlD;SAhDY,cAAc","sourcesContent":["import * as React from 'react';\n\nimport { ApolloClient, DefaultOptions } from '../../core';\nimport { InMemoryCache as Cache } from '../../cache';\nimport { ApolloProvider } from '../../react/context';\nimport { MockLink, MockedResponse } from '../core';\nimport { ApolloLink } from '../../link/core';\nimport { Resolvers } from '../../core';\nimport { ApolloCache } from '../../cache';\n\nexport interface MockedProviderProps<TSerializedCache = {}> {\n mocks?: ReadonlyArray<MockedResponse>;\n addTypename?: boolean;\n defaultOptions?: DefaultOptions;\n cache?: ApolloCache<TSerializedCache>;\n resolvers?: Resolvers;\n childProps?: object;\n children?: any;\n link?: ApolloLink;\n showWarnings?: boolean;\n}\n\nexport interface MockedProviderState {\n client: ApolloClient<any>;\n}\n\nexport class MockedProvider extends React.Component<\n MockedProviderProps,\n MockedProviderState\n> {\n public static defaultProps: MockedProviderProps = {\n addTypename: true\n };\n\n constructor(props: MockedProviderProps) {\n super(props);\n\n const {\n mocks,\n addTypename,\n defaultOptions,\n cache,\n resolvers,\n link,\n showWarnings,\n } = this.props;\n const client = new ApolloClient({\n cache: cache || new Cache({ addTypename }),\n defaultOptions,\n link: link || new MockLink(\n mocks || [],\n addTypename,\n { showWarnings }\n ),\n resolvers,\n });\n\n this.state = { client };\n }\n\n public render() {\n const { children, childProps } = this.props;\n return React.isValidElement(children) ? (\n <ApolloProvider client={this.state.client}>\n {React.cloneElement(React.Children.only(children), { ...childProps })}\n </ApolloProvider>\n ) : null;\n }\n\n public componentWillUnmount() {\n // Since this.state.client was created in the constructor, it's this\n // MockedProvider's responsibility to terminate it.\n this.state.client.stop();\n }\n}\n"]}
1
+ {"version":3,"file":"MockedProvider.js","sourceRoot":"","sources":["../../../src/testing/react/MockedProvider.tsx"],"names":[],"mappings":";AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,YAAY,EAAkB,MAAM,YAAY,CAAC;AAC1D,OAAO,EAAE,aAAa,IAAI,KAAK,EAAE,MAAM,aAAa,CAAC;AACrD,OAAO,EAAE,cAAc,EAAE,MAAM,qBAAqB,CAAC;AACrD,OAAO,EAAE,QAAQ,EAAkB,MAAM,SAAS,CAAC;AAqBnD;IAAoC,kCAGnC;IAKC,wBAAY,KAA0B;;QAAtC,YACE,kBAAM,KAAK,CAAC,SAuBb;QApBG,IAAA,KAAK,IADD,KAQF,KAAI,CAAC,KAAK,WAPP,EACL,WAAW,iBAAA,EACX,cAAc,oBAAA,EACd,KAAK,WAAA,EACL,SAAS,eAAA,EACT,IAAI,UAAA,EACJ,YAAY,kBAAA,CACC;QACf,IAAM,MAAM,GAAG,IAAI,YAAY,CAAC;YAC9B,KAAK,EAAE,KAAK,IAAI,IAAI,KAAK,CAAC,EAAE,WAAW,aAAA,EAAE,CAAC;YAC1C,cAAc,gBAAA;YACd,IAAI,EAAE,IAAI,IAAI,IAAI,QAAQ,CACxB,KAAK,IAAI,EAAE,EACX,WAAW,EACX,EAAE,YAAY,cAAA,EAAE,CACjB;YACD,SAAS,WAAA;SACV,CAAC,CAAC;QAEH,KAAI,CAAC,KAAK,GAAG,EAAE,MAAM,QAAA,EAAE,CAAC;;IAC1B,CAAC;IAEM,+BAAM,GAAb;;QACU,IAAA,QAAQ,IAAV,KAA2B,IAAI,CAAC,KAAK,cAA3B,EAAE,UAAU,gBAAA,CAAgB;QAC5C,OAAO,KAAK,CAAC,cAAc,CAAC,QAAQ,CAAC,CAAC,CAAC,CAAC,CACtC,oBAAC,cAAc,IAAC,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,IACtC,KAAK,CAAC,YAAY,CAAC,KAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,eAAO,UAAU,EAAG,CACtD,CAClB,CAAC,CAAC,CAAC,IAAI,CAAC;IACX,CAAC;IAEM,6CAAoB,GAA3B;QAGE,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC3B,CAAC;IA3Ca,2BAAY,GAAwB;QAChD,WAAW,EAAE,IAAI;KAClB,CAAC;IA0CJ,qBAAC;CAAA,AAhDD,CAAoC,KAAK,CAAC,SAAS,GAgDlD","sourcesContent":["import * as React from 'react';\n\nimport { ApolloClient, DefaultOptions } from '../../core';\nimport { InMemoryCache as Cache } from '../../cache';\nimport { ApolloProvider } from '../../react/context';\nimport { MockLink, MockedResponse } from '../core';\nimport { ApolloLink } from '../../link/core';\nimport { Resolvers } from '../../core';\nimport { ApolloCache } from '../../cache';\n\nexport interface MockedProviderProps<TSerializedCache = {}> {\n mocks?: ReadonlyArray<MockedResponse>;\n addTypename?: boolean;\n defaultOptions?: DefaultOptions;\n cache?: ApolloCache<TSerializedCache>;\n resolvers?: Resolvers;\n childProps?: object;\n children?: any;\n link?: ApolloLink;\n showWarnings?: boolean;\n}\n\nexport interface MockedProviderState {\n client: ApolloClient<any>;\n}\n\nexport class MockedProvider extends React.Component<\n MockedProviderProps,\n MockedProviderState\n> {\n public static defaultProps: MockedProviderProps = {\n addTypename: true\n };\n\n constructor(props: MockedProviderProps) {\n super(props);\n\n const {\n mocks,\n addTypename,\n defaultOptions,\n cache,\n resolvers,\n link,\n showWarnings,\n } = this.props;\n const client = new ApolloClient({\n cache: cache || new Cache({ addTypename }),\n defaultOptions,\n link: link || new MockLink(\n mocks || [],\n addTypename,\n { showWarnings }\n ),\n resolvers,\n });\n\n this.state = { client };\n }\n\n public render() {\n const { children, childProps } = this.props;\n return React.isValidElement(children) ? (\n <ApolloProvider client={this.state.client}>\n {React.cloneElement(React.Children.only(children), { ...childProps })}\n </ApolloProvider>\n ) : null;\n }\n\n public componentWillUnmount() {\n // Since this.state.client was created in the constructor, it's this\n // MockedProvider's responsibility to terminate it.\n this.state.client.stop();\n }\n}\n"]}
@@ -27,8 +27,9 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
27
27
  var MockedProvider = (function (_super) {
28
28
  tslib.__extends(MockedProvider, _super);
29
29
  function MockedProvider(props) {
30
+ var _a;
30
31
  var _this = _super.call(this, props) || this;
31
- var _a = _this.props, mocks = _a.mocks, addTypename = _a.addTypename, defaultOptions = _a.defaultOptions, cache$1 = _a.cache, resolvers = _a.resolvers, link = _a.link, showWarnings = _a.showWarnings;
32
+ var mocks = (_a = _this.props, _a.mocks), addTypename = _a.addTypename, defaultOptions = _a.defaultOptions, cache$1 = _a.cache, resolvers = _a.resolvers, link = _a.link, showWarnings = _a.showWarnings;
32
33
  var client = new core$1.ApolloClient({
33
34
  cache: cache$1 || new cache.InMemoryCache({ addTypename: addTypename }),
34
35
  defaultOptions: defaultOptions,
@@ -39,7 +40,8 @@ var MockedProvider = (function (_super) {
39
40
  return _this;
40
41
  }
41
42
  MockedProvider.prototype.render = function () {
42
- var _a = this.props, children = _a.children, childProps = _a.childProps;
43
+ var _a;
44
+ var children = (_a = this.props, _a.children), childProps = _a.childProps;
43
45
  return React__namespace.isValidElement(children) ? (React__namespace.createElement(context.ApolloProvider, { client: this.state.client }, React__namespace.cloneElement(React__namespace.Children.only(children), tslib.__assign({}, childProps)))) : null;
44
46
  };
45
47
  MockedProvider.prototype.componentWillUnmount = function () {
@@ -1 +1 @@
1
- {"version":3,"file":"testing.cjs","sources":["react/MockedProvider.js"],"sourcesContent":["import { __assign, __extends } from \"tslib\";\nimport * as React from 'react';\nimport { ApolloClient } from '../../core';\nimport { InMemoryCache as Cache } from '../../cache';\nimport { ApolloProvider } from '../../react/context';\nimport { MockLink } from '../core';\nvar MockedProvider = (function (_super) {\n __extends(MockedProvider, _super);\n function MockedProvider(props) {\n var _this = _super.call(this, props) || this;\n var _a = _this.props, mocks = _a.mocks, addTypename = _a.addTypename, defaultOptions = _a.defaultOptions, cache = _a.cache, resolvers = _a.resolvers, link = _a.link, showWarnings = _a.showWarnings;\n var client = new ApolloClient({\n cache: cache || new Cache({ addTypename: addTypename }),\n defaultOptions: defaultOptions,\n link: link || new MockLink(mocks || [], addTypename, { showWarnings: showWarnings }),\n resolvers: resolvers,\n });\n _this.state = { client: client };\n return _this;\n }\n MockedProvider.prototype.render = function () {\n var _a = this.props, children = _a.children, childProps = _a.childProps;\n return React.isValidElement(children) ? (React.createElement(ApolloProvider, { client: this.state.client }, React.cloneElement(React.Children.only(children), __assign({}, childProps)))) : null;\n };\n MockedProvider.prototype.componentWillUnmount = function () {\n this.state.client.stop();\n };\n MockedProvider.defaultProps = {\n addTypename: true\n };\n return MockedProvider;\n}(React.Component));\nexport { MockedProvider };\n//# sourceMappingURL=MockedProvider.js.map"],"names":["__extends","cache","ApolloClient","Cache","MockLink","React","ApolloProvider","__assign"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAMG,IAAC,cAAc,IAAI,UAAU,MAAM,EAAE;AACxC,IAAIA,eAAS,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AACtC,IAAI,SAAS,cAAc,CAAC,KAAK,EAAE;AACnC,QAAQ,IAAI,KAAK,GAAG,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,KAAK,CAAC,IAAI,IAAI,CAAC;AACrD,QAAQ,IAAI,EAAE,GAAG,KAAK,CAAC,KAAK,EAAE,KAAK,GAAG,EAAE,CAAC,KAAK,EAAE,WAAW,GAAG,EAAE,CAAC,WAAW,EAAE,cAAc,GAAG,EAAE,CAAC,cAAc,EAAEC,OAAK,GAAG,EAAE,CAAC,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AC;AACjC,KAAK,CAAC;AACN,IAAI,cAAc,CAAC,YAAY,GAAG;AAClC,QAAQ,WAAW,EAAE,IAAI;AACzB,KAAK,CAAC;AACN,IAAI,OAAO,cAAc,CAAC;AAC1B,CAAC,CAACF,gBAAK,CAAC,SAAS,CAAC;;;;;;;"}
1
+ {"version":3,"file":"testing.cjs","sources":["react/MockedProvider.js"],"sourcesContent":["import { __assign, __extends } from \"tslib\";\nimport * as React from 'react';\nimport { ApolloClient } from '../../core';\nimport { InMemoryCache as Cache } from '../../cache';\nimport { ApolloProvider } from '../../react/context';\nimport { MockLink } from '../core';\nexport var MockedProvider = (function (_super) {\n __extends(MockedProvider, _super);\n function MockedProvider(props) {\n var _a;\n var _this = _super.call(this, props) || this;\n var mocks = (_a = _this.props, _a.mocks), addTypename = _a.addTypename, defaultOptions = _a.defaultOptions, cache = _a.cache, resolvers = _a.resolvers, link = _a.link, showWarnings = _a.showWarnings;\n var client = new ApolloClient({\n cache: cache || new Cache({ addTypename: addTypename }),\n defaultOptions: defaultOptions,\n link: link || new MockLink(mocks || [], addTypename, { showWarnings: showWarnings }),\n resolvers: resolvers,\n });\n _this.state = { client: client };\n return _this;\n }\n MockedProvider.prototype.render = function () {\n var _a;\n var children = (_a = this.props, _a.children), childProps = _a.childProps;\n return React.isValidElement(children) ? (React.createElement(ApolloProvider, { client: this.state.client }, React.cloneElement(React.Children.only(children), __assign({}, childProps)))) : null;\n };\n MockedProvider.prototype.componentWillUnmount = function () {\n this.state.client.stop();\n };\n MockedProvider.defaultProps = {\n addTypename: true\n };\n return MockedProvider;\n}(React.Component));\n//# sourceMappingURL=MockedProvider.js.map"],"names":["__extends","cache","ApolloClient","Cache","MockLink","React","ApolloProvider","__assign"],"mappings":";;;;;;;;;;;;;;;;;;;;;;;;;;AAMU,IAAC,cAAc,IAAI,UAAU,MAAM,EAAE;AAC/C,IAAIA,eAAS,CAAC,cAAc,EAAE,MAAM,CAAC,CAAC;AACtC,IAAI,SAAS,cAAc,CAA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AAa,CAACC,sBAAc,EAAE,EAAE,MAAM,EAAE,IAAI,CAAC,KAAK,CAAC,MAAM,EAAE,EAAED,gBAAK,CAAC,YAAY,CAACA,gBAAK,CAAC,QAAQ,CAAC,IAAI,CAAC,QAAQ,CAAC,EAAEE,cAAQ,CAAC,EAAE,EAAE,UAAU,CAAC,CAAC,CAAC,IAAI,IAAI,CAAC;AACzM,KAAK,CAAC;AACN,IAAI,cAAc,CAAC,SAAS,CAAC,oBAAoB,GAAG,YAAY;AAChE,QAAQ,IAAI,CAAC,KAAK,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;AACjC,KAAK,CAAC;AACN,IAAI,cAAc,CAAC,YAAY,GAAG;AAClC,QAAQ,WAAW,EAAE,IAAI;AACzB,KAAK,CAAC;AACN,IAAI,OAAO,cAAc,CAAC;AAC1B,CAAC,CAACF,gBAAK,CAAC,SAAS,CAAC;;;;;;;"}
@@ -27,8 +27,9 @@ var React__namespace = /*#__PURE__*/_interopNamespace(React);
27
27
  var MockedProvider = (function (_super) {
28
28
  tslib.__extends(MockedProvider, _super);
29
29
  function MockedProvider(props) {
30
+ var _a;
30
31
  var _this = _super.call(this, props) || this;
31
- var _a = _this.props, mocks = _a.mocks, addTypename = _a.addTypename, defaultOptions = _a.defaultOptions, cache$1 = _a.cache, resolvers = _a.resolvers, link = _a.link, showWarnings = _a.showWarnings;
32
+ var mocks = (_a = _this.props, _a.mocks), addTypename = _a.addTypename, defaultOptions = _a.defaultOptions, cache$1 = _a.cache, resolvers = _a.resolvers, link = _a.link, showWarnings = _a.showWarnings;
32
33
  var client = new core$1.ApolloClient({
33
34
  cache: cache$1 || new cache.InMemoryCache({ addTypename: addTypename }),
34
35
  defaultOptions: defaultOptions,
@@ -39,7 +40,8 @@ var MockedProvider = (function (_super) {
39
40
  return _this;
40
41
  }
41
42
  MockedProvider.prototype.render = function () {
42
- var _a = this.props, children = _a.children, childProps = _a.childProps;
43
+ var _a;
44
+ var children = (_a = this.props, _a.children), childProps = _a.childProps;
43
45
  return React__namespace.isValidElement(children) ? (React__namespace.createElement(context.ApolloProvider, { client: this.state.client }, React__namespace.cloneElement(React__namespace.Children.only(children), tslib.__assign({}, childProps)))) : null;
44
46
  };
45
47
  MockedProvider.prototype.componentWillUnmount = function () {
@@ -1,6 +1,7 @@
1
- import { ExecutionPatchIncrementalResult, ExecutionPatchInitialResult, ExecutionPatchResult, FetchResult } from "../../link/core";
1
+ import { ExecutionPatchIncrementalResult, ExecutionPatchInitialResult, ExecutionPatchResult, ApolloPayloadResult, FetchResult } from "../../link/core";
2
2
  export declare function isExecutionPatchIncrementalResult<T>(value: FetchResult<T>): value is ExecutionPatchIncrementalResult;
3
3
  export declare function isExecutionPatchInitialResult<T>(value: FetchResult<T>): value is ExecutionPatchInitialResult<T>;
4
4
  export declare function isExecutionPatchResult<T>(value: FetchResult<T>): value is ExecutionPatchResult<T>;
5
+ export declare function isApolloPayloadResult(value: unknown): value is ApolloPayloadResult;
5
6
  export declare function mergeIncrementalData<TData extends object>(prevResult: TData, result: ExecutionPatchResult<TData>): TData;
6
7
  //# sourceMappingURL=incrementalResult.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"incrementalResult.d.ts","sourceRoot":"","sources":["../../../src/utilities/common/incrementalResult.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,2BAA2B,EAC3B,oBAAoB,EACpB,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAIzB,wBAAgB,iCAAiC,CAAC,CAAC,EACjD,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GACpB,KAAK,IAAI,+BAA+B,CAE1C;AAED,wBAAgB,6BAA6B,CAAC,CAAC,EAC7C,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GACpB,KAAK,IAAI,2BAA2B,CAAC,CAAC,CAAC,CAEzC;AAED,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GACpB,KAAK,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAKlC;AAED,wBAAgB,oBAAoB,CAAC,KAAK,SAAS,MAAM,EACvD,UAAU,EAAE,KAAK,EACjB,MAAM,EAAE,oBAAoB,CAAC,KAAK,CAAC,SAoBpC"}
1
+ {"version":3,"file":"incrementalResult.d.ts","sourceRoot":"","sources":["../../../src/utilities/common/incrementalResult.ts"],"names":[],"mappings":"AAAA,OAAO,EACL,+BAA+B,EAC/B,2BAA2B,EAC3B,oBAAoB,EACpB,mBAAmB,EACnB,WAAW,EACZ,MAAM,iBAAiB,CAAC;AAKzB,wBAAgB,iCAAiC,CAAC,CAAC,EACjD,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GACpB,KAAK,IAAI,+BAA+B,CAE1C;AAED,wBAAgB,6BAA6B,CAAC,CAAC,EAC7C,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GACpB,KAAK,IAAI,2BAA2B,CAAC,CAAC,CAAC,CAEzC;AAED,wBAAgB,sBAAsB,CAAC,CAAC,EACtC,KAAK,EAAE,WAAW,CAAC,CAAC,CAAC,GACpB,KAAK,IAAI,oBAAoB,CAAC,CAAC,CAAC,CAKlC;AAKD,wBAAgB,qBAAqB,CACnC,KAAK,EAAE,OAAO,GACb,KAAK,IAAI,mBAAmB,CAE9B;AAED,wBAAgB,oBAAoB,CAAC,KAAK,SAAS,MAAM,EACvD,UAAU,EAAE,KAAK,EACjB,MAAM,EAAE,oBAAoB,CAAC,KAAK,CAAC,SAoBpC"}
@@ -1,3 +1,4 @@
1
+ import { isNonNullObject } from "./objects.js";
1
2
  import { isNonEmptyArray } from "./arrays.js";
2
3
  import { DeepMerger } from "./mergeDeep.js";
3
4
  export function isExecutionPatchIncrementalResult(value) {
@@ -10,6 +11,9 @@ export function isExecutionPatchResult(value) {
10
11
  return (isExecutionPatchIncrementalResult(value) ||
11
12
  isExecutionPatchInitialResult(value));
12
13
  }
14
+ export function isApolloPayloadResult(value) {
15
+ return isNonNullObject(value) && "payload" in value;
16
+ }
13
17
  export function mergeIncrementalData(prevResult, result) {
14
18
  var mergedData = prevResult;
15
19
  var merger = new DeepMerger();
@@ -1 +1 @@
1
- {"version":3,"file":"incrementalResult.js","sourceRoot":"","sources":["../../../src/utilities/common/incrementalResult.ts"],"names":[],"mappings":"AAMA,OAAO,EAAE,eAAe,EAAE,MAAM,UAAU,CAAC;AAC3C,OAAO,EAAE,UAAU,EAAE,MAAM,aAAa,CAAC;AAEzC,MAAM,UAAU,iCAAiC,CAC/C,KAAqB;IAErB,OAAO,aAAa,IAAI,KAAK,CAAC;AAChC,CAAC;AAED,MAAM,UAAU,6BAA6B,CAC3C,KAAqB;IAErB,OAAO,SAAS,IAAI,KAAK,IAAI,MAAM,IAAI,KAAK,CAAC;AAC/C,CAAC;AAED,MAAM,UAAU,sBAAsB,CACpC,KAAqB;IAErB,OAAO,CACL,iCAAiC,CAAC,KAAK,CAAC;QACxC,6BAA6B,CAAC,KAAK,CAAC,CACrC,CAAC;AACJ,CAAC;AAED,MAAM,UAAU,oBAAoB,CAClC,UAAiB,EACjB,MAAmC;IAEnC,IAAI,UAAU,GAAG,UAAU,CAAC;IAC5B,IAAM,MAAM,GAAG,IAAI,UAAU,EAAE,CAAC;IAChC,IACE,iCAAiC,CAAC,MAAM,CAAC;QACzC,eAAe,CAAC,MAAM,CAAC,WAAW,CAAC,EACnC;QACA,MAAM,CAAC,WAAW,CAAC,OAAO,CAAC,UAAC,EAAc;gBAAZ,IAAI,UAAA,EAAE,IAAI,UAAA;YACtC,KAAK,IAAI,CAAC,GAAG,IAAI,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,EAAE,CAAC,EAAE;gBACzC,IAAM,GAAG,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC;gBACpB,IAAM,YAAY,GAAG,CAAC,KAAK,CAAC,CAAC,GAAG,CAAC,CAAC;gBAClC,IAAM,QAAM,GAAiC,YAAY,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,EAAE,CAAC;gBACpE,QAAM,CAAC,GAAG,CAAC,GAAG,IAAI,CAAC;gBACnB,IAAI,GAAG,QAAqB,CAAC;aAC9B;YACD,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,UAAmB,CAAC;AAC7B,CAAC","sourcesContent":["import {\n ExecutionPatchIncrementalResult,\n ExecutionPatchInitialResult,\n ExecutionPatchResult,\n FetchResult,\n} from \"../../link/core\";\nimport { isNonEmptyArray } from \"./arrays\";\nimport { DeepMerger } from \"./mergeDeep\";\n\nexport function isExecutionPatchIncrementalResult<T>(\n value: FetchResult<T>\n): value is ExecutionPatchIncrementalResult {\n return \"incremental\" in value;\n}\n\nexport function isExecutionPatchInitialResult<T>(\n value: FetchResult<T>\n): value is ExecutionPatchInitialResult<T> {\n return \"hasNext\" in value && \"data\" in value;\n}\n\nexport function isExecutionPatchResult<T>(\n value: FetchResult<T>\n): value is ExecutionPatchResult<T> {\n return (\n isExecutionPatchIncrementalResult(value) ||\n isExecutionPatchInitialResult(value)\n );\n}\n\nexport function mergeIncrementalData<TData extends object>(\n prevResult: TData,\n result: ExecutionPatchResult<TData>\n) {\n let mergedData = prevResult;\n const merger = new DeepMerger();\n if (\n isExecutionPatchIncrementalResult(result) &&\n isNonEmptyArray(result.incremental)\n ) {\n result.incremental.forEach(({ data, path }) => {\n for (let i = path.length - 1; i >= 0; --i) {\n const key = path[i];\n const isNumericKey = !isNaN(+key);\n const parent: Record<string | number, any> = isNumericKey ? [] : {};\n parent[key] = data;\n data = parent as typeof data;\n }\n mergedData = merger.merge(mergedData, data);\n });\n }\n return mergedData as TData;\n}\n"]}
1
+ {"version":3,"file":"incrementalResult.js","sourceRoot":"","sources":["../../../src/utilities/common/incrementalResult.ts"],"names":[],"mappings":"AAOA,OAAO,EAAE,eAAe,EAAE,MAAM,WAAW,CAAC;AAC5C,OAAO,EAAE,eAAe,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,QAAqB,CAAC;aAC9B;YACD,UAAU,GAAG,MAAM,CAAC,KAAK,CAAC,UAAU,EAAE,IAAI,CAAC,CAAC;QAC9C,CAAC,CAAC,CAAC;KACJ;IACD,OAAO,UAAmB,CAAC;AAC7B,CAAC","sourcesContent":["import {\n ExecutionPatchIncrementalResult,\n ExecutionPatchInitialResult,\n ExecutionPatchResult,\n ApolloPayloadResult,\n FetchResult,\n} from \"../../link/core\";\nimport { isNonNullObject } from \"./objects\";\nimport { isNonEmptyArray } from \"./arrays\";\nimport { DeepMerger } from \"./mergeDeep\";\n\nexport function isExecutionPatchIncrementalResult<T>(\n value: FetchResult<T>\n): value is ExecutionPatchIncrementalResult {\n return \"incremental\" in value;\n}\n\nexport function isExecutionPatchInitialResult<T>(\n value: FetchResult<T>\n): value is ExecutionPatchInitialResult<T> {\n return \"hasNext\" in value && \"data\" in value;\n}\n\nexport function isExecutionPatchResult<T>(\n value: FetchResult<T>\n): value is ExecutionPatchResult<T> {\n return (\n isExecutionPatchIncrementalResult(value) ||\n isExecutionPatchInitialResult(value)\n );\n}\n\n// This function detects an Apollo payload result before it is transformed\n// into a FetchResult via HttpLink; it cannot detect an ApolloPayloadResult\n// once it leaves the link chain.\nexport function isApolloPayloadResult(\n value: unknown\n): value is ApolloPayloadResult {\n return isNonNullObject(value) && \"payload\" in value;\n}\n\nexport function mergeIncrementalData<TData extends object>(\n prevResult: TData,\n result: ExecutionPatchResult<TData>\n) {\n let mergedData = prevResult;\n const merger = new DeepMerger();\n if (\n isExecutionPatchIncrementalResult(result) &&\n isNonEmptyArray(result.incremental)\n ) {\n result.incremental.forEach(({ data, path }) => {\n for (let i = path.length - 1; i >= 0; --i) {\n const key = path[i];\n const isNumericKey = !isNaN(+key);\n const parent: Record<string | number, any> = isNumericKey ? [] : {};\n parent[key] = data;\n data = parent as typeof data;\n }\n mergedData = merger.merge(mergedData, data);\n });\n }\n return mergedData as TData;\n}\n"]}