@graphitation/apollo-react-relay-duct-tape 0.7.3 → 1.0.0-alpha.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 (202) hide show
  1. package/CHANGELOG.md +13 -2
  2. package/README.md +122 -0
  3. package/graphitation-apollo-react-relay-duct-tape-0.5.0-store-observation.8.tgz +0 -0
  4. package/lib/convertFetchPolicy.d.ts +9 -0
  5. package/lib/convertFetchPolicy.d.ts.map +1 -0
  6. package/lib/convertFetchPolicy.js +20 -0
  7. package/lib/convertFetchPolicy.js.map +7 -0
  8. package/lib/convertFetchPolicy.mjs +14 -0
  9. package/lib/convertFetchPolicy.mjs.map +7 -0
  10. package/lib/hooks.d.ts +15 -5
  11. package/lib/hooks.d.ts.map +1 -1
  12. package/lib/hooks.js +28 -3
  13. package/lib/hooks.js.map +7 -0
  14. package/lib/hooks.mjs +33 -3
  15. package/lib/hooks.mjs.map +7 -0
  16. package/lib/index.d.ts +1 -0
  17. package/lib/index.d.ts.map +1 -1
  18. package/lib/index.js +1 -0
  19. package/lib/index.js.map +7 -0
  20. package/lib/index.mjs +1 -0
  21. package/lib/index.mjs.map +7 -0
  22. package/lib/storeObservation/__generated__/compiledHooks_BackwardPaginationFragment.graphql.d.ts +18 -0
  23. package/lib/storeObservation/__generated__/compiledHooks_BackwardPaginationFragment.graphql.d.ts.map +1 -0
  24. package/lib/storeObservation/__generated__/compiledHooks_BackwardPaginationFragment.graphql.js +4 -0
  25. package/lib/storeObservation/__generated__/compiledHooks_BackwardPaginationFragment.graphql.js.map +7 -0
  26. package/lib/storeObservation/__generated__/compiledHooks_BackwardPaginationFragment.graphql.mjs +0 -0
  27. package/lib/storeObservation/__generated__/compiledHooks_BackwardPaginationFragment.graphql.mjs.map +7 -0
  28. package/lib/storeObservation/__generated__/compiledHooks_BackwardPaginationFragment_PaginationQuery.graphql.d.ts +17 -0
  29. package/lib/storeObservation/__generated__/compiledHooks_BackwardPaginationFragment_PaginationQuery.graphql.d.ts.map +1 -0
  30. package/lib/storeObservation/__generated__/compiledHooks_BackwardPaginationFragment_PaginationQuery.graphql.js +654 -0
  31. package/lib/storeObservation/__generated__/compiledHooks_BackwardPaginationFragment_PaginationQuery.graphql.js.map +7 -0
  32. package/lib/storeObservation/__generated__/compiledHooks_BackwardPaginationFragment_PaginationQuery.graphql.mjs +647 -0
  33. package/lib/storeObservation/__generated__/compiledHooks_BackwardPaginationFragment_PaginationQuery.graphql.mjs.map +7 -0
  34. package/lib/storeObservation/__generated__/compiledHooks_ChildFragment.graphql.d.ts +11 -0
  35. package/lib/storeObservation/__generated__/compiledHooks_ChildFragment.graphql.d.ts.map +1 -0
  36. package/lib/storeObservation/__generated__/compiledHooks_ChildFragment.graphql.js +4 -0
  37. package/lib/storeObservation/__generated__/compiledHooks_ChildFragment.graphql.js.map +7 -0
  38. package/lib/storeObservation/__generated__/compiledHooks_ChildFragment.graphql.mjs +0 -0
  39. package/lib/storeObservation/__generated__/compiledHooks_ChildFragment.graphql.mjs.map +7 -0
  40. package/lib/storeObservation/__generated__/compiledHooks_ChildWatchNodeQuery.graphql.d.ts +2 -0
  41. package/lib/storeObservation/__generated__/compiledHooks_ChildWatchNodeQuery.graphql.d.ts.map +1 -0
  42. package/lib/storeObservation/__generated__/compiledHooks_ChildWatchNodeQuery.graphql.js +173 -0
  43. package/lib/storeObservation/__generated__/compiledHooks_ChildWatchNodeQuery.graphql.js.map +7 -0
  44. package/lib/storeObservation/__generated__/compiledHooks_ChildWatchNodeQuery.graphql.mjs +166 -0
  45. package/lib/storeObservation/__generated__/compiledHooks_ChildWatchNodeQuery.graphql.mjs.map +7 -0
  46. package/lib/storeObservation/__generated__/compiledHooks_ForwardPaginationFragment.graphql.d.ts +21 -0
  47. package/lib/storeObservation/__generated__/compiledHooks_ForwardPaginationFragment.graphql.d.ts.map +1 -0
  48. package/lib/storeObservation/__generated__/compiledHooks_ForwardPaginationFragment.graphql.js +4 -0
  49. package/lib/storeObservation/__generated__/compiledHooks_ForwardPaginationFragment.graphql.js.map +7 -0
  50. package/lib/storeObservation/__generated__/compiledHooks_ForwardPaginationFragment.graphql.mjs +0 -0
  51. package/lib/storeObservation/__generated__/compiledHooks_ForwardPaginationFragment.graphql.mjs.map +7 -0
  52. package/lib/storeObservation/__generated__/compiledHooks_ForwardPaginationFragment_PaginationQuery.graphql.d.ts +20 -0
  53. package/lib/storeObservation/__generated__/compiledHooks_ForwardPaginationFragment_PaginationQuery.graphql.d.ts.map +1 -0
  54. package/lib/storeObservation/__generated__/compiledHooks_ForwardPaginationFragment_PaginationQuery.graphql.js +1059 -0
  55. package/lib/storeObservation/__generated__/compiledHooks_ForwardPaginationFragment_PaginationQuery.graphql.js.map +7 -0
  56. package/lib/storeObservation/__generated__/compiledHooks_ForwardPaginationFragment_PaginationQuery.graphql.mjs +1052 -0
  57. package/lib/storeObservation/__generated__/compiledHooks_ForwardPaginationFragment_PaginationQuery.graphql.mjs.map +7 -0
  58. package/lib/storeObservation/__generated__/compiledHooks_QueryTypeFragment.graphql.d.ts +13 -0
  59. package/lib/storeObservation/__generated__/compiledHooks_QueryTypeFragment.graphql.d.ts.map +1 -0
  60. package/lib/storeObservation/__generated__/compiledHooks_QueryTypeFragment.graphql.js +4 -0
  61. package/lib/storeObservation/__generated__/compiledHooks_QueryTypeFragment.graphql.js.map +7 -0
  62. package/lib/storeObservation/__generated__/compiledHooks_QueryTypeFragment.graphql.mjs +0 -0
  63. package/lib/storeObservation/__generated__/compiledHooks_QueryTypeFragment.graphql.mjs.map +7 -0
  64. package/lib/storeObservation/__generated__/compiledHooks_QueryTypeWatchNodeQuery.graphql.d.ts +2 -0
  65. package/lib/storeObservation/__generated__/compiledHooks_QueryTypeWatchNodeQuery.graphql.d.ts.map +1 -0
  66. package/lib/storeObservation/__generated__/compiledHooks_QueryTypeWatchNodeQuery.graphql.js +98 -0
  67. package/lib/storeObservation/__generated__/compiledHooks_QueryTypeWatchNodeQuery.graphql.js.map +7 -0
  68. package/lib/storeObservation/__generated__/compiledHooks_QueryTypeWatchNodeQuery.graphql.mjs +91 -0
  69. package/lib/storeObservation/__generated__/compiledHooks_QueryTypeWatchNodeQuery.graphql.mjs.map +7 -0
  70. package/lib/storeObservation/__generated__/compiledHooks_RefetchableFragment.graphql.d.ts +13 -0
  71. package/lib/storeObservation/__generated__/compiledHooks_RefetchableFragment.graphql.d.ts.map +1 -0
  72. package/lib/storeObservation/__generated__/compiledHooks_RefetchableFragment.graphql.js +4 -0
  73. package/lib/storeObservation/__generated__/compiledHooks_RefetchableFragment.graphql.js.map +7 -0
  74. package/lib/storeObservation/__generated__/compiledHooks_RefetchableFragment.graphql.mjs +0 -0
  75. package/lib/storeObservation/__generated__/compiledHooks_RefetchableFragment.graphql.mjs.map +7 -0
  76. package/lib/storeObservation/__generated__/compiledHooks_RefetchableFragment_RefetchQuery.graphql.d.ts +16 -0
  77. package/lib/storeObservation/__generated__/compiledHooks_RefetchableFragment_RefetchQuery.graphql.d.ts.map +1 -0
  78. package/lib/storeObservation/__generated__/compiledHooks_RefetchableFragment_RefetchQuery.graphql.js +381 -0
  79. package/lib/storeObservation/__generated__/compiledHooks_RefetchableFragment_RefetchQuery.graphql.js.map +7 -0
  80. package/lib/storeObservation/__generated__/compiledHooks_RefetchableFragment_RefetchQuery.graphql.mjs +374 -0
  81. package/lib/storeObservation/__generated__/compiledHooks_RefetchableFragment_RefetchQuery.graphql.mjs.map +7 -0
  82. package/lib/storeObservation/__generated__/compiledHooks_Root_executionQuery.graphql.d.ts +20 -0
  83. package/lib/storeObservation/__generated__/compiledHooks_Root_executionQuery.graphql.d.ts.map +1 -0
  84. package/lib/storeObservation/__generated__/compiledHooks_Root_executionQuery.graphql.js +871 -0
  85. package/lib/storeObservation/__generated__/compiledHooks_Root_executionQuery.graphql.js.map +7 -0
  86. package/lib/storeObservation/__generated__/compiledHooks_Root_executionQuery.graphql.mjs +864 -0
  87. package/lib/storeObservation/__generated__/compiledHooks_Root_executionQuery.graphql.mjs.map +7 -0
  88. package/lib/storeObservation/compiledHooks/index.d.ts +7 -0
  89. package/lib/storeObservation/compiledHooks/index.d.ts.map +1 -0
  90. package/lib/storeObservation/compiledHooks/index.js +33 -0
  91. package/lib/storeObservation/compiledHooks/index.js.map +7 -0
  92. package/lib/storeObservation/compiledHooks/index.mjs +11 -0
  93. package/lib/storeObservation/compiledHooks/index.mjs.map +7 -0
  94. package/lib/storeObservation/compiledHooks/types.d.ts +15 -0
  95. package/lib/storeObservation/compiledHooks/types.d.ts.map +1 -0
  96. package/lib/storeObservation/compiledHooks/types.js +3 -0
  97. package/lib/storeObservation/compiledHooks/types.js.map +7 -0
  98. package/lib/storeObservation/compiledHooks/types.mjs +0 -0
  99. package/lib/storeObservation/compiledHooks/types.mjs.map +7 -0
  100. package/lib/storeObservation/compiledHooks/useCompiledFragment.d.ts +9 -0
  101. package/lib/storeObservation/compiledHooks/useCompiledFragment.d.ts.map +1 -0
  102. package/lib/storeObservation/compiledHooks/useCompiledFragment.js +80 -0
  103. package/lib/storeObservation/compiledHooks/useCompiledFragment.js.map +7 -0
  104. package/lib/storeObservation/compiledHooks/useCompiledFragment.mjs +61 -0
  105. package/lib/storeObservation/compiledHooks/useCompiledFragment.mjs.map +7 -0
  106. package/lib/storeObservation/compiledHooks/useCompiledLazyLoadQuery.d.ts +16 -0
  107. package/lib/storeObservation/compiledHooks/useCompiledLazyLoadQuery.d.ts.map +1 -0
  108. package/lib/storeObservation/compiledHooks/useCompiledLazyLoadQuery.js +92 -0
  109. package/lib/storeObservation/compiledHooks/useCompiledLazyLoadQuery.js.map +7 -0
  110. package/lib/storeObservation/compiledHooks/useCompiledLazyLoadQuery.mjs +73 -0
  111. package/lib/storeObservation/compiledHooks/useCompiledLazyLoadQuery.mjs.map +7 -0
  112. package/lib/storeObservation/compiledHooks/useCompiledPaginationFragment.d.ts +15 -0
  113. package/lib/storeObservation/compiledHooks/useCompiledPaginationFragment.d.ts.map +1 -0
  114. package/lib/storeObservation/compiledHooks/useCompiledPaginationFragment.js +176 -0
  115. package/lib/storeObservation/compiledHooks/useCompiledPaginationFragment.js.map +7 -0
  116. package/lib/storeObservation/compiledHooks/useCompiledPaginationFragment.mjs +157 -0
  117. package/lib/storeObservation/compiledHooks/useCompiledPaginationFragment.mjs.map +7 -0
  118. package/lib/storeObservation/compiledHooks/useCompiledRefetchableFragment.d.ts +23 -0
  119. package/lib/storeObservation/compiledHooks/useCompiledRefetchableFragment.d.ts.map +1 -0
  120. package/lib/storeObservation/compiledHooks/useCompiledRefetchableFragment.js +131 -0
  121. package/lib/storeObservation/compiledHooks/useCompiledRefetchableFragment.js.map +7 -0
  122. package/lib/storeObservation/compiledHooks/useCompiledRefetchableFragment.mjs +112 -0
  123. package/lib/storeObservation/compiledHooks/useCompiledRefetchableFragment.mjs.map +7 -0
  124. package/lib/storeObservation/compiledHooks/useDeepCompareMemoize.d.ts +12 -0
  125. package/lib/storeObservation/compiledHooks/useDeepCompareMemoize.d.ts.map +1 -0
  126. package/lib/storeObservation/compiledHooks/useDeepCompareMemoize.js +37 -0
  127. package/lib/storeObservation/compiledHooks/useDeepCompareMemoize.js.map +7 -0
  128. package/lib/storeObservation/compiledHooks/useDeepCompareMemoize.mjs +15 -0
  129. package/lib/storeObservation/compiledHooks/useDeepCompareMemoize.mjs.map +7 -0
  130. package/lib/storeObservation/compiledHooks/useForceUpdate.d.ts +3 -0
  131. package/lib/storeObservation/compiledHooks/useForceUpdate.d.ts.map +1 -0
  132. package/lib/storeObservation/compiledHooks/useForceUpdate.js +31 -0
  133. package/lib/storeObservation/compiledHooks/useForceUpdate.js.map +7 -0
  134. package/lib/storeObservation/compiledHooks/useForceUpdate.mjs +9 -0
  135. package/lib/storeObservation/compiledHooks/useForceUpdate.mjs.map +7 -0
  136. package/lib/storeObservation/compiledHooks.test.d.ts +2 -0
  137. package/lib/storeObservation/compiledHooks.test.d.ts.map +1 -0
  138. package/lib/storeObservation/compiledHooks.test.js +945 -0
  139. package/lib/storeObservation/compiledHooks.test.js.map +7 -0
  140. package/lib/storeObservation/compiledHooks.test.mjs +947 -0
  141. package/lib/storeObservation/compiledHooks.test.mjs.map +7 -0
  142. package/lib/storeObservation/createImportDocumentsTransform.d.ts +9 -0
  143. package/lib/storeObservation/createImportDocumentsTransform.d.ts.map +1 -0
  144. package/lib/storeObservation/createImportDocumentsTransform.js +107 -0
  145. package/lib/storeObservation/createImportDocumentsTransform.js.map +7 -0
  146. package/lib/storeObservation/createImportDocumentsTransform.mjs +99 -0
  147. package/lib/storeObservation/createImportDocumentsTransform.mjs.map +7 -0
  148. package/lib/storeObservation/createImportDocumentsTransform.test.d.ts +2 -0
  149. package/lib/storeObservation/createImportDocumentsTransform.test.d.ts.map +1 -0
  150. package/lib/storeObservation/createImportDocumentsTransform.test.js +62 -0
  151. package/lib/storeObservation/createImportDocumentsTransform.test.js.map +7 -0
  152. package/lib/storeObservation/createImportDocumentsTransform.test.mjs +50 -0
  153. package/lib/storeObservation/createImportDocumentsTransform.test.mjs.map +7 -0
  154. package/lib/storeObservation/fragmentReferencesFieldPolicy.d.ts +3 -0
  155. package/lib/storeObservation/fragmentReferencesFieldPolicy.d.ts.map +1 -0
  156. package/lib/storeObservation/fragmentReferencesFieldPolicy.js +13 -0
  157. package/lib/storeObservation/fragmentReferencesFieldPolicy.js.map +7 -0
  158. package/lib/storeObservation/fragmentReferencesFieldPolicy.mjs +7 -0
  159. package/lib/storeObservation/fragmentReferencesFieldPolicy.mjs.map +7 -0
  160. package/lib/storeObservation/fragmentReferencesFieldPolicy.test.d.ts +2 -0
  161. package/lib/storeObservation/fragmentReferencesFieldPolicy.test.d.ts.map +1 -0
  162. package/lib/storeObservation/fragmentReferencesFieldPolicy.test.js +123 -0
  163. package/lib/storeObservation/fragmentReferencesFieldPolicy.test.js.map +7 -0
  164. package/lib/storeObservation/fragmentReferencesFieldPolicy.test.mjs +109 -0
  165. package/lib/storeObservation/fragmentReferencesFieldPolicy.test.mjs.map +7 -0
  166. package/lib/storeObservation/index.d.ts +5 -0
  167. package/lib/storeObservation/index.d.ts.map +1 -0
  168. package/lib/storeObservation/index.js +23 -0
  169. package/lib/storeObservation/index.js.map +7 -0
  170. package/lib/storeObservation/index.mjs +5 -0
  171. package/lib/storeObservation/index.mjs.map +7 -0
  172. package/lib/storeObservation/nodeFromCacheFieldPolicy.d.ts +9 -0
  173. package/lib/storeObservation/nodeFromCacheFieldPolicy.d.ts.map +1 -0
  174. package/lib/storeObservation/nodeFromCacheFieldPolicy.js +48 -0
  175. package/lib/storeObservation/nodeFromCacheFieldPolicy.js.map +7 -0
  176. package/lib/storeObservation/nodeFromCacheFieldPolicy.mjs +26 -0
  177. package/lib/storeObservation/nodeFromCacheFieldPolicy.mjs.map +7 -0
  178. package/lib/storeObservation/nodeFromCacheFieldPolicy.test.d.ts +2 -0
  179. package/lib/storeObservation/nodeFromCacheFieldPolicy.test.d.ts.map +1 -0
  180. package/lib/storeObservation/nodeFromCacheFieldPolicy.test.js +112 -0
  181. package/lib/storeObservation/nodeFromCacheFieldPolicy.test.js.map +7 -0
  182. package/lib/storeObservation/nodeFromCacheFieldPolicy.test.mjs +96 -0
  183. package/lib/storeObservation/nodeFromCacheFieldPolicy.test.mjs.map +7 -0
  184. package/lib/storeObservation/shallowCompareFragmentReferences.d.ts +23 -0
  185. package/lib/storeObservation/shallowCompareFragmentReferences.d.ts.map +1 -0
  186. package/lib/storeObservation/shallowCompareFragmentReferences.js +50 -0
  187. package/lib/storeObservation/shallowCompareFragmentReferences.js.map +7 -0
  188. package/lib/storeObservation/shallowCompareFragmentReferences.mjs +28 -0
  189. package/lib/storeObservation/shallowCompareFragmentReferences.mjs.map +7 -0
  190. package/lib/storeObservation/typePolicies.d.ts +3 -0
  191. package/lib/storeObservation/typePolicies.d.ts.map +1 -0
  192. package/lib/storeObservation/typePolicies.js +47 -0
  193. package/lib/storeObservation/typePolicies.js.map +7 -0
  194. package/lib/storeObservation/typePolicies.mjs +25 -0
  195. package/lib/storeObservation/typePolicies.mjs.map +7 -0
  196. package/lib/types.d.ts +8 -0
  197. package/lib/types.d.ts.map +1 -1
  198. package/lib/types.js.map +7 -0
  199. package/lib/types.mjs.map +7 -0
  200. package/package.json +23 -18
  201. package/.eslintcache +0 -1
  202. package/CHANGELOG.json +0 -405
