@apollo/client 3.5.0 → 3.6.0-beta.1

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 (132) hide show
  1. package/README.md +1 -1
  2. package/apollo-client.cjs +153 -178
  3. package/apollo-client.cjs.map +1 -1
  4. package/apollo-client.min.cjs +1 -1
  5. package/cache/core/cache.js +2 -2
  6. package/cache/inmemory/entityStore.js +4 -4
  7. package/cache/inmemory/inMemoryCache.js +3 -3
  8. package/cache/inmemory/object-canon.js +2 -2
  9. package/cache/inmemory/policies.js +1 -1
  10. package/cache/inmemory/reactiveVars.js +2 -2
  11. package/cache/inmemory/readFromStore.js +2 -2
  12. package/cache/inmemory/writeToStore.js +3 -3
  13. package/config/jest/setup.js +1 -1
  14. package/core/ApolloClient.d.ts +0 -1
  15. package/core/ApolloClient.d.ts.map +1 -1
  16. package/core/ApolloClient.js +1 -1
  17. package/core/LocalState.js +2 -2
  18. package/core/ObservableQuery.d.ts +0 -1
  19. package/core/ObservableQuery.d.ts.map +1 -1
  20. package/core/ObservableQuery.js +2 -2
  21. package/core/QueryInfo.d.ts +2 -2
  22. package/core/QueryInfo.d.ts.map +1 -1
  23. package/core/QueryInfo.js +2 -2
  24. package/core/QueryManager.d.ts +0 -1
  25. package/core/QueryManager.d.ts.map +1 -1
  26. package/core/QueryManager.js +2 -2
  27. package/core/core.cjs +1 -1
  28. package/core/core.cjs.map +1 -1
  29. package/core/index.js +2 -2
  30. package/errors/index.js +1 -1
  31. package/invariantErrorCodes.js +1 -1
  32. package/link/batch/batchLink.d.ts +0 -1
  33. package/link/batch/batchLink.d.ts.map +1 -1
  34. package/link/batch/batchLink.js +1 -1
  35. package/link/batch/batching.d.ts +0 -1
  36. package/link/batch/batching.d.ts.map +1 -1
  37. package/link/batch/batching.js +1 -1
  38. package/link/batch-http/batchHttpLink.d.ts +0 -1
  39. package/link/batch-http/batchHttpLink.d.ts.map +1 -1
  40. package/link/batch-http/batchHttpLink.js +1 -1
  41. package/link/context/index.js +1 -1
  42. package/link/core/ApolloLink.d.ts +0 -1
  43. package/link/core/ApolloLink.d.ts.map +1 -1
  44. package/link/core/ApolloLink.js +1 -1
  45. package/link/core/types.d.ts +0 -1
  46. package/link/core/types.d.ts.map +1 -1
  47. package/link/error/index.d.ts +0 -1
  48. package/link/error/index.d.ts.map +1 -1
  49. package/link/error/index.js +1 -1
  50. package/link/http/HttpLink.js +1 -1
  51. package/link/http/createHttpLink.js +2 -2
  52. package/link/http/selectHttpOptionsAndBody.js +2 -2
  53. package/link/persisted-queries/index.js +2 -2
  54. package/link/retry/retryLink.d.ts +0 -1
  55. package/link/retry/retryLink.d.ts.map +1 -1
  56. package/link/retry/retryLink.js +1 -1
  57. package/link/schema/index.d.ts +0 -1
  58. package/link/schema/index.d.ts.map +1 -1
  59. package/link/schema/index.js +2 -2
  60. package/link/utils/createOperation.js +1 -1
  61. package/link/utils/fromError.d.ts +0 -1
  62. package/link/utils/fromError.d.ts.map +1 -1
  63. package/link/utils/fromPromise.d.ts +0 -1
  64. package/link/utils/fromPromise.d.ts.map +1 -1
  65. package/link/utils/toPromise.d.ts +0 -1
  66. package/link/utils/toPromise.d.ts.map +1 -1
  67. package/link/ws/index.d.ts +0 -1
  68. package/link/ws/index.d.ts.map +1 -1
  69. package/link/ws/index.js +2 -2
  70. package/package.json +12 -8
  71. package/react/components/Mutation.js +1 -1
  72. package/react/components/Query.js +2 -2
  73. package/react/components/Subscription.js +1 -1
  74. package/react/context/ApolloConsumer.js +1 -1
  75. package/react/context/ApolloContext.js +1 -1
  76. package/react/context/ApolloProvider.js +1 -1
  77. package/react/hoc/hoc-utils.js +2 -2
  78. package/react/hoc/mutation-hoc.js +3 -3
  79. package/react/hoc/query-hoc.js +3 -3
  80. package/react/hoc/subscription-hoc.js +3 -3
  81. package/react/hoc/withApollo.js +3 -3
  82. package/react/hooks/hooks.cjs +149 -174
  83. package/react/hooks/hooks.cjs.map +1 -1
  84. package/react/hooks/useApolloClient.js +1 -1
  85. package/react/hooks/useLazyQuery.d.ts.map +1 -1
  86. package/react/hooks/useLazyQuery.js +2 -2
  87. package/react/hooks/useLazyQuery.js.map +1 -1
  88. package/react/hooks/useMutation.d.ts.map +1 -1
  89. package/react/hooks/useMutation.js +70 -54
  90. package/react/hooks/useMutation.js.map +1 -1
  91. package/react/hooks/useQuery.d.ts.map +1 -1
  92. package/react/hooks/useQuery.js +85 -126
  93. package/react/hooks/useQuery.js.map +1 -1
  94. package/react/hooks/useReactiveVar.js +1 -1
  95. package/react/hooks/useSubscription.js +2 -2
  96. package/react/ssr/RenderPromises.d.ts +2 -2
  97. package/react/ssr/RenderPromises.d.ts.map +1 -1
  98. package/react/ssr/RenderPromises.js +5 -7
  99. package/react/ssr/RenderPromises.js.map +1 -1
  100. package/react/ssr/getDataFromTree.js +2 -2
  101. package/react/ssr/ssr.cjs +5 -7
  102. package/react/ssr/ssr.cjs.map +1 -1
  103. package/react/types/types.d.ts +0 -1
  104. package/react/types/types.d.ts.map +1 -1
  105. package/testing/core/mocking/mockFetch.js +2 -2
  106. package/testing/core/mocking/mockLink.d.ts +0 -1
  107. package/testing/core/mocking/mockLink.d.ts.map +1 -1
  108. package/testing/core/mocking/mockLink.js +3 -3
  109. package/testing/core/mocking/mockSubscriptionLink.d.ts +0 -1
  110. package/testing/core/mocking/mockSubscriptionLink.d.ts.map +1 -1
  111. package/testing/core/mocking/mockSubscriptionLink.js +1 -1
  112. package/testing/core/mocking/mockWatchQuery.js +1 -1
  113. package/testing/core/observableToPromise.js +1 -1
  114. package/testing/react/MockedProvider.js +2 -2
  115. package/utilities/common/mergeDeep.js +1 -1
  116. package/utilities/globals/fix-graphql.js +2 -2
  117. package/utilities/globals/index.js +1 -1
  118. package/utilities/graphql/directives.js +1 -1
  119. package/utilities/graphql/fragments.d.ts.map +1 -1
  120. package/utilities/graphql/fragments.js +1 -1
  121. package/utilities/graphql/fragments.js.map +1 -1
  122. package/utilities/graphql/transform.js +2 -2
  123. package/utilities/observables/Concast.d.ts +0 -1
  124. package/utilities/observables/Concast.d.ts.map +1 -1
  125. package/utilities/observables/Concast.js +1 -1
  126. package/utilities/observables/Observable.js +2 -2
  127. package/utilities/observables/asyncMap.d.ts +0 -1
  128. package/utilities/observables/asyncMap.d.ts.map +1 -1
  129. package/utilities/observables/subclassing.d.ts +0 -1
  130. package/utilities/observables/subclassing.d.ts.map +1 -1
  131. package/utilities/policies/pagination.js +2 -2
  132. package/version.js +1 -1
