@apollo/client 3.5.10 → 3.6.5

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 (152) hide show
  1. package/LICENSE +1 -1
  2. package/apollo-client.cjs +541 -369
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/cache/cache.cjs +9 -10
  6. package/cache/cache.cjs.map +1 -1
  7. package/cache/cache.cjs.native.js +2288 -0
  8. package/cache/inmemory/readFromStore.d.ts.map +1 -1
  9. package/cache/inmemory/readFromStore.js +10 -11
  10. package/cache/inmemory/readFromStore.js.map +1 -1
  11. package/core/ApolloClient.d.ts +2 -3
  12. package/core/ApolloClient.d.ts.map +1 -1
  13. package/core/ApolloClient.js +4 -8
  14. package/core/ApolloClient.js.map +1 -1
  15. package/core/ObservableQuery.d.ts +10 -4
  16. package/core/ObservableQuery.d.ts.map +1 -1
  17. package/core/ObservableQuery.js +97 -45
  18. package/core/ObservableQuery.js.map +1 -1
  19. package/core/QueryInfo.d.ts.map +1 -1
  20. package/core/QueryInfo.js +4 -2
  21. package/core/QueryInfo.js.map +1 -1
  22. package/core/QueryManager.d.ts +5 -2
  23. package/core/QueryManager.d.ts.map +1 -1
  24. package/core/QueryManager.js +29 -23
  25. package/core/QueryManager.js.map +1 -1
  26. package/core/core.cjs +138 -85
  27. package/core/core.cjs.map +1 -1
  28. package/core/core.cjs.native.js +2141 -0
  29. package/core/index.d.ts +1 -1
  30. package/core/index.d.ts.map +1 -1
  31. package/core/index.js +1 -1
  32. package/core/index.js.map +1 -1
  33. package/core/watchQueryOptions.d.ts +9 -1
  34. package/core/watchQueryOptions.d.ts.map +1 -1
  35. package/core/watchQueryOptions.js.map +1 -1
  36. package/errors/errors.cjs.native.js +48 -0
  37. package/invariantErrorCodes.js +1 -1
  38. package/link/batch/batch.cjs +47 -37
  39. package/link/batch/batch.cjs.map +1 -1
  40. package/link/batch/batch.cjs.native.js +161 -0
  41. package/link/batch/batching.d.ts +2 -6
  42. package/link/batch/batching.d.ts.map +1 -1
  43. package/link/batch/batching.js +47 -37
  44. package/link/batch/batching.js.map +1 -1
  45. package/link/batch-http/batch-http.cjs.native.js +127 -0
  46. package/link/context/context.cjs.native.js +38 -0
  47. package/link/core/core.cjs.native.js +121 -0
  48. package/link/error/error.cjs.native.js +90 -0
  49. package/link/http/http.cjs.native.js +320 -0
  50. package/link/http/selectHttpOptionsAndBody.d.ts.map +1 -1
  51. package/link/http/selectHttpOptionsAndBody.js.map +1 -1
  52. package/link/persisted-queries/index.d.ts +2 -1
  53. package/link/persisted-queries/index.d.ts.map +1 -1
  54. package/link/persisted-queries/index.js +26 -13
  55. package/link/persisted-queries/index.js.map +1 -1
  56. package/link/persisted-queries/persisted-queries.cjs +25 -12
  57. package/link/persisted-queries/persisted-queries.cjs.map +1 -1
  58. package/link/persisted-queries/persisted-queries.cjs.native.js +174 -0
  59. package/link/retry/retry.cjs.native.js +170 -0
  60. package/link/schema/schema.cjs.native.js +56 -0
  61. package/link/subscriptions/subscriptions.cjs.native.js +45 -0
  62. package/link/utils/utils.cjs.native.js +115 -0
  63. package/link/ws/ws.cjs.native.js +28 -0
  64. package/main.cjs.native.js +16 -0
  65. package/package.json +28 -26
  66. package/react/components/components.cjs.native.js +79 -0
  67. package/react/context/ApolloConsumer.js +2 -2
  68. package/react/context/ApolloProvider.js +2 -2
  69. package/react/context/context.cjs +4 -4
  70. package/react/context/context.cjs.map +1 -1
  71. package/react/context/context.cjs.native.js +67 -0
  72. package/react/hoc/hoc.cjs.native.js +325 -0
  73. package/react/hooks/hooks.cjs +365 -253
  74. package/react/hooks/hooks.cjs.map +1 -1
  75. package/react/hooks/hooks.cjs.native.js +612 -0
  76. package/react/hooks/index.d.ts +1 -1
  77. package/react/hooks/index.d.ts.map +1 -1
  78. package/react/hooks/index.js +1 -1
  79. package/react/hooks/index.js.map +1 -1
  80. package/react/hooks/useLazyQuery.d.ts +2 -2
  81. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  82. package/react/hooks/useLazyQuery.js +26 -21
  83. package/react/hooks/useLazyQuery.js.map +1 -1
  84. package/react/hooks/useMutation.d.ts.map +1 -1
  85. package/react/hooks/useMutation.js +13 -10
  86. package/react/hooks/useMutation.js.map +1 -1
  87. package/react/hooks/useQuery.d.ts +36 -2
  88. package/react/hooks/useQuery.d.ts.map +1 -1
  89. package/react/hooks/useQuery.js +245 -206
  90. package/react/hooks/useQuery.js.map +1 -1
  91. package/react/hooks/useSubscription.d.ts.map +1 -1
  92. package/react/hooks/useSubscription.js +17 -7
  93. package/react/hooks/useSubscription.js.map +1 -1
  94. package/react/hooks/useSyncExternalStore.d.ts +4 -0
  95. package/react/hooks/useSyncExternalStore.d.ts.map +1 -0
  96. package/react/hooks/useSyncExternalStore.js +48 -0
  97. package/react/hooks/useSyncExternalStore.js.map +1 -0
  98. package/react/parser/index.d.ts.map +1 -1
  99. package/react/parser/index.js +24 -10
  100. package/react/parser/index.js.map +1 -1
  101. package/react/parser/parser.cjs +24 -10
  102. package/react/parser/parser.cjs.map +1 -1
  103. package/react/parser/parser.cjs.native.js +103 -0
  104. package/react/react.cjs.native.js +22 -0
  105. package/react/ssr/RenderPromises.d.ts +3 -2
  106. package/react/ssr/RenderPromises.d.ts.map +1 -1
  107. package/react/ssr/RenderPromises.js +25 -3
  108. package/react/ssr/RenderPromises.js.map +1 -1
  109. package/react/ssr/ssr.cjs +25 -3
  110. package/react/ssr/ssr.cjs.map +1 -1
  111. package/react/ssr/ssr.cjs.native.js +150 -0
  112. package/react/types/types.d.ts +10 -11
  113. package/react/types/types.d.ts.map +1 -1
  114. package/react/types/types.js.map +1 -1
  115. package/testing/core/core.cjs.native.js +288 -0
  116. package/testing/core/mocking/mockFetch.js +1 -1
  117. package/testing/core/mocking/mockFetch.js.map +1 -1
  118. package/testing/core/mocking/mockQueryManager.js +1 -1
  119. package/testing/core/mocking/mockWatchQuery.js +1 -1
  120. package/testing/core/wrap.js +1 -1
  121. package/testing/testing.cjs.native.js +58 -0
  122. package/utilities/common/canUse.d.ts +2 -0
  123. package/utilities/common/canUse.d.ts.map +1 -1
  124. package/utilities/common/canUse.js +6 -2
  125. package/utilities/common/canUse.js.map +1 -1
  126. package/utilities/common/mergeDeep.d.ts.map +1 -1
  127. package/utilities/common/mergeDeep.js +8 -11
  128. package/utilities/common/mergeDeep.js.map +1 -1
  129. package/utilities/common/mergeOptions.d.ts +5 -0
  130. package/utilities/common/mergeOptions.d.ts.map +1 -0
  131. package/utilities/common/mergeOptions.js +8 -0
  132. package/utilities/common/mergeOptions.js.map +1 -0
  133. package/utilities/globals/global.js +1 -2
  134. package/utilities/globals/globals.cjs.native.js +56 -0
  135. package/utilities/graphql/transform.d.ts +2 -2
  136. package/utilities/graphql/transform.d.ts.map +1 -1
  137. package/utilities/graphql/transform.js +1 -1
  138. package/utilities/graphql/transform.js.map +1 -1
  139. package/utilities/index.d.ts +1 -0
  140. package/utilities/index.d.ts.map +1 -1
  141. package/utilities/index.js +1 -0
  142. package/utilities/index.js.map +1 -1
  143. package/utilities/observables/Concast.d.ts.map +1 -1
  144. package/utilities/observables/Concast.js +5 -2
  145. package/utilities/observables/Concast.js.map +1 -1
  146. package/utilities/policies/pagination.d.ts.map +1 -1
  147. package/utilities/policies/pagination.js +9 -7
  148. package/utilities/policies/pagination.js.map +1 -1
  149. package/utilities/utilities.cjs +37 -23
  150. package/utilities/utilities.cjs.map +1 -1
  151. package/utilities/utilities.cjs.native.js +1281 -0
  152. package/version.js +1 -1