@@ -0,0 +1,947 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
3
+ var __getOwnPropSymbols = Object.getOwnPropertySymbols;
4
+ var __propIsEnum = Object.prototype.propertyIsEnumerable;
5
+ var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, {enumerable: true, configurable: true, writable: true, value}) : obj[key] = value;
6
+ var __objSpread = (a, b) => {
7
+ for (var prop in b || (b = {}))
8
+ if (__hasOwnProp.call(b, prop))
9
+ __defNormalProp(a, prop, b[prop]);
10
+ if (__getOwnPropSymbols)
11
+ for (var prop of __getOwnPropSymbols(b)) {
12
+ if (__propIsEnum.call(b, prop))
13
+ __defNormalProp(a, prop, b[prop]);
14
+ }
15
+ return a;
16
+ };
17
+ var __async = (__this, __arguments, generator) => {
18
+ return new Promise((resolve2, reject) => {
19
+ var fulfilled = (value) => {
20
+ try {
21
+ step(generator.next(value));
22
+ } catch (e) {
23
+ reject(e);
24
+ }
25
+ };
26
+ var rejected = (value) => {
27
+ try {
28
+ step(generator.throw(value));
29
+ } catch (e) {
30
+ reject(e);
31
+ }
32
+ };
33
+ var step = (x) => x.done ? resolve2(x.value) : Promise.resolve(x.value).then(fulfilled, rejected);
34
+ step((generator = generator.apply(__this, __arguments)).next());
35
+ });
36
+ };
37
+
38
+ // src/storeObservation/compiledHooks.test.tsx
39
+ import React from "react";
40
+ import {ApolloProvider} from "@apollo/client";
41
+ import {
42
+ act,
43
+ create as createTestRenderer
44
+ } from "react-test-renderer";
45
+ import {buildSchema} from "graphql";
46
+ import {graphql} from "@graphitation/graphql-js-tag";
47
+ import {
48
+ createMockClient
49
+ } from "@graphitation/apollo-mock-client";
50
+ import {
51
+ generate
52
+ } from "@graphitation/graphql-js-operation-payload-generator";
53
+ import {
54
+ readFileSync
55
+ } from "fs";
56
+ import {
57
+ resolve
58
+ } from "path";
59
+ import {
60
+ useCompiledFragment,
61
+ useCompiledLazyLoadQuery,
62
+ useCompiledPaginationFragment,
63
+ useCompiledRefetchableFragment
64
+ } from "./compiledHooks.mjs";
65
+ import {typePolicies} from "./typePolicies.mjs";
66
+ import {documents as compiledHooks_Root_executionQuery_documents} from "./__generated__/compiledHooks_Root_executionQuery.graphql.mjs";
67
+ import {documents as compiledHooks_ChildFragment_documents} from "./__generated__/compiledHooks_ChildWatchNodeQuery.graphql.mjs";
68
+ import {documents as compiledHooks_RefetchableFragment_documents} from "./__generated__/compiledHooks_RefetchableFragment_RefetchQuery.graphql.mjs";
69
+ import {documents as compiledHooks_QueryTypeFragment_documents} from "./__generated__/compiledHooks_QueryTypeWatchNodeQuery.graphql.mjs";
70
+ import {documents as compiledHooks_ForwardPaginationFragment_documents} from "./__generated__/compiledHooks_ForwardPaginationFragment_PaginationQuery.graphql.mjs";
71
+ import {documents as compiledHooks_BackwardPaginationFragment_documents} from "./__generated__/compiledHooks_BackwardPaginationFragment_PaginationQuery.graphql.mjs";
72
+ var schema = buildSchema(readFileSync(resolve(__dirname, "../__tests__/schema.graphql"), "utf8"));
73
+ var Child_fragment = graphql`
74
+ fragment compiledHooks_ChildFragment on User {
75
+ petName
76
+ }
77
+ `;
78
+ var Refetchable_fragment = graphql`
79
+ fragment compiledHooks_RefetchableFragment on User
80
+ @refetchable(queryName: "compiledHooks_RefetchableFragment_RefetchQuery") {
81
+ petName
82
+ avatarUrl(size: $avatarSize)
83
+ }
84
+ `;
85
+ var QueryType_fragment = graphql`
86
+ fragment compiledHooks_QueryTypeFragment on Query {
87
+ nonNode {
88
+ id
89
+ }
90
+ }
91
+ `;
92
+ var ForwardPagination_fragment = graphql`
93
+ fragment compiledHooks_ForwardPaginationFragment on User
94
+ @refetchable(
95
+ queryName: "compiledHooks_ForwardPaginationFragment_PaginationQuery"
96
+ )
97
+ @argumentDefinitions(
98
+ conversationsForwardCount: { type: "Int!", defaultValue: 1 }
99
+ conversationsAfterCursor: { type: "String!", defaultValue: "" }
100
+ ) {
101
+ petName
102
+ avatarUrl(size: $avatarSize)
103
+ conversations(
104
+ first: $conversationsForwardCount
105
+ after: $conversationsAfterCursor
106
+ ) @connection(key: "compiledHooks_user_conversations") {
107
+ edges {
108
+ node {
109
+ title
110
+ ...compiledHooks_BackwardPaginationFragment
111
+ }
112
+ }
113
+ }
114
+ }
115
+ `;
116
+ var BackwardPagination_fragment = graphql`
117
+ fragment compiledHooks_BackwardPaginationFragment on Conversation
118
+ @refetchable(
119
+ queryName: "compiledHooks_BackwardPaginationFragment_PaginationQuery"
120
+ ) {
121
+ messages(last: $messagesBackwardCount, before: $messagesBeforeCursor)
122
+ @connection(key: "compiledHooks_conversation_messages") {
123
+ edges {
124
+ node {
125
+ text
126
+ }
127
+ }
128
+ }
129
+ }
130
+ `;
131
+ var Root_executionQueryDocument = graphql`
132
+ query compiledHooks_Root_executionQuery(
133
+ $userId: Int!
134
+ $avatarSize: Int = 21
135
+ $messagesBackwardCount: Int!
136
+ $messagesBeforeCursor: String!
137
+ ) {
138
+ user(id: $userId) {
139
+ name
140
+ ...compiledHooks_ChildFragment
141
+ ...compiledHooks_RefetchableFragment
142
+ ...compiledHooks_ForwardPaginationFragment
143
+ }
144
+ ...compiledHooks_QueryTypeFragment
145
+ }
146
+ `;
147
+ describe("compiledHooks", () => {
148
+ let client;
149
+ let testRenderer;
150
+ let useFragmentResult;
151
+ let useRefetchableFragmentResult;
152
+ let forwardUsePaginationFragmentResult;
153
+ let backwardUsePaginationFragmentResult;
154
+ let useLazyLoadQueryResult = null;
155
+ let componentOnQueryTypeResult;
156
+ const ChildComponent = (props) => {
157
+ const result = useCompiledFragment(compiledHooks_ChildFragment_documents, props.user);
158
+ useFragmentResult.push(result);
159
+ return null;
160
+ };
161
+ const ChildRefetchableComponent = (props) => {
162
+ const result = useCompiledRefetchableFragment(compiledHooks_RefetchableFragment_documents, props.user);
163
+ useRefetchableFragmentResult.push(result);
164
+ return null;
165
+ };
166
+ const ComponentOnQueryType = (props) => {
167
+ const result = useCompiledFragment(compiledHooks_QueryTypeFragment_documents, props.query);
168
+ componentOnQueryTypeResult.push(result);
169
+ return null;
170
+ };
171
+ const ChildForwardPaginationComponent = (props) => {
172
+ const result = useCompiledPaginationFragment(compiledHooks_ForwardPaginationFragment_documents, props.user);
173
+ forwardUsePaginationFragmentResult.push(result);
174
+ return result.data.conversations.edges.map((edge, index) => {
175
+ return /* @__PURE__ */ React.createElement(ChildBackwardPaginationComponent, {
176
+ conversation: edge.node,
177
+ key: index
178
+ });
179
+ });
180
+ };
181
+ const ChildBackwardPaginationComponent = (props) => {
182
+ const result = useCompiledPaginationFragment(compiledHooks_BackwardPaginationFragment_documents, props.conversation);
183
+ backwardUsePaginationFragmentResult.push(result);
184
+ return null;
185
+ };
186
+ const RootComponent = (props) => {
187
+ const result = useCompiledLazyLoadQuery(compiledHooks_Root_executionQuery_documents, {variables: props.variables});
188
+ useLazyLoadQueryResult = result;
189
+ return result.data ? /* @__PURE__ */ React.createElement(React.Fragment, null, /* @__PURE__ */ React.createElement(ChildComponent, {
190
+ user: result.data.user
191
+ }), /* @__PURE__ */ React.createElement(ChildRefetchableComponent, {
192
+ user: result.data.user
193
+ }), /* @__PURE__ */ React.createElement(ChildForwardPaginationComponent, {
194
+ user: result.data.user
195
+ }), /* @__PURE__ */ React.createElement(ComponentOnQueryType, {
196
+ query: result.data
197
+ })) : null;
198
+ };
199
+ beforeEach(() => {
200
+ useLazyLoadQueryResult = null;
201
+ useFragmentResult = [];
202
+ useRefetchableFragmentResult = [];
203
+ forwardUsePaginationFragmentResult = [];
204
+ backwardUsePaginationFragmentResult = [];
205
+ componentOnQueryTypeResult = [];
206
+ client = createMockClient(schema, {
207
+ cache: {
208
+ possibleTypes: {
209
+ Node: ["User"]
210
+ },
211
+ typePolicies
212
+ }
213
+ });
214
+ act(() => {
215
+ testRenderer = createTestRenderer(/* @__PURE__ */ React.createElement(ApolloProvider, {
216
+ client
217
+ }, /* @__PURE__ */ React.createElement(ErrorBoundary, null, /* @__PURE__ */ React.createElement(RootComponent, {
218
+ variables: {
219
+ userId: 42,
220
+ messagesBackwardCount: 1,
221
+ messagesBeforeCursor: ""
222
+ }
223
+ }))));
224
+ });
225
+ });
226
+ describe(useCompiledLazyLoadQuery, () => {
227
+ it("correctly returns loading state", () => __async(void 0, null, function* () {
228
+ expect(useLazyLoadQueryResult).toEqual({
229
+ data: void 0,
230
+ error: void 0
231
+ });
232
+ yield act(() => client.mock.resolveMostRecentOperation((operation) => generate(operation)));
233
+ expect(useLazyLoadQueryResult).toEqual({
234
+ data: expect.objectContaining({}),
235
+ error: void 0
236
+ });
237
+ }));
238
+ it("cancels the execution query while in-flight on unmount", () => __async(void 0, null, function* () {
239
+ expect(activeQueries(client).map((query) => query.queryName)).toEqual([
240
+ "compiledHooks_Root_executionQuery"
241
+ ]);
242
+ yield act(() => __async(void 0, null, function* () {
243
+ testRenderer.unmount();
244
+ return new Promise((resolve2) => setTimeout(resolve2, 0));
245
+ }));
246
+ expect(client.getObservableQueries().size).toBe(0);
247
+ }));
248
+ describe("once loaded", () => {
249
+ let executionQueryId;
250
+ beforeEach(() => __async(void 0, null, function* () {
251
+ executionQueryId = last(activeQueries(client)).queryId;
252
+ yield act(() => client.mock.resolveMostRecentOperation((operation) => generate(operation, {
253
+ User: (options, generateId) => {
254
+ return {
255
+ id: options.parentType === "Query" ? operation.request.variables.userId : generateId()
256
+ };
257
+ },
258
+ Conversation: () => ({
259
+ id: "first-paged-conversation"
260
+ }),
261
+ Message: () => ({
262
+ id: "first-paged-message"
263
+ })
264
+ })));
265
+ }));
266
+ it("unsubscribes from the execution query", () => __async(void 0, null, function* () {
267
+ expect(activeQueries(client).map((query) => query.queryId)).not.toContain(executionQueryId);
268
+ }));
269
+ it("loads all data of the execution query into the store", () => {
270
+ expect(client.cache.extract()).toMatchInlineSnapshot(`
271
+ Object {
272
+ "Conversation:first-paged-conversation": Object {
273
+ "__typename": "Conversation",
274
+ "id": "first-paged-conversation",
275
+ "messages:compiledHooks_conversation_messages": Object {
276
+ "__typename": "ConversationMessagesConnection",
277
+ "edges": Array [
278
+ Object {
279
+ "__typename": "ConversationMessagesConnectionEdge",
280
+ "cursor": "<mock-value-for-field-\\"cursor\\">",
281
+ "node": Object {
282
+ "__ref": "Message:first-paged-message",
283
+ },
284
+ },
285
+ ],
286
+ "pageInfo": Object {
287
+ "__typename": "PageInfo",
288
+ "hasPreviousPage": false,
289
+ "startCursor": "<mock-value-for-field-\\"startCursor\\">",
290
+ },
291
+ },
292
+ "title": "<mock-value-for-field-\\"title\\">",
293
+ },
294
+ "Message:first-paged-message": Object {
295
+ "__typename": "Message",
296
+ "id": "first-paged-message",
297
+ "text": "<mock-value-for-field-\\"text\\">",
298
+ },
299
+ "NonNode:<mock-value-for-field-\\"id\\">": Object {
300
+ "__typename": "NonNode",
301
+ "id": "<mock-value-for-field-\\"id\\">",
302
+ },
303
+ "ROOT_QUERY": Object {
304
+ "__typename": "Query",
305
+ "nonNode": Object {
306
+ "__ref": "NonNode:<mock-value-for-field-\\"id\\">",
307
+ },
308
+ "user({\\"id\\":42})": Object {
309
+ "__ref": "User:42",
310
+ },
311
+ },
312
+ "User:42": Object {
313
+ "__typename": "User",
314
+ "avatarUrl({\\"size\\":21})": "<mock-value-for-field-\\"avatarUrl\\">",
315
+ "conversations:compiledHooks_user_conversations": Object {
316
+ "__typename": "ConversationsConnection",
317
+ "edges": Array [
318
+ Object {
319
+ "__typename": "ConversationsConnectionEdge",
320
+ "cursor": "<mock-value-for-field-\\"cursor\\">",
321
+ "node": Object {
322
+ "__ref": "Conversation:first-paged-conversation",
323
+ },
324
+ },
325
+ ],
326
+ "pageInfo": Object {
327
+ "__typename": "PageInfo",
328
+ "endCursor": "<mock-value-for-field-\\"endCursor\\">",
329
+ "hasNextPage": false,
330
+ },
331
+ },
332
+ "id": 42,
333
+ "name": "<mock-value-for-field-\\"name\\">",
334
+ "petName": "<mock-value-for-field-\\"petName\\">",
335
+ },
336
+ }
337
+ `);
338
+ });
339
+ it("only returns the fields selected in the watch query to the component", () => {
340
+ expect(useLazyLoadQueryResult.data).toMatchInlineSnapshot(`
341
+ Object {
342
+ "__fragments": Object {
343
+ "avatarSize": 21,
344
+ "messagesBackwardCount": 1,
345
+ "messagesBeforeCursor": "",
346
+ "userId": 42,
347
+ },
348
+ "user": Object {
349
+ "__fragments": Object {
350
+ "avatarSize": 21,
351
+ "messagesBackwardCount": 1,
352
+ "messagesBeforeCursor": "",
353
+ "userId": 42,
354
+ },
355
+ "__typename": "User",
356
+ "id": 42,
357
+ "name": "<mock-value-for-field-\\"name\\">",
358
+ },
359
+ }
360
+ `);
361
+ });
362
+ it("does not re-render when a field that was not selected in the watch query is updated in the store", () => __async(void 0, null, function* () {
363
+ const before = useLazyLoadQueryResult.data;
364
+ yield act(() => __async(void 0, null, function* () {
365
+ client.cache.modify({
366
+ id: "User:42",
367
+ fields: {
368
+ petName: () => "Phoenix"
369
+ }
370
+ });
371
+ return new Promise((resolve2) => setTimeout(resolve2, 0));
372
+ }));
373
+ expect(useLazyLoadQueryResult.data).toBe(before);
374
+ }));
375
+ it("does re-render when a field that was selected in the watch query is updated in the store", () => __async(void 0, null, function* () {
376
+ const before = useLazyLoadQueryResult.data;
377
+ yield act(() => __async(void 0, null, function* () {
378
+ client.cache.modify({
379
+ id: "User:42",
380
+ fields: {
381
+ name: () => "Satya"
382
+ }
383
+ });
384
+ return new Promise((resolve2) => setTimeout(resolve2, 0));
385
+ }));
386
+ expect(useLazyLoadQueryResult.data).not.toBe(before);
387
+ expect(useLazyLoadQueryResult.data).toMatchInlineSnapshot(`
388
+ Object {
389
+ "__fragments": Object {
390
+ "avatarSize": 21,
391
+ "messagesBackwardCount": 1,
392
+ "messagesBeforeCursor": "",
393
+ "userId": 42,
394
+ },
395
+ "user": Object {
396
+ "__fragments": Object {
397
+ "avatarSize": 21,
398
+ "messagesBackwardCount": 1,
399
+ "messagesBeforeCursor": "",
400
+ "userId": 42,
401
+ },
402
+ "__typename": "User",
403
+ "id": 42,
404
+ "name": "Satya",
405
+ },
406
+ }
407
+ `);
408
+ }));
409
+ it("fetches new data when variables change", () => __async(void 0, null, function* () {
410
+ act(() => {
411
+ testRenderer.update(/* @__PURE__ */ React.createElement(ApolloProvider, {
412
+ client
413
+ }, /* @__PURE__ */ React.createElement(ErrorBoundary, null, /* @__PURE__ */ React.createElement(RootComponent, {
414
+ variables: {
415
+ userId: 21,
416
+ messagesBackwardCount: 1,
417
+ messagesBeforeCursor: ""
418
+ }
419
+ }))));
420
+ });
421
+ yield act(() => client.mock.resolveMostRecentOperation((operation) => generate(operation, {
422
+ User: () => ({id: operation.request.variables.userId})
423
+ })));
424
+ expect(client.cache.extract()["User:21"]).toMatchInlineSnapshot(`
425
+ Object {
426
+ "__typename": "User",
427
+ "avatarUrl({\\"size\\":21})": "<mock-value-for-field-\\"avatarUrl\\">",
428
+ "conversations:compiledHooks_user_conversations": Object {
429
+ "__typename": "ConversationsConnection",
430
+ "edges": Array [
431
+ Object {
432
+ "__typename": "ConversationsConnectionEdge",
433
+ "cursor": "<mock-value-for-field-\\"cursor\\">",
434
+ "node": Object {
435
+ "__ref": "Conversation:<Conversation-mock-id-5>",
436
+ },
437
+ },
438
+ ],
439
+ "pageInfo": Object {
440
+ "__typename": "PageInfo",
441
+ "endCursor": "<mock-value-for-field-\\"endCursor\\">",
442
+ "hasNextPage": false,
443
+ },
444
+ },
445
+ "id": 21,
446
+ "name": "<mock-value-for-field-\\"name\\">",
447
+ "petName": "<mock-value-for-field-\\"petName\\">",
448
+ }
449
+ `);
450
+ }));
451
+ it("does not try to kick-off a new query when the variables object deep equals the previous one", () => __async(void 0, null, function* () {
452
+ const spy = jest.spyOn(client, "query");
453
+ yield act(() => __async(void 0, null, function* () {
454
+ testRenderer.update(/* @__PURE__ */ React.createElement(ApolloProvider, {
455
+ client
456
+ }, /* @__PURE__ */ React.createElement(ErrorBoundary, null, /* @__PURE__ */ React.createElement(RootComponent, {
457
+ variables: {
458
+ userId: 42,
459
+ messagesBackwardCount: 1,
460
+ messagesBeforeCursor: ""
461
+ }
462
+ }))));
463
+ return new Promise((resolve2) => setTimeout(resolve2, 100));
464
+ }));
465
+ expect(spy).not.toHaveBeenCalled();
466
+ }));
467
+ it("removes all watch queries on unmount", () => __async(void 0, null, function* () {
468
+ yield act(() => __async(void 0, null, function* () {
469
+ testRenderer.unmount();
470
+ return new Promise((resolve2) => setTimeout(resolve2, 0));
471
+ }));
472
+ expect(client.getObservableQueries().size).toBe(0);
473
+ }));
474
+ });
475
+ });
476
+ function itBehavesLikeFragment(returnedResults, fragmentSpecificFieldSelections) {
477
+ beforeEach(() => __async(this, null, function* () {
478
+ yield act(() => client.mock.resolveMostRecentOperation((operation) => {
479
+ const result = generate(operation, {
480
+ User: () => ({
481
+ id: 42
482
+ }),
483
+ Conversation: () => ({
484
+ id: "first-paged-conversation"
485
+ }),
486
+ Message: () => ({
487
+ id: "first-paged-message"
488
+ }),
489
+ PageInfo: () => ({
490
+ startCursor: "first-page-start-cursor",
491
+ endCursor: "first-page-end-cursor",
492
+ hasNextPage: true,
493
+ hasPreviousPage: true
494
+ })
495
+ });
496
+ return result;
497
+ }));
498
+ }));
499
+ it("only returns the fields selected in the watch query to the component", () => {
500
+ expect(last(returnedResults())).toEqual(__objSpread({
501
+ __fragments: {
502
+ avatarSize: 21,
503
+ messagesBackwardCount: 1,
504
+ messagesBeforeCursor: "",
505
+ userId: 42
506
+ },
507
+ __typename: "User",
508
+ id: 42,
509
+ petName: '<mock-value-for-field-"petName">'
510
+ }, fragmentSpecificFieldSelections));
511
+ });
512
+ it("returns the same object when a field that was not selected in the watch query is updated in the store", () => __async(this, null, function* () {
513
+ const before = last(returnedResults());
514
+ yield act(() => __async(this, null, function* () {
515
+ client.cache.modify({
516
+ id: "User:42",
517
+ fields: {
518
+ name: () => "Satya"
519
+ }
520
+ });
521
+ return new Promise((resolve2) => setTimeout(resolve2, 0));
522
+ }));
523
+ expect(last(returnedResults())).toBe(before);
524
+ }));
525
+ it("returns a new object when a field that was selected in the watch query is updated in the store", () => __async(this, null, function* () {
526
+ yield act(() => __async(this, null, function* () {
527
+ client.cache.modify({
528
+ id: "User:42",
529
+ fields: {
530
+ petName: () => "some new value"
531
+ }
532
+ });
533
+ return new Promise((resolve2) => setTimeout(resolve2, 0));
534
+ }));
535
+ expect(returnedResults().length).toBe(2);
536
+ expect(last(returnedResults())).toMatchObject({
537
+ petName: "some new value"
538
+ });
539
+ }));
540
+ it("returns data synchronously", () => {
541
+ expect(returnedResults().length).toBe(1);
542
+ });
543
+ it("fetches new data when variables change", () => __async(this, null, function* () {
544
+ act(() => {
545
+ testRenderer.update(/* @__PURE__ */ React.createElement(ApolloProvider, {
546
+ client
547
+ }, /* @__PURE__ */ React.createElement(ErrorBoundary, null, /* @__PURE__ */ React.createElement(RootComponent, {
548
+ variables: {
549
+ userId: 21,
550
+ messagesBackwardCount: 1,
551
+ messagesBeforeCursor: ""
552
+ }
553
+ }))));
554
+ });
555
+ yield act(() => client.mock.resolveMostRecentOperation((operation) => generate(operation, {
556
+ User: () => ({id: operation.request.variables.userId})
557
+ })));
558
+ expect(last(returnedResults()).id).toBe(21);
559
+ }));
560
+ }
561
+ describe(useCompiledFragment, () => {
562
+ itBehavesLikeFragment(() => useFragmentResult, {
563
+ petName: '<mock-value-for-field-"petName">'
564
+ });
565
+ it("also works with fragments on the Query type", () => {
566
+ expect(last(componentOnQueryTypeResult)).toMatchInlineSnapshot(`
567
+ Object {
568
+ "__fragments": Object {
569
+ "avatarSize": 21,
570
+ "messagesBackwardCount": 1,
571
+ "messagesBeforeCursor": "",
572
+ "userId": 42,
573
+ },
574
+ "nonNode": Object {
575
+ "__typename": "NonNode",
576
+ "id": "<mock-value-for-field-\\"id\\">",
577
+ },
578
+ }
579
+ `);
580
+ });
581
+ });
582
+ function itBehavesLikeRefetchableFragment(returnedResults) {
583
+ it.todo("supports variables with default values on either operations or with @argumentDefinitions");
584
+ describe("when refetching", () => {
585
+ let onCompleted;
586
+ let disposable;
587
+ beforeEach(() => {
588
+ const [_data, refetch] = last(returnedResults());
589
+ onCompleted = jest.fn();
590
+ disposable = refetch({avatarSize: 42}, {onCompleted});
591
+ });
592
+ it("can be cancelled", () => {
593
+ const query = last(activeQueries(client));
594
+ disposable.dispose();
595
+ expect(client.getObservableQueries().has(query.queryId)).toBeFalsy();
596
+ });
597
+ it("cancels when unmounting", () => __async(this, null, function* () {
598
+ yield act(() => __async(this, null, function* () {
599
+ const query = last(activeQueries(client));
600
+ testRenderer.unmount();
601
+ yield new Promise((resolve2) => setTimeout(resolve2, 0));
602
+ expect(client.getObservableQueries().has(query.queryId)).toBeFalsy();
603
+ }));
604
+ }));
605
+ describe("successfully", () => {
606
+ beforeEach(() => __async(this, null, function* () {
607
+ yield act(() => {
608
+ client.mock.resolveMostRecentOperation((operation) => generate(operation, {
609
+ Node: () => ({
610
+ id: 42,
611
+ avatarUrl: `avatarUrl-with-size-${operation.request.variables.avatarSize}`
612
+ })
613
+ }));
614
+ return new Promise((resolve2) => setTimeout(resolve2, 0));
615
+ });
616
+ }));
617
+ it("returns a new object from the hook", () => {
618
+ expect(last(returnedResults())[0]).toMatchObject({
619
+ __typename: "User",
620
+ avatarUrl: "avatarUrl-with-size-42",
621
+ id: 42
622
+ });
623
+ });
624
+ it("updates the fragment reference request variables for future requests", () => {
625
+ expect(last(returnedResults())[0]).toMatchObject({
626
+ __fragments: {
627
+ avatarSize: 42,
628
+ userId: 42
629
+ }
630
+ });
631
+ });
632
+ it("invokes the onComplete callback without error", () => {
633
+ expect(onCompleted).toHaveBeenCalledWith(null);
634
+ });
635
+ });
636
+ describe("and an error occurs", () => {
637
+ const error = new Error("oh noes");
638
+ beforeEach(() => __async(this, null, function* () {
639
+ yield act(() => client.mock.rejectMostRecentOperation(error));
640
+ }));
641
+ it("invokes the onComplete callback when an error occurs", () => {
642
+ expect(onCompleted).toHaveBeenCalledWith(error);
643
+ });
644
+ it("does not update the fragment reference request variables for future requests", () => __async(this, null, function* () {
645
+ const [_data, refetch] = last(returnedResults());
646
+ refetch({});
647
+ expect(client.mock.getMostRecentOperation().request.variables.avatarSize).toBe(21);
648
+ }));
649
+ });
650
+ });
651
+ }
652
+ describe(useCompiledRefetchableFragment, () => {
653
+ itBehavesLikeFragment(() => useRefetchableFragmentResult.map(([data, _refetch]) => data), {avatarUrl: '<mock-value-for-field-"avatarUrl">'});
654
+ itBehavesLikeRefetchableFragment(() => useRefetchableFragmentResult);
655
+ });
656
+ describe(useCompiledPaginationFragment, () => {
657
+ itBehavesLikeFragment(() => forwardUsePaginationFragmentResult.map(({data}) => data), {
658
+ avatarUrl: '<mock-value-for-field-"avatarUrl">',
659
+ conversations: {
660
+ __typename: "ConversationsConnection",
661
+ edges: [
662
+ {
663
+ __typename: "ConversationsConnectionEdge",
664
+ cursor: '<mock-value-for-field-"cursor">',
665
+ node: {
666
+ __fragments: {
667
+ avatarSize: 21,
668
+ messagesBackwardCount: 1,
669
+ messagesBeforeCursor: "",
670
+ userId: 42
671
+ },
672
+ __typename: "Conversation",
673
+ id: "first-paged-conversation",
674
+ title: '<mock-value-for-field-"title">'
675
+ }
676
+ }
677
+ ],
678
+ pageInfo: {
679
+ __typename: "PageInfo",
680
+ endCursor: "first-page-end-cursor",
681
+ hasNextPage: true
682
+ }
683
+ }
684
+ });
685
+ itBehavesLikeRefetchableFragment(() => forwardUsePaginationFragmentResult.map(({data, refetch}) => [
686
+ data,
687
+ refetch
688
+ ]));
689
+ describe("when paginating forward", () => {
690
+ it("returns that next data is available", () => {
691
+ const {hasNext} = last(forwardUsePaginationFragmentResult);
692
+ expect(hasNext).toBeTruthy();
693
+ });
694
+ it("uses the correct count and cursor values", () => {
695
+ act(() => {
696
+ const {loadNext} = last(forwardUsePaginationFragmentResult);
697
+ loadNext(123);
698
+ });
699
+ const operation = client.mock.getMostRecentOperation();
700
+ expect(operation.request.variables).toMatchObject({
701
+ conversationsForwardCount: 123,
702
+ conversationsAfterCursor: "first-page-end-cursor"
703
+ });
704
+ });
705
+ it("returns that a pagination operation is in-flight", () => {
706
+ act(() => {
707
+ const {loadNext} = last(forwardUsePaginationFragmentResult);
708
+ loadNext(123);
709
+ });
710
+ const {isLoadingNext} = last(forwardUsePaginationFragmentResult);
711
+ expect(isLoadingNext).toBeTruthy();
712
+ });
713
+ it("can be cancelled", () => {
714
+ act(() => {
715
+ const {loadNext} = last(forwardUsePaginationFragmentResult);
716
+ const disposable = loadNext(123);
717
+ const query = last(activeQueries(client));
718
+ disposable.dispose();
719
+ expect(client.getObservableQueries().has(query.queryId)).toBeFalsy();
720
+ });
721
+ });
722
+ it("cancels when unmounting", () => __async(void 0, null, function* () {
723
+ yield act(() => __async(void 0, null, function* () {
724
+ const {loadNext} = last(forwardUsePaginationFragmentResult);
725
+ loadNext(123);
726
+ const query = last(activeQueries(client));
727
+ testRenderer.unmount();
728
+ yield new Promise((resolve2) => setTimeout(resolve2, 0));
729
+ expect(client.getObservableQueries().has(query.queryId)).toBeFalsy();
730
+ }));
731
+ }));
732
+ it("invokes the onComplete callback when an error occurs", () => __async(void 0, null, function* () {
733
+ const onCompleted = jest.fn();
734
+ const error = new Error("oh noes");
735
+ const {loadNext} = last(forwardUsePaginationFragmentResult);
736
+ yield act(() => __async(void 0, null, function* () {
737
+ loadNext(1, {onCompleted});
738
+ yield client.mock.rejectMostRecentOperation(error);
739
+ }));
740
+ expect(onCompleted).toHaveBeenCalledWith(error);
741
+ }));
742
+ describe("and having received the response", () => {
743
+ let onCompleted;
744
+ beforeEach(() => __async(void 0, null, function* () {
745
+ onCompleted = jest.fn();
746
+ yield act(() => __async(void 0, null, function* () {
747
+ const {loadNext} = last(forwardUsePaginationFragmentResult);
748
+ loadNext(1, {onCompleted});
749
+ yield new Promise((resolve2) => setTimeout(resolve2, 0));
750
+ client.mock.resolveMostRecentOperation((operation) => generate(operation, {
751
+ Node: () => ({
752
+ id: 42
753
+ }),
754
+ Conversation: () => ({
755
+ id: "second-paged-conversation"
756
+ }),
757
+ PageInfo: () => ({
758
+ endCursor: "second-page-end-cursor",
759
+ hasNextPage: false
760
+ })
761
+ }));
762
+ return new Promise((resolve2) => setTimeout(resolve2, 0));
763
+ }));
764
+ }));
765
+ it("returns that no pagination operation is in-flight", () => {
766
+ const {isLoadingNext} = last(forwardUsePaginationFragmentResult);
767
+ expect(isLoadingNext).toBeFalsy();
768
+ });
769
+ it("loads the new data into the store", () => {
770
+ expect(client.cache.extract()).toMatchObject({
771
+ "Conversation:second-paged-conversation": {
772
+ id: "second-paged-conversation",
773
+ __typename: "Conversation",
774
+ title: '<mock-value-for-field-"title">'
775
+ }
776
+ });
777
+ });
778
+ it("returns the complete list data (previous+new) from the hook", () => {
779
+ const result = last(forwardUsePaginationFragmentResult);
780
+ expect(result.data.conversations.edges.map((edge) => edge.node.id)).toMatchInlineSnapshot(`
781
+ Array [
782
+ "first-paged-conversation",
783
+ "second-paged-conversation",
784
+ ]
785
+ `);
786
+ });
787
+ it("uses the new cursor value", () => {
788
+ act(() => {
789
+ const {loadNext} = last(forwardUsePaginationFragmentResult);
790
+ loadNext(123);
791
+ });
792
+ const operation = client.mock.getMostRecentOperation();
793
+ expect(operation.request.variables).toMatchObject({
794
+ conversationsAfterCursor: "second-page-end-cursor"
795
+ });
796
+ });
797
+ it("returns that no next data is available", () => {
798
+ const {hasNext} = last(forwardUsePaginationFragmentResult);
799
+ expect(hasNext).toBeFalsy();
800
+ });
801
+ it("invokes the onComplete callback without error", () => {
802
+ expect(onCompleted).toHaveBeenCalledWith(null);
803
+ });
804
+ });
805
+ });
806
+ describe("when paginating backward", () => {
807
+ it("returns that previous data is available", () => {
808
+ const {hasPrevious} = last(backwardUsePaginationFragmentResult);
809
+ expect(hasPrevious).toBeTruthy();
810
+ });
811
+ it("uses the correct count and cursor values", () => {
812
+ act(() => {
813
+ const {loadPrevious} = last(backwardUsePaginationFragmentResult);
814
+ loadPrevious(123);
815
+ });
816
+ const operation = client.mock.getMostRecentOperation();
817
+ expect(operation.request.variables).toMatchObject({
818
+ messagesBackwardCount: 123,
819
+ messagesBeforeCursor: "first-page-start-cursor"
820
+ });
821
+ });
822
+ it("returns that a pagination operation is in-flight", () => {
823
+ act(() => {
824
+ const {loadPrevious} = last(backwardUsePaginationFragmentResult);
825
+ loadPrevious(123);
826
+ });
827
+ const {isLoadingPrevious} = last(backwardUsePaginationFragmentResult);
828
+ expect(isLoadingPrevious).toBeTruthy();
829
+ });
830
+ it("can be cancelled", () => {
831
+ act(() => {
832
+ const {loadPrevious} = last(backwardUsePaginationFragmentResult);
833
+ const disposable = loadPrevious(123);
834
+ const query = last(activeQueries(client));
835
+ disposable.dispose();
836
+ expect(client.getObservableQueries().has(query.queryId)).toBeFalsy();
837
+ });
838
+ });
839
+ it("cancels when unmounting", () => __async(void 0, null, function* () {
840
+ yield act(() => __async(void 0, null, function* () {
841
+ const {loadPrevious} = last(backwardUsePaginationFragmentResult);
842
+ loadPrevious(123);
843
+ const query = last(activeQueries(client));
844
+ testRenderer.unmount();
845
+ yield new Promise((resolve2) => setTimeout(resolve2, 0));
846
+ expect(client.getObservableQueries().has(query.queryId)).toBeFalsy();
847
+ }));
848
+ }));
849
+ it("invokes the onComplete callback when an error occurs", () => __async(void 0, null, function* () {
850
+ const onCompleted = jest.fn();
851
+ const error = new Error("oh noes");
852
+ const {loadPrevious} = last(backwardUsePaginationFragmentResult);
853
+ yield act(() => __async(void 0, null, function* () {
854
+ loadPrevious(1, {onCompleted});
855
+ yield client.mock.rejectMostRecentOperation(error);
856
+ }));
857
+ expect(onCompleted).toHaveBeenCalledWith(error);
858
+ }));
859
+ describe("and having received the response", () => {
860
+ let onCompleted;
861
+ beforeEach(() => __async(void 0, null, function* () {
862
+ onCompleted = jest.fn();
863
+ yield act(() => {
864
+ const {loadPrevious} = last(backwardUsePaginationFragmentResult);
865
+ loadPrevious(1, {onCompleted});
866
+ client.mock.resolveMostRecentOperation((operation) => generate(operation, {
867
+ Node: () => ({
868
+ id: 42
869
+ }),
870
+ Message: () => ({
871
+ id: "second-paged-message"
872
+ }),
873
+ PageInfo: () => ({
874
+ startCursor: "second-page-start-cursor",
875
+ hasPreviousPage: false
876
+ })
877
+ }));
878
+ return new Promise((resolve2) => setTimeout(resolve2, 0));
879
+ });
880
+ }));
881
+ it("returns that no pagination operation is in-flight", () => {
882
+ const {isLoadingPrevious} = last(backwardUsePaginationFragmentResult);
883
+ expect(isLoadingPrevious).toBeFalsy();
884
+ });
885
+ it("loads the new data into the store", () => {
886
+ expect(client.cache.extract()).toMatchObject({
887
+ "Message:second-paged-message": {
888
+ id: "second-paged-message",
889
+ __typename: "Message",
890
+ text: '<mock-value-for-field-"text">'
891
+ }
892
+ });
893
+ });
894
+ it("returns the complete list data (previous+new) from the hook", () => {
895
+ const result = last(backwardUsePaginationFragmentResult);
896
+ expect(result.data.messages.edges.map((edge) => edge.node.id)).toMatchInlineSnapshot(`
897
+ Array [
898
+ "second-paged-message",
899
+ "first-paged-message",
900
+ ]
901
+ `);
902
+ });
903
+ it("uses the new cursor value", () => {
904
+ act(() => {
905
+ const {loadPrevious} = last(backwardUsePaginationFragmentResult);
906
+ loadPrevious(123);
907
+ });
908
+ const operation = client.mock.getMostRecentOperation();
909
+ expect(operation.request.variables).toMatchObject({
910
+ messagesBeforeCursor: "second-page-start-cursor"
911
+ });
912
+ });
913
+ it("returns that no previous data is available", () => {
914
+ const {hasPrevious} = last(backwardUsePaginationFragmentResult);
915
+ expect(hasPrevious).toBeFalsy();
916
+ });
917
+ it("invokes the onComplete callback without error", () => {
918
+ expect(onCompleted).toHaveBeenCalledWith(null);
919
+ });
920
+ });
921
+ });
922
+ });
923
+ });
924
+ var ErrorBoundary = class extends React.Component {
925
+ constructor() {
926
+ super(...arguments);
927
+ this.state = {hasError: false};
928
+ }
929
+ static getDerivedStateFromError(error) {
930
+ return {hasError: true};
931
+ }
932
+ componentDidCatch(error, errorInfo) {
933
+ console.error({error, errorInfo});
934
+ }
935
+ render() {
936
+ if (this.state.hasError) {
937
+ return /* @__PURE__ */ React.createElement("h1", null, "Something went wrong.");
938
+ }
939
+ return this.props.children;
940
+ }
941
+ };
942
+ function last(list) {
943
+ return list[list.length - 1];
944
+ }
945
+ function activeQueries(client) {
946
+ return Array.from(client.getObservableQueries().values());
947
+ }