@@ -1 +1 @@
1
- {"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAQzD,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,CAMxC;QACA,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,EAAE;KACb,CAAC,EATK,SAAS,QAAA,EAAE,YAAY,QAS5B,CAAC;IAEH,IAAM,OAAO,GAAG,WAAW,CAEzB,UAAC,cAA6C;QAC9C,IAAI,OAA8D,CAAC;QACnE,IAAM,OAAO,GAAG,IAAI,OAAO,CACzB,UAAC,QAAQ,IAAK,OAAA,CAAC,OAAO,GAAG,QAAQ,CAAC,EAApB,CAAoB,CACnC,CAAC;QACF,YAAY,CAAC,UAAC,SAAS;YACrB,IAAI,SAAS,CAAC,MAAM,EAAE;gBACpB,MAAM,IAAI,MAAM,CAAC,OAAO,CAAC,cAAc,aAAd,cAAc,uBAAd,cAAc,CAAE,SAAS,CAAC,CAAC;aACrD;YAED,OAAO;gBACL,MAAM,EAAE,IAAI;gBACZ,QAAQ,kCAAM,SAAS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M,EAAE,IAAI,IAAG,EAAhC,CAAgC,CAAC,CAAC;gBAC9D,OAAQ,MAAc,eAAI,IAAI,EAAE;YAClC,CAAC,CAAC;;QALJ,KAAkB,UAAa,EAAb,+BAAa,EAAb,2BAAa,EAAb,IAAa;YAA1B,IAAM,GAAG,sBAAA;oBAAH,GAAG;SAMb;KACF;IAGD,OAAO,CAAC,OAAO,EAAE,MAA4C,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport { useCallback, useEffect, useState } from 'react';\n\nimport {\n LazyQueryHookOptions,\n LazyQueryResult,\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 {\n called: boolean,\n options?: QueryLazyOptions<TVariables>,\n resolves: Array<(result: LazyQueryResult<TData, TVariables>) => void>,\n }\n >({\n called: false,\n resolves: [],\n });\n\n const execute = useCallback<\n QueryTuple<TData, TVariables>[0]\n >((executeOptions?: QueryLazyOptions<TVariables>) => {\n let resolve!: (result: LazyQueryResult<TData, TVariables>) => void;\n const promise = new Promise<LazyQueryResult<TData, TVariables>>(\n (resolve1) => (resolve = resolve1),\n );\n setExecution((execution) => {\n if (execution.called) {\n result && result.refetch(executeOptions?.variables);\n }\n\n return {\n called: true,\n resolves: [...execution.resolves, resolve],\n options: executeOptions,\n };\n });\n\n return promise;\n }, []);\n\n let result = useQuery<TData, TVariables>(query, {\n ...options,\n ...execution.options,\n // We don’t set skip to execution.called, because we need useQuery to call\n // addQueryPromise, so that ssr calls waits for execute to be called.\n fetchPolicy: execution.called ? options?.fetchPolicy : 'standby',\n skip: undefined,\n });\n useEffect(() => {\n const { resolves } = execution;\n if (!result.loading && resolves.length) {\n setExecution((execution) => ({ ...execution, resolves: [] }));\n resolves.forEach((resolve) => resolve(result));\n }\n }, [result, execution]);\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 // TODO: fix the type of result\n called: false as any,\n };\n\n\n for (const key of EAGER_METHODS) {\n const method = result[key];\n result[key] = (...args: any) => {\n setExecution((execution) => ({ ...execution, called: true }));\n return (method as any)(...args);\n };\n }\n }\n\n // TODO: fix the type of result\n return [execute, result as LazyQueryResult<TData, TVariables>];\n}\n"]}
1
+ {"version":3,"file":"useLazyQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useLazyQuery.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAQzD,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,CAMxC;QACA,MAAM,EAAE,KAAK;QACb,QAAQ,EAAE,EAAE;KACb,CAAC,EATK,SAAS,QAAA,EAAE,YAAY,QAS5B,CAAC;IAEH,IAAM,OAAO,GAAG,WAAW,CAEzB,UAAC,cAA6C;QAC9C,IAAI,OAA8D,CAAC;QACnE,IAAM,OAAO,GAAG,IAAI,OAAO,CACzB,UAAC,QAAQ,IAAK,OAAA,CAAC,OAAO,GAAG,QAAQ,CAAC,EAApB,CAAoB,CACnC,CAAC;QACF,YAAY,CAAC,UAAC,SAAS;YACrB,IAAI,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,CAAC,CAAC;YAC3B,MAAM,CAAC,GAAG,CAAC,GAAG;gBAAC,cAAY;qBAAZ,UAAY,EAAZ,qBAAY,EAAZ,IAAY;oBAAZ,yBAAY;;gBACzB,YAAY,CAAC,UAAC,SAAS,IAAK,OAAA,uBAAM,SAAS,KAAE,MAAM,EAAE,IAAI,IAAG,EAAhC,CAAgC,CAAC,CAAC;gBAC9D,OAAQ,MAAc,eAAI,IAAI,EAAE;YAClC,CAAC,CAAC;;QALJ,KAAkB,UAAa,EAAb,+BAAa,EAAb,2BAAa,EAAb,IAAa;YAA1B,IAAM,GAAG,sBAAA;oBAAH,GAAG;SAMb;KACF;IAGD,OAAO,CAAC,OAAO,EAAE,MAA4C,CAAC,CAAC;AACjE,CAAC","sourcesContent":["import { DocumentNode } from 'graphql';\nimport { TypedDocumentNode } from '@graphql-typed-document-node/core';\nimport { useCallback, useEffect, useState } from 'react';\n\nimport {\n LazyQueryHookOptions,\n LazyQueryResult,\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 {\n called: boolean,\n options?: QueryLazyOptions<TVariables>,\n resolves: Array<(result: LazyQueryResult<TData, TVariables>) => void>,\n }\n >({\n called: false,\n resolves: [],\n });\n\n const execute = useCallback<\n QueryTuple<TData, TVariables>[0]\n >((executeOptions?: QueryLazyOptions<TVariables>) => {\n let resolve!: (result: LazyQueryResult<TData, TVariables>) => void;\n const promise = new Promise<LazyQueryResult<TData, TVariables>>(\n (resolve1) => (resolve = resolve1),\n );\n setExecution((execution) => {\n if (execution.called) {\n result && result.refetch(executeOptions?.variables);\n }\n\n return {\n called: true,\n resolves: [...execution.resolves, resolve],\n options: executeOptions,\n };\n });\n\n return promise;\n }, []);\n\n let result = useQuery<TData, TVariables>(query, {\n ...options,\n ...execution.options,\n // We don’t set skip to execution.called, because we need useQuery to call\n // addQueryPromise, so that ssr calls waits for execute to be called.\n fetchPolicy: execution.called ? options?.fetchPolicy : 'standby',\n skip: undefined,\n });\n useEffect(() => {\n const { resolves } = execution;\n if (!result.loading && resolves.length) {\n setExecution((execution) => ({ ...execution, resolves: [] }));\n resolves.forEach((resolve) => resolve(result));\n }\n }, [result, execution]);\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 // TODO: fix the type of result\n called: false as any,\n };\n\n for (const key of EAGER_METHODS) {\n const method = result[key];\n result[key] = (...args: any) => {\n setExecution((execution) => ({ ...execution, called: true }));\n return (method as any)(...args);\n };\n }\n }\n\n // TODO: fix the type of result\n return [execute, result as LazyQueryResult<TData, TVariables>];\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,CAyGpD"}
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,CA2HpD"}
@@ -1,7 +1,7 @@
1
- import { __assign } from "tslib/tslib.es6.js";
2
- import { useCallback, useEffect, useRef, useState } from "react/index.js";
1
+ import { __assign } from "tslib";
2
+ import { useCallback, useMemo, useEffect, useRef, useState } from 'react';
3
3
  import { mergeOptions, } from "../../core/index.js";
4
- import { equal } from "@wry/equality/lib/equality.esm.js";
4
+ import { equal } from '@wry/equality';
5
5
  import { DocumentType, verifyDocumentType } from "../parser/index.js";
6
6
  import { ApolloError } from "../../errors/index.js";
7
7
  import { useApolloClient } from "./useApolloClient.js";
@@ -17,63 +17,79 @@ export function useMutation(mutation, options) {
17
17
  result: result,
18
18
  mutationId: 0,
19
19
  isMounted: true,
20
+ execute: null,
21
+ client: client,
22
+ mutation: mutation,
23
+ options: options,
20
24
  });