@@ -1,32 +1,38 @@
1
1
  import { __assign } from "tslib";
2
- import { useCallback, useMemo, useState } from 'react';
3
- import { useQuery } from "./useQuery.js";
2
+ import { useCallback, useMemo, useRef } from 'react';
3
+ import { mergeOptions } from "../../utilities/index.js";
4
+ import { useInternalState } from "./useQuery.js";
5
+ import { useApolloClient } from "./useApolloClient.js";
4
6
  var EAGER_METHODS = [
5
7
  'refetch',
8
+ 'reobserve',
6
9
  'fetchMore',
7
10
  'updateQuery',
8
11
  'startPolling',
9
12
  'subscribeToMore',
10
13
  ];
11
14
  export function useLazyQuery(query, options) {
12
- var _a = useState({
13
- called: false,
14
- }), execution = _a[0], setExecution = _a[1];
15
- var result = useQuery(query, __assign(__assign(__assign({}, options), execution.options), { fetchPolicy: execution.called ? options === null || options === void 0 ? void 0 : options.fetchPolicy : 'standby', skip: undefined }));
16
- if (!execution.called) {
17
- result = __assign(__assign({}, result), { loading: false, data: void 0, error: void 0, called: false });
18
- }
15
+ var internalState = useInternalState(useApolloClient(options && options.client), query);
16
+ var execOptionsRef = useRef();
17
+ var merged = execOptionsRef.current
18
+ ? mergeOptions(options, execOptionsRef.current)
19
+ : options;
20
+ var useQueryResult = internalState.useQuery(__assign(__assign({}, merged), { skip: !execOptionsRef.current }));
21
+ var initialFetchPolicy = useQueryResult.observable.options.initialFetchPolicy ||
22
+ internalState.getDefaultFetchPolicy();
23
+ var result = Object.assign(useQueryResult, {
24
+ called: !!execOptionsRef.current,
25
+ });
19
26
  var eagerMethods = useMemo(function () {
20
27
  var eagerMethods = {};
21
28
  var _loop_1 = function (key) {
22
29
  var method = result[key];
23
30
  eagerMethods[key] = function () {
24
- var args = [];
25
- for (var _i = 0; _i < arguments.length; _i++) {
26
- args[_i] = arguments[_i];
31
+ if (!execOptionsRef.current) {
32
+ execOptionsRef.current = Object.create(null);
33
+ internalState.forceUpdate();
27
34
  }
28
- setExecution(function (execution) { return (__assign(__assign({}, execution), { called: true })); });
29
- return method.apply(void 0, args);
35
+ return method.apply(this, arguments);
30
36
  };
31
37
  };
32
38
  for (var _i = 0, EAGER_METHODS_1 = EAGER_METHODS; _i < EAGER_METHODS_1.length; _i++) {
@@ -35,15 +41,14 @@ export function useLazyQuery(query, options) {
35
41
  }
36
42
  return eagerMethods;
37
43
  }, []);
38
- result.error = result.error || void 0;
39
44
  Object.assign(result, eagerMethods);
40
45
  var execute = useCallback(function (executeOptions) {
41
- setExecution({ called: true, options: executeOptions });
42
- var promise = result.refetch(executeOptions === null || executeOptions === void 0 ? void 0 : executeOptions.variables).then(function (result1) {
43
- var result2 = __assign(__assign({}, result), { data: result1.data, error: result1.error, called: true, loading: false });
44
- Object.assign(result2, eagerMethods);
45
- return result2;
46
- });
46
+ execOptionsRef.current = executeOptions ? __assign(__assign({}, executeOptions), { fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy }) : {
47
+ fetchPolicy: initialFetchPolicy,
48
+ };
49
+ var promise = internalState
50
+ .asyncUpdate()
51
+ .then(function (queryResult) { return Object.assign(queryResult, eagerMethods); });
47
52
  promise.catch(function () { });
48
53
  return promise;
49
54
  }, []);
@@ -1 +1 @@
1
- {"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAOvD,OAAO,EAAE,QAAQ,EAAE,MAAM,YAAY,CAAC;AAKtC,IAAM,aAAa,GAAG;IACpB,SAAS;IACT,WAAW;IACX,aAAa;IACb,cAAc;IACd,iBAAiB;CACT,CAAC;AAEX,MAAM,UAAU,YAAY,CAC1B,KAA0D,EAC1D,OAAiD;IAE3C,IAAA,KAA4B,QAAQ,CAGvC;QACD,MAAM,EAAE,KAAK;KACd,CAAC,EALK,SAAS,QAAA,EAAE,YAAY,QAK5B,CAAC;IAEH,IAAI,MAAM,GAAG,QAAQ,CAAoB,KAAK,iCACzC,OAAO,GACP,SAAS,CAAC,OAAO,KAGpB,WAAW,EAAE,SAAS,CAAC,MAAM,CAAC,CAAC,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,WAAW,CAAC,CAAC,CAAC,SAAS,EAChE,IAAI,EAAE,SAAS,IACf,CAAC;IAEH,IAAI,CAAC,SAAS,CAAC,MAAM,EAAE;QACrB,MAAM,yBACD,MAAM,KACT,OAAO,EAAE,KAAK,EACd,IAAI,EAAE,KAAK,CAAqB,EAChC,KAAK,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AAO,EAAE,YAAY,CAAC,CAAC;YACrC,OAAO,OAAO,CAAC;QACjB,CAAC,CAAC,CAAC;QAIH,OAAO,CAAC,KAAK,CAAC,cAAO,CAAC,CAAC,CAAC;QAExB,OAAO,OAAO,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport { useCallback, useMemo, useState } from 'react';\n\nimport {\n LazyQueryHookOptions,\n QueryLazyOptions,\n QueryTuple,\n} from '../types/types';\nimport { useQuery } from './useQuery';\nimport { OperationVariables } from '../../core';\n\n// The following methods, when called will execute the query, regardless of\n// whether the useLazyQuery execute function was called before.\nconst EAGER_METHODS = [\n 'refetch',\n 'fetchMore',\n 'updateQuery',\n 'startPolling',\n 'subscribeToMore',\n] as const;\n\nexport function useLazyQuery<TData = any, TVariables = OperationVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LazyQueryHookOptions<TData, TVariables>\n): QueryTuple<TData, TVariables> {\n const [execution, setExecution] = useState<{\n called: boolean,\n options?: QueryLazyOptions<TVariables>,\n }>({\n called: false,\n });\n\n let result = useQuery<TData, TVariables>(query, {\n ...options,\n ...execution.options,\n // We don’t set skip to execution.called, because some useQuery SSR code\n // checks skip for some reason.\n fetchPolicy: execution.called ? options?.fetchPolicy : 'standby',\n skip: undefined,\n });\n\n if (!execution.called) {\n result = {\n ...result,\n loading: false,\n data: void 0 as unknown as TData,\n error: void 0,\n called: false,\n };\n }\n\n // We use useMemo here to make sure the eager methods have a stable identity.\n const eagerMethods = useMemo(() => {\n const eagerMethods: Record<string, any> = {};\n for (const key of EAGER_METHODS) {\n const method = result[key];\n eagerMethods[key] = (...args: any) => {\n setExecution((execution) => ({ ...execution, called: true }));\n return (method as any)(...args);\n };\n }\n\n return eagerMethods;\n }, []);\n\n result.error = result.error || void 0;\n Object.assign(result, eagerMethods);\n\n const execute = useCallback<\n QueryTuple<TData, TVariables>[0]\n >((executeOptions?: QueryLazyOptions<TVariables>) => {\n setExecution({ called: true, options: executeOptions });\n const promise = result.refetch(executeOptions?.variables).then((result1) => {\n const result2 = {\n ...result,\n data: result1.data,\n error: result1.error,\n called: true,\n loading: false,\n };\n\n Object.assign(result2, eagerMethods);\n return result2;\n });\n\n // Because the return value of `useLazyQuery` is usually floated, we need\n // to catch the promise to prevent unhandled rejections.\n promise.catch(() => {});\n\n return promise;\n }, []);\n\n return [execute, result];\n}\n"]}
1
+ {"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,MAAM,EAAE,MAAM,OAAO,CAAC;AAGrD,OAAO,EAAE,YAAY,EAAE,MAAM,iBAAiB,CAAC;AAM/C,OAAO,EAAE,gBAAgB,EAAE,MAAM,YAAY,CAAC;AAC9C,OAAO,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAC;AAIpD,IAAM,aAAa,GAAG;IACpB,SAAS;IACT,WAAW;IACX,WAAW;IACX,aAAa;IACb,cAAc;IACd,iBAAiB;CACT,CAAC;AAEX,MAAM,UAAU,YAAY,CAC1B,KAA0D,EAC1D,OAAiD;IAEjD,IAAM,aAAa,GAAG,gBAAgB,CACpC,eAAe,CAAC,OAAO,IAAI,OAAO,CAAC,MAAM,CAAC,EAC1C,KAAK,CACN,CAAC;IAEF,IAAM,cAAc,GAAG,MAAM,EAAoD,CAAC;IAClF,IAAM,MAAM,GAAG,cAAc,CAAC,OAAO;QACnC,CAAC,CAAC,YAAY,CAAC,OAAO,EAAE,cAAc,CAAC,OAAO,CAAC;QAC/C,CAAC,CAAC,OAAO,CAAC;IAEZ,IAAM,cAAc,GAAG,aAAa,CAAC,QAAQ,uBACxC,MAAM,KACT,IAAI,EAAE,CAAC,cAAc,CAAC,OAAO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C,WAAW,EAAE,YAAY,CAAC,EAAxC,CAAwC,CAAC,CAAC;QAIjE,OAAO,CAAC,KAAK,CAAC,cAAO,CAAC,CAAC,CAAC;QAExB,OAAO,OAAO,CAAC;IACjB,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,OAAO,CAAC,OAAO,EAAE,MAAM,CAAC,CAAC;AAC3B,CAAC","sourcesContent":["import { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport { useCallback, useMemo, useRef } from 'react';\n\nimport { OperationVariables } from '../../core';\nimport { mergeOptions } from '../../utilities';\nimport {\n LazyQueryHookOptions,\n LazyQueryResultTuple,\n QueryResult,\n} from '../types/types';\nimport { useInternalState } from './useQuery';\nimport { useApolloClient } from './useApolloClient';\n\n// The following methods, when called will execute the query, regardless of\n// whether the useLazyQuery execute function was called before.\nconst EAGER_METHODS = [\n 'refetch',\n 'reobserve',\n 'fetchMore',\n 'updateQuery',\n 'startPolling',\n 'subscribeToMore',\n] as const;\n\nexport function useLazyQuery<TData = any, TVariables = OperationVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: LazyQueryHookOptions<TData, TVariables>\n): LazyQueryResultTuple<TData, TVariables> {\n const internalState = useInternalState(\n useApolloClient(options && options.client),\n query,\n );\n\n const execOptionsRef = useRef<Partial<LazyQueryHookOptions<TData, TVariables>>>();\n const merged = execOptionsRef.current\n ? mergeOptions(options, execOptionsRef.current)\n : options;\n\n const useQueryResult = internalState.useQuery({\n ...merged,\n skip: !execOptionsRef.current,\n });\n\n const initialFetchPolicy =\n useQueryResult.observable.options.initialFetchPolicy ||\n internalState.getDefaultFetchPolicy();\n\n const result: QueryResult<TData, TVariables> =\n Object.assign(useQueryResult, {\n called: !!execOptionsRef.current,\n });\n\n // We use useMemo here to make sure the eager methods have a stable identity.\n const eagerMethods = useMemo(() => {\n const eagerMethods: Record<string, any> = {};\n for (const key of EAGER_METHODS) {\n const method = result[key];\n eagerMethods[key] = function () {\n if (!execOptionsRef.current) {\n execOptionsRef.current = Object.create(null);\n // Only the first time populating execOptionsRef.current matters here.\n internalState.forceUpdate();\n }\n return method.apply(this, arguments);\n };\n }\n\n return eagerMethods;\n }, []);\n\n Object.assign(result, eagerMethods);\n\n const execute = useCallback<\n LazyQueryResultTuple<TData, TVariables>[0]\n >(executeOptions => {\n execOptionsRef.current = executeOptions ? {\n ...executeOptions,\n fetchPolicy: executeOptions.fetchPolicy || initialFetchPolicy,\n } : {\n fetchPolicy: initialFetchPolicy,\n };\n\n const promise = internalState\n .asyncUpdate() // Like internalState.forceUpdate, but returns a Promise.\n .then(queryResult => Object.assign(queryResult, eagerMethods));\n\n // Because the return value of `useLazyQuery` is usually floated, we need\n // to catch the promise to prevent unhandled rejections.\n promise.catch(() => {});\n\n return promise;\n }, []);\n\n return [execute, result];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAEL,mBAAmB,EAEnB,aAAa,EACd,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,WAAW,EACX,cAAc,EAEd,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAMpB,wBAAgB,WAAW,CACzB,KAAK,GAAG,GAAG,EACX,UAAU,GAAG,kBAAkB,EAC/B,QAAQ,GAAG,cAAc,EACzB,MAAM,SAAS,WAAW,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,EAElD,QAAQ,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC7D,OAAO,CAAC,EAAE,mBAAmB,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,GACzD,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CAmHpD"}
1
+ {"version":3,"file":"useMutation.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AACvC,OAAO,EAAE,iBAAiB,EAAE,MAAM,mCAAmC,CAAC;AACtE,OAAO,EAEL,mBAAmB,EAEnB,aAAa,EACd,MAAM,gBAAgB,CAAC;AAExB,OAAO,EACL,WAAW,EACX,cAAc,EAEd,kBAAkB,EACnB,MAAM,YAAY,CAAC;AAMpB,wBAAgB,WAAW,CACzB,KAAK,GAAG,GAAG,EACX,UAAU,GAAG,kBAAkB,EAC/B,QAAQ,GAAG,cAAc,EACzB,MAAM,SAAS,WAAW,CAAC,GAAG,CAAC,GAAG,WAAW,CAAC,GAAG,CAAC,EAElD,QAAQ,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC7D,OAAO,CAAC,EAAE,mBAAmB,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,CAAC,GACzD,aAAa,CAAC,KAAK,EAAE,UAAU,EAAE,QAAQ,EAAE,MAAM,CAAC,CAuHpD"}
@@ -40,7 +40,7 @@ export function useMutation(mutation, options) {
40
40
  var mutationId = ++ref.current.mutationId;
41
41
  var clientOptions = mergeOptions(baseOptions, executeOptions);
42
42
  return client.mutate(clientOptions).then(function (response) {
43
- var _a, _b;
43
+ var _a, _b, _c;
44
44
  var data = response.data, errors = response.errors;
45
45
  var error = errors && errors.length > 0
46
46
  ? new ApolloError({ graphQLErrors: errors })
@@ -58,11 +58,11 @@ export function useMutation(mutation, options) {
58
58
  setResult(ref.current.result = result_1);
59
59
  }
60
60
  }
61
- (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
62
- (_b = executeOptions.onCompleted) === null || _b === void 0 ? void 0 : _b.call(executeOptions, response.data);
61
+ (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, response.data);
62
+ (_c = executeOptions.onCompleted) === null || _c === void 0 ? void 0 : _c.call(executeOptions, response.data);
63
63
  return response;
64
64
  }).catch(function (error) {
65
- var _a, _b;
65
+ var _a, _b, _c, _d;
66
66
  if (mutationId === ref.current.mutationId &&
67
67
  ref.current.isMounted) {
68
68
  var result_2 = {
@@ -76,9 +76,9 @@ export function useMutation(mutation, options) {
76
76
  setResult(ref.current.result = result_2);
77
77
  }
78
78
  }
79
- if (baseOptions.onError || clientOptions.onError) {
80
- (_a = baseOptions.onError) === null || _a === void 0 ? void 0 : _a.call(baseOptions, error);
81
- (_b = executeOptions.onError) === null || _b === void 0 ? void 0 : _b.call(executeOptions, error);
79
+ if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) || clientOptions.onError) {
80
+ (_c = (_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.onError) === null || _c === void 0 ? void 0 : _c.call(_b, error);
81
+ (_d = executeOptions.onError) === null || _d === void 0 ? void 0 : _d.call(executeOptions, error);
82
82
  return { data: void 0, errors: error };
83
83
  }
84
84
  throw error;
@@ -87,9 +87,12 @@ export function useMutation(mutation, options) {
87
87
  var reset = useCallback(function () {
88
88
  setResult({ called: false, loading: false, client: client });
89
89
  }, []);
90
- useEffect(function () { return function () {
91
- ref.current.isMounted = false;
92
- }; }, []);
90
+ useEffect(function () {
91
+ ref.current.isMounted = true;
92
+ return function () {
93
+ ref.current.isMounted = false;
94
+ };
95
+ }, []);
93
96
  return [execute, __assign({ reset: reset }, result)];
94
97
  }
95
98
  //# sourceMappingURL=useMutation.js.map
@@ -1 +1 @@
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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AO,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
+ {"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,QAA6D,EAC7D,OAA0D;IAE1D,IAAM,MAAM,GAAG,eAAe,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,MAAM,CAAC,CAAC;IAChD,kBAAkB,CAAC,QAAQ,EAAE,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AG,CAAC,OAAO,CAAC,MAAM,EAAE,QAAM,CAAC,EAAE;oBACtC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,QAAM,CAAC,CAAC;iBACxC;aACF;YAED,IAAI,CAAA,MAAA,GAAG,CAAC,OAAO,CAAC,OAAO,0CAAE,OAAO,KAAI,aAAa,CAAC,OAAO,EAAE;gBACzD,MAAA,MAAA,GAAG,CAAC,OAAO,CAAC,OAAO,0CAAE,OAAO,mDAAG,KAAK,CAAC,CAAC;gBACtC,MAAA,cAAc,CAAC,OAAO,+DAAG,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;QACR,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,IAAI,CAAC;QAE7B,OAAO;YACL,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;QAChC,CAAC,CAAC;IACJ,CAAC,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 ref.current.options?.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 (ref.current.options?.onError || clientOptions.onError) {\n ref.current.options?.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 = true;\n\n return () => {\n ref.current.isMounted = false;\n };\n }, []);\n\n return [execute, { reset, ...result }];\n}\n"]}
@@ -1,5 +1,39 @@
1
- import { OperationVariables } from '../../core';
2
- import { DocumentNode, TypedDocumentNode } from '../../core';
1
+ import { OperationVariables, WatchQueryFetchPolicy } from '../../core';
2
+ import { ApolloClient, ApolloQueryResult, DocumentNode, TypedDocumentNode } from '../../core';
3
3
  import { QueryHookOptions, QueryResult } from '../types/types';
4
+ import { useApolloClient } from './useApolloClient';
4
5
  export declare function useQuery<TData = any, TVariables = OperationVariables>(query: DocumentNode | TypedDocumentNode<TData, TVariables>, options?: QueryHookOptions<TData, TVariables>): QueryResult<TData, TVariables>;
6
+ export declare function useInternalState<TData, TVariables>(client: ApolloClient<any>, query: DocumentNode | TypedDocumentNode<TData, TVariables>): InternalState<TData, TVariables>;
7
+ declare class InternalState<TData, TVariables> {
8
+ readonly client: ReturnType<typeof useApolloClient>;
9
+ readonly query: DocumentNode | TypedDocumentNode<TData, TVariables>;
10
+ constructor(client: ReturnType<typeof useApolloClient>, query: DocumentNode | TypedDocumentNode<TData, TVariables>, previous?: InternalState<TData, TVariables>);
11
+ forceUpdate(): void;
12
+ asyncUpdate(): Promise<QueryResult<TData, TVariables>>;
13
+ private asyncResolveFns;
14
+ private optionsToIgnoreOnce;
15
+ useQuery(options: QueryHookOptions<TData, TVariables>): QueryResult<TData, TVariables>;
16
+ private renderPromises;
17
+ private queryHookOptions;
18
+ private watchQueryOptions;
19
+ private useOptions;
20
+ private ssrDisabledResult;
21
+ private skipStandbyResult;
22
+ private createWatchQueryOptions;
23
+ getDefaultFetchPolicy(): WatchQueryFetchPolicy;
24
+ private onCompleted;
25
+ private onError;
26
+ private observable;
27
+ private obsQueryFields;
28
+ private useObservableQuery;
29
+ private result;
30
+ private previousData;
31
+ private setResult;
32
+ private handleErrorOrCompleted;
33
+ private getCurrentResult;
34
+ private toQueryResultCache;
35
+ toQueryResult(result: ApolloQueryResult<TData>): QueryResult<TData, TVariables>;
36
+ private unsafeHandlePartialRefetch;
37
+ }
38
+ export {};
5
39
  //# sourceMappingURL=useQuery.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAgB,MAAM,YAAY,CAAC;AAG9D,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,CAsShC"}
1
+ {"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":"AAYA,OAAO,EAAgB,kBAAkB,EAAE,qBAAqB,EAAE,MAAM,YAAY,CAAC;AAGrF,OAAO,EACL,YAAY,EACZ,iBAAiB,EAGjB,YAAY,EACZ,iBAAiB,EAElB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,gBAAgB,EAChB,WAAW,EAEZ,MAAM,gBAAgB,CAAC;AAGxB,OAAO,EAAE,eAAe,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