21
- var execute = useCallback(function (executeOptions) {
22
- if (executeOptions === void 0) { executeOptions = {}; }
23
- var baseOptions = __assign(__assign({}, options), { mutation: mutation });
24
- if (!ref.current.result.loading && !baseOptions.ignoreResults) {
25
- setResult(ref.current.result = {
26
- loading: true,
27
- error: void 0,
28
- data: void 0,
29
- called: true,
30
- client: client,
31
- });
25
+ var execute = useMemo(function () {
26
+ if (ref.current.execute != null &&
27
+ ref.current.client === client &&
28
+ equal(options, ref.current.options) &&
29
+ equal(mutation, ref.current.mutation)) {
30
+ return ref.current.execute;
32
31
  }
33
- var mutationId = ++ref.current.mutationId;
34
- var clientOptions = mergeOptions(baseOptions, executeOptions);
35
- return client.mutate(clientOptions).then(function (response) {
36
- var _a;
37
- var data = response.data, errors = response.errors;
38
- var error = errors && errors.length > 0
39
- ? new ApolloError({ graphQLErrors: errors })
40
- : void 0;
41
- if (mutationId === ref.current.mutationId &&
42
- !baseOptions.ignoreResults) {
43
- var result_1 = {
44
- called: true,
45
- loading: false,
46
- data: data,
47
- error: error,
48
- client: client,
49
- };
50
- if (ref.current.isMounted && !equal(ref.current.result, result_1)) {
51
- setResult(ref.current.result = result_1);
52
- }
53
- }
54
- (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
55
- return response;
56
- }).catch(function (error) {
57
- if (mutationId === ref.current.mutationId &&
58
- ref.current.isMounted) {
59
- var result_2 = {
60
- loading: false,
61
- error: error,
32
+ ref.current.client = client;
33
+ ref.current.options = options;
34
+ ref.current.mutation = mutation;
35
+ ref.current.execute = function (executeOptions) {
36
+ if (executeOptions === void 0) { executeOptions = {}; }
37
+ var baseOptions = __assign(__assign({}, options), { mutation: mutation });
38
+ if (!ref.current.result.loading && !baseOptions.ignoreResults) {
39
+ setResult(ref.current.result = {
40
+ loading: true,
41
+ error: void 0,
62
42
  data: void 0,
63
43
  called: true,
64
44
  client: client,
65
- };
66
- if (!equal(ref.current.result, result_2)) {
67
- setResult(ref.current.result = result_2);
68
- }
69
- }
70
- if (baseOptions.onError) {
71
- baseOptions.onError(error);
72
- return { data: void 0, errors: error };
45
+ });
73
46
  }
74
- throw error;
75
- });
76
- }, [client, options, mutation]);
47
+ var mutationId = ++ref.current.mutationId;
48
+ var clientOptions = mergeOptions(baseOptions, executeOptions);
49
+ return client.mutate(clientOptions).then(function (response) {
50
+ var _a;
51
+ var data = response.data, errors = response.errors;
52
+ var error = errors && errors.length > 0
53
+ ? new ApolloError({ graphQLErrors: errors })
54
+ : void 0;
55
+ if (mutationId === ref.current.mutationId &&
56
+ !baseOptions.ignoreResults) {
57
+ var result_1 = {
58
+ called: true,
59
+ loading: false,
60
+ data: data,
61
+ error: error,
62
+ client: client,
63
+ };
64
+ if (ref.current.isMounted && !equal(ref.current.result, result_1)) {
65
+ setResult(ref.current.result = result_1);
66
+ }
67
+ }
68
+ (_a = baseOptions.onCompleted) === null || _a === void 0 ? void 0 : _a.call(baseOptions, response.data);
69
+ return response;
70
+ }).catch(function (error) {
71
+ if (mutationId === ref.current.mutationId &&
72
+ ref.current.isMounted) {
73
+ var result_2 = {
74
+ loading: false,
75
+ error: error,
76
+ data: void 0,
77
+ called: true,
78
+ client: client,
79
+ };
80
+ if (!equal(ref.current.result, result_2)) {
81
+ setResult(ref.current.result = result_2);
82
+ }
83
+ }
84
+ if (baseOptions.onError) {
85
+ baseOptions.onError(error);
86
+ return { data: void 0, errors: error };
87
+ }
88
+ throw error;
89
+ });
90
+ };
91
+ return ref.current.execute;
92
+ }, [client, mutation, options]);
77
93
  var reset = useCallback(function () {
78
94
  setResult({ called: false, loading: false, client: client });
79
95
  }, []);
@@ -1 +1 @@
1
- {"version":3,"file":"useMutation.js","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":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,EAAE,KAAK;oBACd,KAAK,OAAA;oBACL,IAAI,EAAE,KAAK,CAAC;oBACZ,MAAM,EAAE,IAAI;oBACZ,MAAM,QAAA;iBACP,CAAC;gBAEF,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,EAAE,QAAM,CAAC,EAAE;oBACtC,SAAS,CAAC,GAAG,CAAC,OAAO,CAAC,MAAM,GAAG,QAAM,CAAC,CAAC;iBACxC;aACF;YAED,IAAI,WAAW,CAAC,OAAO,EAAE;gBACvB,WAAW,CAAC,OAAO,CAAC,KAAK,CAAC,CAAC;gBAE3B,OAAO,EAAE,IAAI,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;aACxC;YAED,MAAM,KAAK,CAAC;QACd,CAAC,CAAC,CAAC;IACL,CAAC,EAAE,CAAC,MAAM,EAAE,OAAO,EAAE,QAAQ,CAAC,CAAC,CAAC;IAEhC,IAAM,KAAK,GAAG,WAAW,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;IACvD,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,CAAC,cAAM,OAAA;QACd,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;IAChC,CAAC,EAFe,CAEf,EAAE,EAAE,CAAC,CAAC;IAGP,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 });\n\n const execute = useCallback((\n executeOptions: MutationFunctionOptions<\n TData,\n TVariables,\n TContext,\n TCache\n > = {},\n ) => {\n\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 !baseOptions.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 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) {\n baseOptions.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 }, [client, options, mutation]);\n\n const reset = useCallback(() => {\n setResult({ called: false, loading: false, client });\n }, []);\n\n useEffect(() => () => {\n ref.current.isMounted = false;\n }, []);\n\n\n return [execute, { reset, ...result }];\n}\n"]}
1
+ {"version":3,"file":"useMutation.js","sourceRoot":"","sources":["../../../src/react/hooks/useMutation.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,WAAW,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AAU1E,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,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC9C,IAAA,KAAsB,QAAQ,CAAgC;QAClE,MAAM,EAAE,KAAK;QACb,OAAO,EAAE,KAAK;QACd,MAAM,QAAA;KACP,CAAC,EAJK,MAAM,QAAA,EAAE,SAAS,QAItB,CAAC;IAEH,IAAM,GAAG,GAAG,MAAM,CAAC;QACjB,MAAM,QAAA;QACN,UAAU,EAAE,CAAC;QACb,SAAS,EAAE,IAAI;QACf,OAAO,EAAE,IAAoE;QAC7E,MAAM,QAAA;QACN,QAAQ,UAAA;QACR,OAAO,SAAA;KACR,CAAC,CAAC;IAEH,IAAM,OAAO,GAAG,OAAO,CAAC;QACtB,IACE,GAAG,CAAC,OAAO,CAAC,OAAO,IAAI,IAAI;YAC3B,GAAG,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CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,CAAC;iBACxC;gBAED,MAAM,KAAK,CAAC;YACd,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,OAAO,GAAG,CAAC,OAAO,CAAC,OAAO,CAAC;IAC7B,CAAC,EAAE,CAAC,MAAM,EAAE,QAAQ,EAAE,OAAO,CAAC,CAAC,CAAC;IAEhC,IAAM,KAAK,GAAG,WAAW,CAAC;QACxB,SAAS,CAAC,EAAE,MAAM,EAAE,KAAK,EAAE,OAAO,EAAE,KAAK,EAAE,MAAM,QAAA,EAAE,CAAC,CAAC;IACvD,CAAC,EAAE,EAAE,CAAC,CAAC;IAEP,SAAS,CAAC,cAAM,OAAA;QACd,GAAG,CAAC,OAAO,CAAC,SAAS,GAAG,KAAK,CAAC;IAChC,CAAC,EAFe,CAEf,EAAE,EAAE,CAAC,CAAC;IAGP,OAAO,CAAC,OAAO,aAAI,KAAK,OAAA,IAAK,MAAM,EAAG,CAAC;AACzC,CAAC","sourcesContent":["import { useCallback, useMemo, 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 execute: null as null | MutationTuple<TData, TVariables, TContext, TCache>[0],\n client,\n mutation,\n options,\n });\n\n const execute = useMemo(() => {\n if (\n ref.current.execute != null &&\n ref.current.client === client &&\n equal(options, ref.current.options) &&\n equal(mutation, ref.current.mutation)) {\n return ref.current.execute;\n }\n\n ref.current.client = client;\n ref.current.options = options;\n ref.current.mutation = mutation;\n ref.current.execute = (\n executeOptions: MutationFunctionOptions<\n TData,\n TVariables,\n TContext,\n TCache\n > = {},\n ) => {\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 !baseOptions.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 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) {\n baseOptions.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 return ref.current.execute;\n }, [client, mutation, options]);\n\n const reset = useCallback(() => {\n setResult({ called: false, loading: false, client });\n }, []);\n\n useEffect(() => () => {\n ref.current.isMounted = false;\n }, []);\n\n\n return [execute, { reset, ...result }];\n}\n"]}
@@ -1 +1 @@
1
- {"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGhD,OAAO,EAIL,YAAY,EACZ,iBAAiB,EAElB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,gBAAgB,EAChB,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAKxB,wBAAgB,QAAQ,CACtB,KAAK,GAAG,GAAG,EACX,UAAU,GAAG,kBAAkB,EAE/B,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,GAC5C,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC,CAmShC"}
1
+ {"version":3,"file":"useQuery.d.ts","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":"AAGA,OAAO,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAGhD,OAAO,EAIL,YAAY,EACZ,iBAAiB,EAElB,MAAM,YAAY,CAAC;AACpB,OAAO,EACL,gBAAgB,EAChB,WAAW,EACZ,MAAM,gBAAgB,CAAC;AAKxB,wBAAgB,QAAQ,CACtB,KAAK,GAAG,GAAG,EACX,UAAU,GAAG,kBAAkB,EAE/B,KAAK,EAAE,YAAY,GAAG,iBAAiB,CAAC,KAAK,EAAE,UAAU,CAAC,EAC1D,OAAO,CAAC,EAAE,gBAAgB,CAAC,KAAK,EAAE,UAAU,CAAC,GAC5C,WAAW,CAAC,KAAK,EAAE,UAAU,CAAC,CA0OhC"}
@@ -1,6 +1,7 @@
1
- import { __assign, __rest } from "tslib/tslib.es6.js";
2
- import { useContext, useEffect, useMemo, useRef, useState } from "react/index.js";
3
- import { equal } from "@wry/equality/lib/equality.esm.js";
1
+ import { __assign, __rest } from "tslib";
2
+ import { useContext, useEffect, useMemo, useRef, useState } from 'react';
3
+ import { useSyncExternalStore } from 'use-sync-external-store/shim';
4
+ import { equal } from '@wry/equality';
4
5
  import { getApolloContext } from "../context/index.js";
5
6
  import { ApolloError } from "../../errors/index.js";
6
7
  import { NetworkStatus, } from "../../core/index.js";
@@ -11,6 +12,12 @@ export function useQuery(query, options) {
11
12
  var context = useContext(getApolloContext());
12
13
  var client = useApolloClient(options === null || options === void 0 ? void 0 : options.client);
13
14
  verifyDocumentType(query, DocumentType.Query);
15
+ var ref = useRef({
16
+ client: client,
17
+ query: query,
18
+ options: options,
19
+ watchQueryOptions: createWatchQueryOptions(query, options),
20
+ });
14
21
  var _b = useState(function () {
15
22
  var watchQueryOptions = createWatchQueryOptions(query, options);
16
23
  var obsQuery = null;
@@ -50,114 +57,96 @@ export function useQuery(query, options) {
50
57
  }
51
58
  return obsQuery;
52
59
  }), obsQuery = _b[0], setObsQuery = _b[1];
53
- var _c = useState(function () {
54
- var _a, _b;
55
- var result = obsQuery.getCurrentResult();
56
- if (!result.loading && options) {
57
- if (result.error) {
58
- (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
59
- }
60
- else if (result.data) {
61
- (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, result.data);
62
- }
63
- }
64
- return result;
65
- }), result = _c[0], setResult = _c[1];
66
- var ref = useRef({
67
- client: client,
68
- query: query,
69
- options: options,
70
- result: result,
71
- previousData: void 0,
72
- watchQueryOptions: createWatchQueryOptions(query, options),
73
- });
74
60
  useEffect(function () {
75
- var _a, _b;
76
61
  var watchQueryOptions = createWatchQueryOptions(query, options);
77
- var nextResult;
78
62
  if (ref.current.client !== client || !equal(ref.current.query, query)) {
79
63
  var obsQuery_1 = client.watchQuery(watchQueryOptions);
80
64
  setObsQuery(obsQuery_1);
81
- nextResult = obsQuery_1.getCurrentResult();
82
65
  }
83
66
  else if (!equal(ref.current.watchQueryOptions, watchQueryOptions)) {
84
- obsQuery.setOptions(watchQueryOptions).catch(function () { });
85
- nextResult = obsQuery.getCurrentResult();
86
- ref.current.watchQueryOptions = watchQueryOptions;
67
+ obsQuery.setOptions(watchQueryOptions);
68
+ setObsQuery(obsQuery);
87
69
  }
88
- if (nextResult) {
89
- var previousResult = ref.current.result;
90
- if (previousResult.data) {
91
- ref.current.previousData = previousResult.data;
92
- }
93
- setResult(ref.current.result = nextResult);
94
- if (!nextResult.loading && options) {
95
- if (!result.loading) {
96
- if (result.error) {
97
- (_a = options.onError) === null || _a === void 0 ? void 0 : _a.call(options, result.error);
98
- }
99
- else if (result.data) {
100
- (_b = options.onCompleted) === null || _b === void 0 ? void 0 : _b.call(options, result.data);
101
- }
70
+ Object.assign(ref.current, {
71
+ client: client,
72
+ query: query,
73
+ options: options,
74
+ watchQueryOptions: watchQueryOptions,
75
+ });
76
+ }, [obsQuery, client, query, options]);
77
+ var _c = useMemo(function () {
78
+ var previousResult;
79
+ var subscribe = function (forceUpdate) {
80
+ var subscription = obsQuery.subscribe(forceUpdate, onError);
81
+ function onError(error) {
82
+ forceUpdate();
83
+ subscription.unsubscribe();
84
+ var last = obsQuery["last"];
85
+ obsQuery.resetLastResults();
86
+ obsQuery.subscribe(forceUpdate, onError);
87
+ obsQuery["last"] = last;
88
+ if (!error.hasOwnProperty('graphQLErrors')) {
89
+ throw error;
102
90
  }
103
91
  }
104
- }
105
- Object.assign(ref.current, { client: client, query: query, options: options });
106
- }, [obsQuery, client, query, options]);
107
- useEffect(function () {
108
- if (context.renderPromises) {
109
- return;
110
- }
111
- var subscription = obsQuery.subscribe(onNext, onError);
112
- function onNext() {
113
- var _a, _b;
114
- var previousResult = ref.current.result;
92
+ return function () {
93
+ subscription.unsubscribe();
94
+ };
95
+ };
96
+ var getSnapshot = function () {
115
97
  var result = obsQuery.getCurrentResult();
116
- if (previousResult &&
117
- previousResult.loading === result.loading &&
118
- previousResult.networkStatus === result.networkStatus &&
119
- equal(previousResult.data, result.data)) {
120
- return;
121
- }
122
- if (previousResult.data) {
123
- ref.current.previousData = previousResult.data;
98
+ if (result.errors && result.errors.length) {
99
+ result = __assign(__assign({}, result), { error: result.error || new ApolloError({ graphQLErrors: result.errors }) });
124
100
  }
125
- setResult(ref.current.result = result);
126
- if (!result.loading) {
127
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onCompleted) === null || _b === void 0 ? void 0 : _b.call(_a, result.data);
101
+ if (!previousResult ||
102
+ previousResult.loading !== result.loading ||
103
+ previousResult.networkStatus !== result.networkStatus ||
104
+ !equal(previousResult.data, result.data) ||
105
+ !equal(previousResult.error, result.error)) {
106
+ if (previousResult) {
107
+ result = __assign(__assign({}, result), { previousData: previousResult.data || previousResult.previousData });
108
+ }
109
+ previousResult = result;
128
110
  }
111
+ return previousResult;
112
+ };
113
+ return [subscribe, getSnapshot];
114
+ }, [obsQuery]), subscribe = _c[0], getSnapshot = _c[1];
115
+ var obsQueryMethods = useMemo(function () { return ({
116
+ refetch: obsQuery.refetch.bind(obsQuery),
117
+ fetchMore: obsQuery.fetchMore.bind(obsQuery),
118
+ updateQuery: obsQuery.updateQuery.bind(obsQuery),
119
+ startPolling: obsQuery.startPolling.bind(obsQuery),
120
+ stopPolling: obsQuery.stopPolling.bind(obsQuery),
121
+ subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
122
+ }); }, [obsQuery]);
123
+ var result = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);
124
+ useEffect(function () {
125
+ var _a, _b, _c, _d, _e, _f;
126
+ if (((_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.skip) ||
127
+ ((_b = ref.current.options) === null || _b === void 0 ? void 0 : _b.fetchPolicy) === 'standby') {
128
+ return;
129
129
  }
130
- function onError(error) {
131
- var _a, _b;
132
- var last = obsQuery["last"];
133
- subscription.unsubscribe();
134
- try {
135
- obsQuery.resetLastResults();
136
- subscription = obsQuery.subscribe(onNext, onError);
137
- }
138
- finally {
139
- obsQuery["last"] = last;
140
- }
141
- if (!error.hasOwnProperty('graphQLErrors')) {
142
- throw error;
130
+ if (!result.loading) {
131
+ if (result.error) {
132
+ (_d = (_c = ref.current.options) === null || _c === void 0 ? void 0 : _c.onError) === null || _d === void 0 ? void 0 : _d.call(_c, result.error);
143
133
  }
144
- var previousResult = ref.current.result;
145
- if ((previousResult && previousResult.loading) ||
146
- !equal(error, previousResult.error)) {
147
- setResult(ref.current.result = {
148
- data: previousResult.data,
149
- error: error,
150
- loading: false,
151
- networkStatus: NetworkStatus.error,
152
- });
153
- (_b = (_a = ref.current.options) === null || _a === void 0 ? void 0 : _a.onError) === null || _b === void 0 ? void 0 : _b.call(_a, error);
134
+ else if (result.data) {
135
+ (_f = (_e = ref.current.options) === null || _e === void 0 ? void 0 : _e.onCompleted) === null || _f === void 0 ? void 0 : _f.call(_e, result.data);
154
136
  }
155
137
  }
156
- return function () { return subscription.unsubscribe(); };
157
- }, [obsQuery, context.renderPromises, client.disableNetworkFetches]);
138
+ }, [result]);
158
139
  var partial;
159
140
  (_a = result, partial = _a.partial, result = __rest(_a, ["partial"]));
160
- {
141
+ if ((options === null || options === void 0 ? void 0 : options.skip) || (options === null || options === void 0 ? void 0 : options.fetchPolicy) === 'standby') {
142
+ result = {
143
+ loading: false,
144
+ data: void 0,
145
+ error: void 0,
146
+ networkStatus: NetworkStatus.ready,
147
+ };
148
+ }
149
+ else {
161
150
  if (partial &&
162
151
  (options === null || options === void 0 ? void 0 : options.partialRefetch) &&
163
152
  !result.loading &&
@@ -166,42 +155,12 @@ export function useQuery(query, options) {
166
155
  result = __assign(__assign({}, result), { loading: true, networkStatus: NetworkStatus.refetch });
167
156
  obsQuery.refetch();
168
157
  }
169
- if (context.renderPromises &&
170
- (options === null || options === void 0 ? void 0 : options.ssr) !== false &&
171
- !(options === null || options === void 0 ? void 0 : options.skip) &&
172
- result.loading) {
173
- obsQuery.setOptions(createWatchQueryOptions(query, options)).catch(function () { });
158
+ if (context.renderPromises && (options === null || options === void 0 ? void 0 : options.ssr) !== false && result.loading) {
159
+ obsQuery.setOptions(createWatchQueryOptions(query, options))
160
+ .catch(function () { });
174
161
  }
175
162
  }
176
- if ((context.renderPromises || client.disableNetworkFetches) &&
177
- (options === null || options === void 0 ? void 0 : options.ssr) === false) {
178
- result = ref.current.result = {
179
- loading: true,
180
- data: void 0,
181
- error: void 0,
182
- networkStatus: NetworkStatus.loading,
183
- };
184
- }
185
- else if ((options === null || options === void 0 ? void 0 : options.skip) || (options === null || options === void 0 ? void 0 : options.fetchPolicy) === 'standby') {
186
- result = {
187
- loading: false,
188
- data: void 0,
189
- error: void 0,
190
- networkStatus: NetworkStatus.ready,
191
- };
192
- }
193
- if (result.errors && result.errors.length) {
194
- result = __assign(__assign({}, result), { error: result.error || new ApolloError({ graphQLErrors: result.errors }) });
195
- }
196
- var obsQueryFields = useMemo(function () { return ({
197
- refetch: obsQuery.refetch.bind(obsQuery),
198
- fetchMore: obsQuery.fetchMore.bind(obsQuery),
199
- updateQuery: obsQuery.updateQuery.bind(obsQuery),
200
- startPolling: obsQuery.startPolling.bind(obsQuery),
201
- stopPolling: obsQuery.stopPolling.bind(obsQuery),
202
- subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),
203
- }); }, [obsQuery]);
204
- return __assign(__assign(__assign({}, obsQueryFields), { variables: obsQuery.variables, client: client, called: true, previousData: ref.current.previousData }), result);
163
+ return __assign(__assign(__assign({}, obsQueryMethods), { variables: obsQuery.variables, client: client, called: true }), result);
205
164
  }
206
165
  function createWatchQueryOptions(query, options) {
207
166
  var _a;
@@ -1 +1 @@
1
- {"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,CAAC;AACzE,OAAO,EAAE,KAAK,EAAE,MAAM,eAAe,CAAC;AAEtC,OAAO,EAAE,gBAAgB,EAAE,MAAM,YA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,EACX,OAAO,GAGL,OAAO,QAHF,EACP,WAAW,GAET,OAAO,YAFE,EACR,iBAAiB,UAClB,OAAO,EAPL,wDAOL,CADqB,CACV;IAEZ,IAAI,IAAI,EAAE;QACR,iBAAiB,CAAC,WAAW,GAAG,SAAS,CAAC;KAC3C;SAAM,IACL,CAAA,MAAA,iBAAiB,CAAC,OAAO,0CAAE,cAAc;QACzC,CACE,iBAAiB,CAAC,WAAW,KAAK,cAAc;YAChD,iBAAiB,CAAC,WAAW,KAAK,mBAAmB,CACtD,EACD;QAGA,iBAAiB,CAAC,WAAW,GAAG,aAAa,CAAC;KAC/C;SAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW,EAAE;QAGzC,iBAAiB,CAAC,WAAW,GAAG,aAAa,CAAC;KAC/C;IAED,kBAAS,KAAK,OAAA,IAAK,iBAAiB,EAAG;AACzC,CAAC","sourcesContent":["import { useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport { equal } from '@wry/equality';\nimport { OperationVariables } from '../../core';\nimport { getApolloContext } from '../context';\nimport { ApolloError } from '../../errors';\nimport {\n ApolloQueryResult,\n NetworkStatus,\n ObservableQuery,\n DocumentNode,\n TypedDocumentNode,\n WatchQueryOptions,\n} from '../../core';\nimport {\n QueryHookOptions,\n QueryResult,\n} from '../types/types';\n\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { useApolloClient } from './useApolloClient';\n\nexport function useQuery<\n TData = any,\n TVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: QueryHookOptions<TData, TVariables>,\n): QueryResult<TData, TVariables> {\n const context = useContext(getApolloContext());\n const client = useApolloClient(options?.client);\n verifyDocumentType(query, DocumentType.Query);\n const [obsQuery, setObsQuery] = useState(() => {\n const watchQueryOptions = createWatchQueryOptions(query, options);\n // See if there is an existing observable that was used to fetch the same\n // data and if so, use it instead since it will contain the proper queryId\n // to fetch the result set. This is used during SSR.\n let obsQuery: ObservableQuery<TData, TVariables> | null = null;\n if (context.renderPromises) {\n obsQuery = context.renderPromises.getSSRObservable(watchQueryOptions);\n }\n\n if (!obsQuery) {\n // Is it safe (StrictMode/memory-wise) to call client.watchQuery here?\n obsQuery = client.watchQuery(watchQueryOptions);\n if (context.renderPromises) {\n context.renderPromises.registerSSRObservable(\n obsQuery,\n watchQueryOptions,\n );\n }\n }\n\n if (\n context.renderPromises &&\n options?.ssr !== false &&\n !options?.skip &&\n obsQuery.getCurrentResult().loading\n ) {\n // TODO: This is a legacy API which could probably be cleaned up\n context.renderPromises.addQueryPromise(\n {\n // The only options which seem to actually be used by the\n // RenderPromises class are query and variables.\n getOptions: () => createWatchQueryOptions(query, options),\n fetchData: () => new Promise<void>((resolve) => {\n const sub = obsQuery!.subscribe({\n next(result) {\n if (!result.loading) {\n resolve()\n sub.unsubscribe();\n }\n },\n error() {\n resolve();\n sub.unsubscribe();\n },\n complete() {\n resolve();\n },\n });\n }),\n },\n // This callback never seemed to do anything\n () => null,\n );\n }\n\n return obsQuery;\n });\n\n let [result, setResult] = useState(() => {\n const result = obsQuery.getCurrentResult();\n if (!result.loading && options) {\n if (result.error) {\n options.onError?.(result.error);\n } else if (result.data) {\n options.onCompleted?.(result.data);\n }\n }\n\n return result;\n });\n\n const ref = useRef({\n client,\n query,\n options,\n result,\n previousData: void 0 as TData | undefined,\n watchQueryOptions: createWatchQueryOptions(query, options),\n });\n\n // An effect to recreate the obsQuery whenever the client or query changes.\n // This effect is also responsible for checking and updating the obsQuery\n // options whenever they change.\n useEffect(() => {\n const watchQueryOptions = createWatchQueryOptions(query, options);\n let nextResult: ApolloQueryResult<TData> | undefined;\n if (ref.current.client !== client || !equal(ref.current.query, query)) {\n const obsQuery = client.watchQuery(watchQueryOptions);\n setObsQuery(obsQuery);\n nextResult = obsQuery.getCurrentResult();\n } else if (!equal(ref.current.watchQueryOptions, watchQueryOptions)) {\n obsQuery.setOptions(watchQueryOptions).catch(() => {});\n nextResult = obsQuery.getCurrentResult();\n ref.current.watchQueryOptions = watchQueryOptions;\n }\n\n if (nextResult) {\n const previousResult = ref.current.result;\n if (previousResult.data) {\n ref.current.previousData = previousResult.data;\n }\n\n setResult(ref.current.result = nextResult);\n if (!nextResult.loading && options) {\n if (!result.loading) {\n if (result.error) {\n options.onError?.(result.error);\n } else if (result.data) {\n options.onCompleted?.(result.data);\n }\n }\n }\n }\n\n Object.assign(ref.current, { client, query, options });\n }, [obsQuery, client, query, options]);\n\n // An effect to subscribe to the current observable query\n useEffect(() => {\n if (context.renderPromises) {\n return;\n }\n\n let subscription = obsQuery.subscribe(onNext, onError);\n // We use `getCurrentResult()` instead of the callback argument because\n // the values differ slightly. Specifically, loading results will have\n // an empty object for data instead of `undefined` for some reason.\n function onNext() {\n const previousResult = ref.current.result;\n const result = obsQuery.getCurrentResult();\n // Make sure we're not attempting to re-render similar results\n if (\n previousResult &&\n previousResult.loading === result.loading &&\n previousResult.networkStatus === result.networkStatus &&\n equal(previousResult.data, result.data)\n ) {\n return;\n }\n\n if (previousResult.data) {\n ref.current.previousData = previousResult.data;\n }\n\n setResult(ref.current.result = result);\n if (!result.loading) {\n ref.current.options?.onCompleted?.(result.data);\n }\n }\n\n function onError(error: Error) {\n const last = obsQuery[\"last\"];\n subscription.unsubscribe();\n // Unfortunately, if `lastError` is set in the current\n // `observableQuery` when the subscription is re-created,\n // the subscription will immediately receive the error, which will\n // cause it to terminate again. To avoid this, we first clear\n // the last error/result from the `observableQuery` before re-starting\n // the subscription, and restore it afterwards (so the subscription\n // has a chance to stay open).\n try {\n obsQuery.resetLastResults();\n subscription = obsQuery.subscribe(onNext, onError);\n } finally {\n obsQuery[\"last\"] = last;\n }\n\n if (!error.hasOwnProperty('graphQLErrors')) {\n // The error is not a GraphQL error\n throw error;\n }\n\n const previousResult = ref.current.result;\n if (\n (previousResult && previousResult.loading) ||\n !equal(error, previousResult.error)\n ) {\n setResult(ref.current.result = {\n data: previousResult.data,\n error: error as ApolloError,\n loading: false,\n networkStatus: NetworkStatus.error,\n });\n ref.current.options?.onError?.(error as ApolloError);\n }\n }\n\n return () => subscription.unsubscribe();\n }, [obsQuery, context.renderPromises, client.disableNetworkFetches]);\n\n let partial: boolean | undefined;\n ({ partial, ...result } = result);\n\n {\n // BAD BOY CODE BLOCK WHERE WE PUT SIDE-EFFECTS IN THE RENDER FUNCTION\n //\n // TODO: This code should be removed when the partialRefetch option is\n // removed. I was unable to get this hook to behave reasonably in certain\n // edge cases when this block was put in an effect.\n if (\n partial &&\n options?.partialRefetch &&\n !result.loading &&\n (!result.data || Object.keys(result.data).length === 0) &&\n obsQuery.options.fetchPolicy !== 'cache-only'\n ) {\n result = {\n ...result,\n loading: true,\n networkStatus: NetworkStatus.refetch,\n };\n\n obsQuery.refetch();\n }\n\n // TODO: This is a hack to make sure useLazyQuery executions update the\n // obsevable query options for ssr.\n if (\n context.renderPromises &&\n options?.ssr !== false &&\n !options?.skip &&\n result.loading\n ) {\n obsQuery.setOptions(createWatchQueryOptions(query, options)).catch(() => {});\n }\n }\n\n if (\n (context.renderPromises || client.disableNetworkFetches) &&\n options?.ssr === false\n ) {\n // If SSR has been explicitly disabled, and this function has been called\n // on the server side, return the default loading state.\n result = ref.current.result = {\n loading: true,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.loading,\n };\n } else if (options?.skip || options?.fetchPolicy === 'standby') {\n // When skipping a query (ie. we're not querying for data but still want to\n // render children), make sure the `data` is cleared out and `loading` is\n // set to `false` (since we aren't loading anything).\n //\n // NOTE: We no longer think this is the correct behavior. Skipping should\n // not automatically set `data` to `undefined`, but instead leave the\n // previous data in place. In other words, skipping should not mandate that\n // previously received data is all of a sudden removed. Unfortunately,\n // changing this is breaking, so we'll have to wait until Apollo Client 4.0\n // to address this.\n result = {\n loading: false,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.ready,\n };\n }\n\n if (result.errors && result.errors.length) {\n // Until a set naming convention for networkError and graphQLErrors is\n // decided upon, we map errors (graphQLErrors) to the error options.\n // TODO: Is it possible for both result.error and result.errors to be\n // defined here?\n result = {\n ...result,\n error: result.error || new ApolloError({ graphQLErrors: result.errors }),\n };\n }\n\n const obsQueryFields = useMemo(() => ({\n refetch: obsQuery.refetch.bind(obsQuery),\n fetchMore: obsQuery.fetchMore.bind(obsQuery),\n updateQuery: obsQuery.updateQuery.bind(obsQuery),\n startPolling: obsQuery.startPolling.bind(obsQuery),\n stopPolling: obsQuery.stopPolling.bind(obsQuery),\n subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),\n }), [obsQuery]);\n\n return {\n ...obsQueryFields,\n variables: obsQuery.variables,\n client,\n called: true,\n previousData: ref.current.previousData,\n ...result,\n };\n}\n\nfunction createWatchQueryOptions<TData, TVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<TData, TVariables> = {},\n): WatchQueryOptions<TVariables, TData> {\n // TODO: For some reason, we pass context, which is the React Apollo Context,\n // into observable queries, and test for that.\n // removing hook specific options\n const {\n skip,\n ssr,\n onCompleted,\n onError,\n displayName,\n ...watchQueryOptions\n } = options;\n\n if (skip) {\n watchQueryOptions.fetchPolicy = 'standby';\n } else if (\n watchQueryOptions.context?.renderPromises &&\n (\n watchQueryOptions.fetchPolicy === 'network-only' ||\n watchQueryOptions.fetchPolicy === 'cache-and-network'\n )\n ) {\n // this behavior was added to react-apollo without explanation in this PR\n // https://github.com/apollographql/react-apollo/pull/1579\n watchQueryOptions.fetchPolicy = 'cache-first';\n } else if (!watchQueryOptions.fetchPolicy) {\n // cache-first is the default policy, but we explicitly assign it here so\n // the cache policies computed based on options can be cleared\n watchQueryOptions.fetchPolicy = 'cache-first';\n }\n\n return { query, ...watchQueryOptions };\n}\n"]}
1
+ {"version":3,"file":"useQuery.js","sourceRoot":"","sources":["../../../src/react/hooks/useQuery.ts"],"names":[],"mappings":";AAAA,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,OAAO,EAAE,MAAM,EAAE,QAAQ,EAAE,MAAM,OAAO,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AK,cAAc;YAChD,iBAAiB,CAAC,WAAW,KAAK,mBAAmB,CACtD,EACD;QAGA,iBAAiB,CAAC,WAAW,GAAG,aAAa,CAAC;KAC/C;SAAM,IAAI,CAAC,iBAAiB,CAAC,WAAW,EAAE;QAGzC,iBAAiB,CAAC,WAAW,GAAG,aAAa,CAAC;KAC/C;IAED,kBAAS,KAAK,OAAA,IAAK,iBAAiB,EAAG;AACzC,CAAC","sourcesContent":["import { useContext, useEffect, useMemo, useRef, useState } from 'react';\nimport { useSyncExternalStore } from 'use-sync-external-store/shim';\nimport { equal } from '@wry/equality';\nimport { OperationVariables } from '../../core';\nimport { getApolloContext } from '../context';\nimport { ApolloError } from '../../errors';\nimport {\n ApolloQueryResult,\n NetworkStatus,\n ObservableQuery,\n DocumentNode,\n TypedDocumentNode,\n WatchQueryOptions,\n} from '../../core';\nimport {\n QueryHookOptions,\n QueryResult,\n} from '../types/types';\n\nimport { DocumentType, verifyDocumentType } from '../parser';\nimport { useApolloClient } from './useApolloClient';\n\nexport function useQuery<\n TData = any,\n TVariables = OperationVariables,\n>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options?: QueryHookOptions<TData, TVariables>,\n): QueryResult<TData, TVariables> {\n const context = useContext(getApolloContext());\n const client = useApolloClient(options?.client);\n verifyDocumentType(query, DocumentType.Query);\n const ref = useRef({\n client,\n query,\n options,\n watchQueryOptions: createWatchQueryOptions(query, options),\n });\n\n const [obsQuery, setObsQuery] = useState(() => {\n const watchQueryOptions = createWatchQueryOptions(query, options);\n // See if there is an existing observable that was used to fetch the same\n // data and if so, use it instead since it will contain the proper queryId\n // to fetch the result set. This is used during SSR.\n let obsQuery: ObservableQuery<TData, TVariables> | null = null;\n if (context.renderPromises) {\n obsQuery = context.renderPromises.getSSRObservable(watchQueryOptions);\n }\n\n if (!obsQuery) {\n // Is it safe (StrictMode/memory-wise) to call client.watchQuery here?\n obsQuery = client.watchQuery(watchQueryOptions);\n if (context.renderPromises) {\n context.renderPromises.registerSSRObservable(\n obsQuery,\n watchQueryOptions,\n );\n }\n }\n\n if (\n context.renderPromises &&\n options?.ssr !== false &&\n !options?.skip &&\n obsQuery.getCurrentResult().loading\n ) {\n // TODO: This is a legacy API which could probably be cleaned up\n context.renderPromises.addQueryPromise(\n {\n // The only options which seem to actually be used by the\n // RenderPromises class are query and variables.\n getOptions: () => createWatchQueryOptions(query, options),\n fetchData: () => new Promise<void>((resolve) => {\n const sub = obsQuery!.subscribe({\n next(result) {\n if (!result.loading) {\n resolve()\n sub.unsubscribe();\n }\n },\n error() {\n resolve();\n sub.unsubscribe();\n },\n complete() {\n // TODO: Does this branch ever get called before next() and error()?\n resolve();\n },\n });\n }),\n },\n // This callback never seemed to do anything\n () => null,\n );\n }\n\n return obsQuery;\n });\n\n // An effect to recreate the obsQuery whenever the client or query changes.\n // This effect is also responsible for updating the obsQuery options whenever\n // they change.\n useEffect(() => {\n const watchQueryOptions = createWatchQueryOptions(query, options);\n if (ref.current.client !== client || !equal(ref.current.query, query)) {\n const obsQuery = client.watchQuery(watchQueryOptions);\n setObsQuery(obsQuery);\n } else if (!equal(ref.current.watchQueryOptions, watchQueryOptions)) {\n obsQuery.setOptions(watchQueryOptions);\n // We call setObsQuery to rerender the hook.\n setObsQuery(obsQuery);\n }\n\n Object.assign(ref.current, {\n client,\n query,\n options,\n watchQueryOptions,\n });\n }, [obsQuery, client, query, options]);\n\n const [subscribe, getSnapshot] = useMemo(() => {\n let previousResult: ApolloQueryResult<TData> | undefined;\n const subscribe = (forceUpdate: () => void) => {\n let subscription = obsQuery.subscribe(forceUpdate, onError);\n function onError(error: Error) {\n forceUpdate();\n subscription.unsubscribe();\n const last = obsQuery[\"last\"];\n obsQuery.resetLastResults();\n obsQuery.subscribe(forceUpdate, onError);\n obsQuery[\"last\"] = last;\n if (!error.hasOwnProperty('graphQLErrors')) {\n // The error is not a GraphQL error\n throw error;\n }\n }\n\n return () => {\n subscription.unsubscribe();\n };\n };\n\n const getSnapshot = () => {\n let result = obsQuery.getCurrentResult();\n if (result.errors && result.errors.length) {\n // Until a set naming convention for networkError and graphQLErrors is\n // decided upon, we map errors (graphQLErrors) to the error options.\n // TODO: Is it possible for both result.error and result.errors to be\n // defined here?\n result = {\n ...result,\n error:\n result.error || new ApolloError({ graphQLErrors: result.errors }),\n };\n }\n\n if (\n !previousResult ||\n previousResult.loading !== result.loading ||\n previousResult.networkStatus !== result.networkStatus ||\n !equal(previousResult.data, result.data) ||\n !equal(previousResult.error, result.error)\n ) {\n if (previousResult) {\n result = {\n ...result,\n previousData: previousResult.data || (previousResult as any).previousData,\n } as ApolloQueryResult<TData>;\n }\n\n previousResult = result;\n }\n\n return previousResult;\n };\n\n return [subscribe, getSnapshot];\n }, [obsQuery]);\n\n const obsQueryMethods = useMemo(() => ({\n refetch: obsQuery.refetch.bind(obsQuery),\n fetchMore: obsQuery.fetchMore.bind(obsQuery),\n updateQuery: obsQuery.updateQuery.bind(obsQuery),\n startPolling: obsQuery.startPolling.bind(obsQuery),\n stopPolling: obsQuery.stopPolling.bind(obsQuery),\n subscribeToMore: obsQuery.subscribeToMore.bind(obsQuery),\n }), [obsQuery]);\n\n let result = useSyncExternalStore(subscribe, getSnapshot, getSnapshot);\n useEffect(() => {\n if (\n ref.current.options?.skip ||\n ref.current.options?.fetchPolicy === 'standby'\n ) {\n return;\n }\n\n if (!result.loading) {\n if (result.error) {\n ref.current.options?.onError?.(result.error);\n } else if (result.data) {\n ref.current.options?.onCompleted?.(result.data);\n }\n }\n }, [result]);\n\n let partial: boolean | undefined;\n ({ partial, ...result } = result);\n if (options?.skip || options?.fetchPolicy === 'standby') {\n // When skipping a query (ie. we're not querying for data but still want to\n // render children), make sure the `data` is cleared out and `loading` is\n // set to `false` (since we aren't loading anything).\n //\n // NOTE: We no longer think this is the correct behavior. Skipping should\n // not automatically set `data` to `undefined`, but instead leave the\n // previous data in place. In other words, skipping should not mandate that\n // previously received data is all of a sudden removed. Unfortunately,\n // changing this is breaking, so we'll have to wait until Apollo Client 4.0\n // to address this.\n result = {\n loading: false,\n data: void 0 as unknown as TData,\n error: void 0,\n networkStatus: NetworkStatus.ready,\n };\n } else {\n // BAD BOY CODE BLOCK WHERE WE PUT SIDE-EFFECTS IN THE RENDER FUNCTION\n // TODO: This code should be removed when the partialRefetch option is\n // removed. I was unable to get this hook to behave reasonably in certain\n // edge cases when this block was put in an effect.\n if (\n partial &&\n options?.partialRefetch &&\n !result.loading &&\n (!result.data || Object.keys(result.data).length === 0) &&\n obsQuery.options.fetchPolicy !== 'cache-only'\n ) {\n result = {\n ...result,\n loading: true,\n networkStatus: NetworkStatus.refetch,\n };\n\n obsQuery.refetch();\n }\n\n // TODO: This is a hack to make sure useLazyQuery executions update the\n // obsevable query options for ssr.\n if (context.renderPromises && options?.ssr !== false && result.loading) {\n obsQuery.setOptions(createWatchQueryOptions(query, options))\n .catch(() => {});\n }\n }\n\n return {\n ...obsQueryMethods,\n variables: obsQuery.variables,\n client,\n called: true,\n ...result,\n };\n}\n\nfunction createWatchQueryOptions<TData, TVariables>(\n query: DocumentNode | TypedDocumentNode<TData, TVariables>,\n options: QueryHookOptions<TData, TVariables> = {},\n): WatchQueryOptions<TVariables, TData> {\n // Using destructuring to remove hook specific options.\n const {\n skip,\n ssr,\n onCompleted,\n onError,\n displayName,\n ...watchQueryOptions\n } = options;\n // TODO: For some reason, we pass context, which is the React Apollo Context,\n // into observable queries, and test for that.\n\n if (skip) {\n watchQueryOptions.fetchPolicy = 'standby';\n } else if (\n watchQueryOptions.context?.renderPromises &&\n (\n watchQueryOptions.fetchPolicy === 'network-only' ||\n watchQueryOptions.fetchPolicy === 'cache-and-network'\n )\n ) {\n // this behavior was added to react-apollo without explanation in this PR\n // https://github.com/apollographql/react-apollo/pull/1579\n watchQueryOptions.fetchPolicy = 'cache-first';\n } else if (!watchQueryOptions.fetchPolicy) {\n // cache-first is the default policy, but we explicitly assign it here so\n // the cache policies computed based on options can be cleared\n watchQueryOptions.fetchPolicy = 'cache-first';\n }\n\n return { query, ...watchQueryOptions };\n}\n"]}
@@ -1,4 +1,4 @@
1
- import { useEffect, useState } from "react/index.js";
1
+ import { useEffect, useState } from 'react';
2
2
  export function useReactiveVar(rv) {
3
3
  var value = rv();
4
4
  var setValue = useState(value)[1];
@@ -1,6 +1,6 @@
1
1
  import "../../utilities/globals/index.js";
2
- import { useState, useRef, useEffect } from "react/index.js";
3
- import { equal } from "@wry/equality/lib/equality.esm.js";
2
+ import { useState, useRef, useEffect } from 'react';
3
+ import { equal } from '@wry/equality';
4
4
  import { DocumentType, verifyDocumentType } from "../parser/index.js";
5
5
  import { useApolloClient } from "./useApolloClient.js";
6
6
  export function useSubscription(subscription, options) {
@@ -10,8 +10,8 @@ export declare class RenderPromises {
10
10
  private queryInfoTrie;
11
11
  private stopped;
12
12
  stop(): void;
13
- registerSSRObservable<TData, TVariables>(observable: ObservableQuery<any, TVariables>, props: QueryDataOptions<TData, TVariables>): void;
14
- getSSRObservable<TData, TVariables>(props: QueryDataOptions<TData, TVariables>): ObservableQuery<any, TVariables> | null;
13
+ registerSSRObservable<TData, TVariables>(observable: ObservableQuery<any, TVariables>, options: QueryDataOptions<TData, TVariables>): void;
14
+ getSSRObservable<TData, TVariables>(options: QueryDataOptions<TData, TVariables>): ObservableQuery<any, TVariables> | null;
15
15
  addQueryPromise(queryInstance: QueryData, finish: () => React.ReactNode): React.ReactNode;
16
16
  hasPromises(): boolean;
17
17
  consumeAndAwaitPromises(): Promise<any[]>;
@@ -1 +1 @@
1
- {"version":3,"file":"RenderPromises.d.ts","sourceRoot":"","sources":["../../../src/react/ssr/RenderPromises.ts"],"names":[],"mappings":";AAEA,OAAO,EAAE,eAAe,EAAE,MAAM,YAAY,CAAC;AAC7C,OAAO,EAAE,gBAAgB,EAAE,MAAM,gBAAgB,CAAC;AAIlD,UAAU,SAAS;IACjB,UAAU,IAAI,GAAG,CAAC;IAClB,SAAS,IAAI,OAAO,CAAC,IAAI,CAAC,CAAC;CAC5B;AAcD,qBAAa,cAAc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