@graphitation/apollo-react-relay-duct-tape 0.7.4 → 1.0.0-alpha.3

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 +2 -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 +19 -13
  201. package/.eslintcache +0 -1
  202. package/CHANGELOG.json +0 -438
package/CHANGELOG.md CHANGED
@@ -1,12 +1,12 @@
1
1
  # Change Log - @graphitation/apollo-react-relay-duct-tape
2
2
 
3
- This log was last generated on Fri, 14 Jan 2022 11:15:11 GMT and should not be manually modified.
3
+ This log was last generated on Fri, 14 Jan 2022 11:15:34 GMT and should not be manually modified.
4
4
 
5
5
  <!-- Start content -->
6
6
 
7
7
  ## 0.7.4
8
8
 
9
- Fri, 14 Jan 2022 11:15:11 GMT
9
+ Fri, 14 Jan 2022 11:15:34 GMT
10
10
 
11
11
  ### Patches
12
12
 
package/README.md CHANGED
@@ -5,3 +5,125 @@ A compatibility wrapper that provides the react-relay API on top of Apollo Clien
5
5
  _The name is a reference to the Apollo 13 mission._
6
6
 
7
7
  Use this together with [relay-compiler-language-graphitation](../relay-compiler-language-graphitation) to have typings generated.
8
+
9
+ # Setup
10
+
11
+ ### Installation
12
+
13
+ - Install the packages from this repo:
14
+
15
+ ```
16
+ yarn add @graphitation/apollo-react-relay-duct-tape
17
+ yarn add --dev relay-compiler-language-graphitation
18
+ ```
19
+
20
+ - Patch your version of `@apollo/client` using the patch found in [the patches directory](../../patches). You can either do so manually or use a tool like [patch-package](https://github.com/ds300/patch-package).
21
+
22
+ - For an expedient developer-experience, you will want to install [the `watchman` tool](https://facebook.github.io/watchman/).
23
+ - On macOS (using [homebrew](https://brew.sh)): `$ brew install watchman`
24
+ - On Windows (using [chocolatey](https://chocolatey.org)): `$ choco install watchman`
25
+
26
+ ### Configuration
27
+
28
+ - Configure Apollo Client's cache to automatically add `__typename` field selections, which concrete types implement the `Node` interface, and the type-policies needed to read the watch query data from the store:
29
+
30
+ ```ts
31
+ import { InMemoryCache } from "@apollo/client";
32
+ import { typePolicies } from "@graphitation/apollo-react-relay-duct-tape";
33
+
34
+ const cache = new InMemoryCache({
35
+ addTypename: true,
36
+ // Be sure to specify types that implement the Node interface
37
+ // See https://www.apollographql.com/docs/react/data/fragments/#using-fragments-with-unions-and-interfaces
38
+ possibleTypes: {
39
+ Node: ["Todo"],
40
+ },
41
+ // Either use the `typePolicies` object directly or otherwise extend appropriately
42
+ typePolicies: {
43
+ Query: {
44
+ fields: {
45
+ __fragments: {
46
+ read: typePolicies.Query.fields.__fragments.read,
47
+ },
48
+ node: {
49
+ read: typePolicies.Query.fields.node.read,
50
+ },
51
+ },
52
+ },
53
+ Node: {
54
+ fields: {
55
+ __fragments: {
56
+ read: typePolicies.Node.fields.__fragments.read,
57
+ },
58
+ },
59
+ },
60
+ },
61
+ });
62
+ ```
63
+
64
+ - Configure webpack to transform your code by replacing inline GraphQL documents with their compiled artefacts:
65
+
66
+ ```ts
67
+ const {
68
+ createImportDocumentsTransform,
69
+ } = require("@graphitation/apollo-react-relay-duct-tape/lib/storeObservation/createImportDocumentsTransform");
70
+
71
+ const config: webpack.Configuration = {
72
+ module: {
73
+ rules: [
74
+ {
75
+ test: /\.tsx?$/,
76
+ loader: "ts-loader",
77
+ exclude: /node_modules/,
78
+ options: {
79
+ getCustomTransformers: () => ({
80
+ before: [createImportDocumentsTransform()],
81
+ }),
82
+ },
83
+ },
84
+ ],
85
+ },
86
+ };
87
+ ```
88
+
89
+ - TODO: Have a `Node` interface definition
90
+ - TODO: Add `node` root field
91
+
92
+ - Optionally, if you rely on Apollo Client's `@client` directive, be sure to explicitly add it to your local copy of your schema, otherwise the compiler will not accept its use.
93
+
94
+ ```graphql
95
+ directive @client(always: Boolean) on FIELD
96
+ ```
97
+
98
+ ## Usage
99
+
100
+ ### Build
101
+
102
+ In a shell, start the compiler and point it to your schema and source. Depending on the size of the code-base a first run may take a while, but subsequent builds should cached. For developer-expedience, it is advised to run the compiler using the watch mode -- provided you have installed the `watchman` tool.
103
+
104
+ ```
105
+ $ yarn graphitation-compiler \
106
+ --schema ./path/to/schema.graphql \
107
+ --src ./path/to/source \
108
+ --watch
109
+ ```
110
+
111
+ TODO:
112
+
113
+ - Add `Node` interface to type that you want to start a new watch query for
114
+ - Restart compiler
115
+
116
+ ### Runtime
117
+
118
+ TODO:
119
+
120
+ - Add query hook
121
+ - Add fragment hook
122
+ - Import and use typings
123
+
124
+ ## Architecture
125
+
126
+ - Fragment reference variables need to be propagated to child fragment hooks, so refetch hooks can re-use original request variables.
127
+ - This cannot be done through React Context, because a refetch hook needs to be able to [partially] update original variables, which cannot be done with React Context.
128
+ - Instead, we pass these as React props, which are populated through GraphQL as we can know exactly where [child] fragments are being referenced and the data needs to be encoded. The actual resolving of the data is done through the (./packages/apollo-react-relay-duct-tape/src/storeObservation/fragmentReferencesFieldPolicy.ts)[fragmentReferencesFieldPolicy] Apollo Cache field policy.
129
+ - Because we can't just add a Apollo Cache field policy to _any_ type, as we don't even know all types, we add it to the `Node` interface instead. The one other type we can assume to exist is the `Query` type.
@@ -0,0 +1,9 @@
1
+ import type { WatchQueryFetchPolicy as ApolloWatchQueryFetchPolicy } from "@apollo/client";
2
+ import type { FetchPolicy } from "./types";
3
+ /**
4
+ * This is for internal use only.
5
+ */
6
+ declare type PrivateFetchPolicy = FetchPolicy | "no-cache";
7
+ export declare function convertFetchPolicy(fetchPolicy: PrivateFetchPolicy | undefined): ApolloWatchQueryFetchPolicy | undefined;
8
+ export {};
9
+ //# sourceMappingURL=convertFetchPolicy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"convertFetchPolicy.d.ts","sourceRoot":"","sources":["../src/convertFetchPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,qBAAqB,IAAI,2BAA2B,EAAE,MAAM,gBAAgB,CAAC;AAC3F,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,SAAS,CAAC;AAE3C;;GAEG;AACH,aAAK,kBAAkB,GAAG,WAAW,GAAG,UAAU,CAAC;AAanD,wBAAgB,kBAAkB,CAChC,WAAW,EAAE,kBAAkB,GAAG,SAAS,GAC1C,2BAA2B,GAAG,SAAS,CAEzC"}
@@ -0,0 +1,20 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
+ var __export = (target, all) => {
4
+ for (var name in all)
5
+ __defProp(target, name, {get: all[name], enumerable: true});
6
+ };
7
+ __markAsModule(exports);
8
+ __export(exports, {
9
+ convertFetchPolicy: () => convertFetchPolicy
10
+ });
11
+ const FETCH_POLICY_MAPPING = {
12
+ "store-or-network": "cache-first",
13
+ "store-and-network": "cache-and-network",
14
+ "network-only": "network-only",
15
+ "store-only": "cache-only",
16
+ "no-cache": "no-cache"
17
+ };
18
+ function convertFetchPolicy(fetchPolicy) {
19
+ return fetchPolicy && FETCH_POLICY_MAPPING[fetchPolicy];
20
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/convertFetchPolicy.ts"],
4
+ "sourcesContent": ["import type { WatchQueryFetchPolicy as ApolloWatchQueryFetchPolicy } from \"@apollo/client\";\nimport type { FetchPolicy } from \"./types\";\n\n/**\n * This is for internal use only.\n */\ntype PrivateFetchPolicy = FetchPolicy | \"no-cache\";\n\nconst FETCH_POLICY_MAPPING: Record<\n PrivateFetchPolicy,\n ApolloWatchQueryFetchPolicy\n> = {\n \"store-or-network\": \"cache-first\",\n \"store-and-network\": \"cache-and-network\",\n \"network-only\": \"network-only\",\n \"store-only\": \"cache-only\",\n \"no-cache\": \"no-cache\",\n};\n\nexport function convertFetchPolicy(\n fetchPolicy: PrivateFetchPolicy | undefined\n): ApolloWatchQueryFetchPolicy | undefined {\n return fetchPolicy && FETCH_POLICY_MAPPING[fetchPolicy];\n}\n"],
5
+ "mappings": ";;;;;;AAAA;AAAA;AAAA;AAAA;AAQA,MAAM,uBAGF;AAAA,EACF,oBAAoB;AAAA,EACpB,qBAAqB;AAAA,EACrB,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,YAAY;AAAA;AAGP,4BACL,aACyC;AACzC,SAAO,eAAe,qBAAqB;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,14 @@
1
+ // src/convertFetchPolicy.ts
2
+ var FETCH_POLICY_MAPPING = {
3
+ "store-or-network": "cache-first",
4
+ "store-and-network": "cache-and-network",
5
+ "network-only": "network-only",
6
+ "store-only": "cache-only",
7
+ "no-cache": "no-cache"
8
+ };
9
+ function convertFetchPolicy(fetchPolicy) {
10
+ return fetchPolicy && FETCH_POLICY_MAPPING[fetchPolicy];
11
+ }
12
+ export {
13
+ convertFetchPolicy
14
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/convertFetchPolicy.ts"],
4
+ "sourcesContent": ["import type { WatchQueryFetchPolicy as ApolloWatchQueryFetchPolicy } from \"@apollo/client\";\nimport type { FetchPolicy } from \"./types\";\n\n/**\n * This is for internal use only.\n */\ntype PrivateFetchPolicy = FetchPolicy | \"no-cache\";\n\nconst FETCH_POLICY_MAPPING: Record<\n PrivateFetchPolicy,\n ApolloWatchQueryFetchPolicy\n> = {\n \"store-or-network\": \"cache-first\",\n \"store-and-network\": \"cache-and-network\",\n \"network-only\": \"network-only\",\n \"store-only\": \"cache-only\",\n \"no-cache\": \"no-cache\",\n};\n\nexport function convertFetchPolicy(\n fetchPolicy: PrivateFetchPolicy | undefined\n): ApolloWatchQueryFetchPolicy | undefined {\n return fetchPolicy && FETCH_POLICY_MAPPING[fetchPolicy];\n}\n"],
5
+ "mappings": ";AAQA,IAAM,uBAGF;AAAA,EACF,oBAAoB;AAAA,EACpB,qBAAqB;AAAA,EACrB,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,YAAY;AAAA;AAGP,4BACL,aACyC;AACzC,SAAO,eAAe,qBAAqB;AAAA;",
6
+ "names": []
7
+ }
package/lib/hooks.d.ts CHANGED
@@ -1,6 +1,5 @@
1
- import { DocumentNode } from "graphql";
2
- import { KeyType, KeyTypeData, OperationType } from "./types";
3
- export declare type GraphQLTaggedNode = DocumentNode;
1
+ import { FetchPolicy, GraphQLTaggedNode, KeyType, KeyTypeData, OperationType } from "./types";
2
+ import { RefetchFn, PaginationFn } from "./storeObservation/compiledHooks";
4
3
  /**
5
4
  * Executes a GraphQL query.
6
5
  *
@@ -47,7 +46,7 @@ export declare type GraphQLTaggedNode = DocumentNode;
47
46
  * @returns An object with either an error, the result data, or neither while loading.
48
47
  */
49
48
  export declare function useLazyLoadQuery<TQuery extends OperationType>(query: GraphQLTaggedNode, variables: TQuery["variables"], options?: {
50
- fetchPolicy: "cache-first";
49
+ fetchPolicy?: FetchPolicy;
51
50
  }): {
52
51
  error?: Error;
53
52
  data?: TQuery["response"];
@@ -116,7 +115,18 @@ export declare function useLazyLoadQuery<TQuery extends OperationType>(query: Gr
116
115
  * fragment.
117
116
  * @returns The data corresponding to the field selections.
118
117
  */
119
- export declare function useFragment<TKey extends KeyType>(_fragmentInput: GraphQLTaggedNode, fragmentRef: TKey): KeyTypeData<TKey>;
118
+ export declare function useFragment<TKey extends KeyType>(fragmentInput: GraphQLTaggedNode, fragmentRef: TKey): KeyTypeData<TKey>;
119
+ export declare function useRefetchableFragment<TQuery extends OperationType, TKey extends KeyType>(fragmentInput: GraphQLTaggedNode, fragmentRef: TKey): [data: KeyTypeData<TKey>, refetch: RefetchFn<TQuery["variables"]>];
120
+ export declare function usePaginationFragment<TQuery extends OperationType, TKey extends KeyType>(fragmentInput: GraphQLTaggedNode, fragmentRef: TKey): {
121
+ data: KeyTypeData<TKey>;
122
+ loadNext: PaginationFn;
123
+ loadPrevious: PaginationFn;
124
+ hasNext: boolean;
125
+ hasPrevious: boolean;
126
+ isLoadingNext: boolean;
127
+ isLoadingPrevious: boolean;
128
+ refetch: RefetchFn<TQuery["variables"]>;
129
+ };
120
130
  interface GraphQLSubscriptionConfig<TSubscriptionPayload extends OperationType> {
121
131
  subscription: GraphQLTaggedNode;
122
132
  variables: TSubscriptionPayload["variables"];
@@ -1 +1 @@
1
- {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,YAAY,EAAE,MAAM,SAAS,CAAC;AASvC,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,aAAa,EAAa,MAAM,SAAS,CAAC;AAEzE,oBAAY,iBAAiB,GAAG,YAAY,CAAC;AAE7C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,SAAS,aAAa,EAC3D,KAAK,EAAE,iBAAiB,EACxB,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,EAC9B,OAAO,CAAC,EAAE;IAAE,WAAW,EAAE,aAAa,CAAA;CAAE,GACvC;IAAE,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;CAAE,CAE9C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,wBAAgB,WAAW,CAAC,IAAI,SAAS,OAAO,EAC9C,cAAc,EAAE,iBAAiB,EACjC,WAAW,EAAE,IAAI,GAChB,WAAW,CAAC,IAAI,CAAC,CAEnB;AAGD,UAAU,yBAAyB,CACjC,oBAAoB,SAAS,aAAa;IAE1C,YAAY,EAAE,iBAAiB,CAAC;IAChC,SAAS,EAAE,oBAAoB,CAAC,WAAW,CAAC,CAAC;IAC7C;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,oBAAoB,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;IAC9D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,wBAAgB,eAAe,CAAC,oBAAoB,SAAS,aAAa,EACxE,MAAM,EAAE,yBAAyB,CAAC,oBAAoB,CAAC,GACtD,IAAI,CAwBN;AAED,UAAU,yBAAyB,CAAC,gBAAgB,SAAS,aAAa;IACxE,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACzC,kBAAkB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC;CACnE;AAED,aAAK,gBAAgB,CAAC,gBAAgB,SAAS,aAAa,IAAI,CAC9D,OAAO,EAAE,yBAAyB,CAAC,gBAAgB,CAAC,KACjD,OAAO,CAAC;IAAE,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IAAC,IAAI,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAA;CAAE,CAAC,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAgB,WAAW,CAAC,gBAAgB,SAAS,aAAa,EAChE,QAAQ,EAAE,iBAAiB,GAC1B,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC,CAuB/C"}
1
+ {"version":3,"file":"hooks.d.ts","sourceRoot":"","sources":["../src/hooks.ts"],"names":[],"mappings":"AAQA,OAAO,EACL,WAAW,EACX,iBAAiB,EACjB,OAAO,EACP,WAAW,EACX,aAAa,EACd,MAAM,SAAS,CAAC;AACjB,OAAO,EACL,SAAS,EACT,YAAY,EAKb,MAAM,kCAAkC,CAAC;AAG1C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,wBAAgB,gBAAgB,CAAC,MAAM,SAAS,aAAa,EAC3D,KAAK,EAAE,iBAAiB,EACxB,SAAS,EAAE,MAAM,CAAC,WAAW,CAAC,EAC9B,OAAO,CAAC,EAAE;IAAE,WAAW,CAAC,EAAE,WAAW,CAAA;CAAE,GACtC;IAAE,KAAK,CAAC,EAAE,KAAK,CAAC;IAAC,IAAI,CAAC,EAAE,MAAM,CAAC,UAAU,CAAC,CAAA;CAAE,CAa9C;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA+DG;AACH,wBAAgB,WAAW,CAAC,IAAI,SAAS,OAAO,EAC9C,aAAa,EAAE,iBAAiB,EAChC,WAAW,EAAE,IAAI,GAChB,WAAW,CAAC,IAAI,CAAC,CAMnB;AAED,wBAAgB,sBAAsB,CACpC,MAAM,SAAS,aAAa,EAC5B,IAAI,SAAS,OAAO,EAEpB,aAAa,EAAE,iBAAiB,EAChC,WAAW,EAAE,IAAI,GAChB,CAAC,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,EAAE,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC,CASpE;AAED,wBAAgB,qBAAqB,CACnC,MAAM,SAAS,aAAa,EAC5B,IAAI,SAAS,OAAO,EAEpB,aAAa,EAAE,iBAAiB,EAChC,WAAW,EAAE,IAAI,GAChB;IACD,IAAI,EAAE,WAAW,CAAC,IAAI,CAAC,CAAC;IACxB,QAAQ,EAAE,YAAY,CAAC;IACvB,YAAY,EAAE,YAAY,CAAC;IAC3B,OAAO,EAAE,OAAO,CAAC;IACjB,WAAW,EAAE,OAAO,CAAC;IACrB,aAAa,EAAE,OAAO,CAAC;IACvB,iBAAiB,EAAE,OAAO,CAAC;IAC3B,OAAO,EAAE,SAAS,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC,CAAC;CACzC,CASA;AAGD,UAAU,yBAAyB,CACjC,oBAAoB,SAAS,aAAa;IAE1C,YAAY,EAAE,iBAAiB,CAAC;IAChC,SAAS,EAAE,oBAAoB,CAAC,WAAW,CAAC,CAAC;IAC7C;;OAEG;IACH,MAAM,CAAC,EAAE,CAAC,QAAQ,EAAE,oBAAoB,CAAC,UAAU,CAAC,KAAK,IAAI,CAAC;IAC9D,OAAO,CAAC,EAAE,CAAC,KAAK,EAAE,KAAK,KAAK,IAAI,CAAC;CAClC;AAED,wBAAgB,eAAe,CAAC,oBAAoB,SAAS,aAAa,EACxE,MAAM,EAAE,yBAAyB,CAAC,oBAAoB,CAAC,GACtD,IAAI,CA4BN;AAED,UAAU,yBAAyB,CAAC,gBAAgB,SAAS,aAAa;IACxE,SAAS,EAAE,gBAAgB,CAAC,WAAW,CAAC,CAAC;IACzC,kBAAkB,CAAC,EAAE,OAAO,CAAC,gBAAgB,CAAC,UAAU,CAAC,CAAC,GAAG,IAAI,CAAC;CACnE;AAED,aAAK,gBAAgB,CAAC,gBAAgB,SAAS,aAAa,IAAI,CAC9D,OAAO,EAAE,yBAAyB,CAAC,gBAAgB,CAAC,KACjD,OAAO,CAAC;IAAE,MAAM,CAAC,EAAE,KAAK,EAAE,CAAC;IAAC,IAAI,CAAC,EAAE,gBAAgB,CAAC,UAAU,CAAC,CAAA;CAAE,CAAC,CAAC;AAExE;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA8CG;AACH,wBAAgB,WAAW,CAAC,gBAAgB,SAAS,aAAa,EAChE,QAAQ,EAAE,iBAAiB,GAC1B,CAAC,gBAAgB,CAAC,gBAAgB,CAAC,EAAE,OAAO,CAAC,CAwB/C"}
package/lib/hooks.js CHANGED
@@ -59,15 +59,40 @@ __export(exports, {
59
59
  useFragment: () => useFragment,
60
60
  useLazyLoadQuery: () => useLazyLoadQuery,
61
61
  useMutation: () => useMutation,
62
+ usePaginationFragment: () => usePaginationFragment,
63
+ useRefetchableFragment: () => useRefetchableFragment,
62
64
  useSubscription: () => useSubscription
63
65
  });
64
66
  var import_invariant = __toModule(require("invariant"));
65
67
  var import_client = __toModule(require("@apollo/client"));
68
+ var import_compiledHooks = __toModule(require("./storeObservation/compiledHooks"));
69
+ var import_convertFetchPolicy = __toModule(require("./convertFetchPolicy"));
66
70
  function useLazyLoadQuery(query, variables, options) {
67
- return (0, import_client.useQuery)(query, __objSpread({variables}, options));
71
+ const apolloOptions = options && __objSpread(__objSpread({}, options), {
72
+ fetchPolicy: (0, import_convertFetchPolicy.convertFetchPolicy)(options.fetchPolicy)
73
+ });
74
+ if (query.watchQueryDocument) {
75
+ return (0, import_compiledHooks.useCompiledLazyLoadQuery)(query, __objSpread({
76
+ variables
77
+ }, apolloOptions));
78
+ } else {
79
+ return (0, import_client.useQuery)(query, __objSpread({variables}, apolloOptions));
80
+ }
81
+ }
82
+ function useFragment(fragmentInput, fragmentRef) {
83
+ if (fragmentInput.watchQueryDocument) {
84
+ return (0, import_compiledHooks.useCompiledFragment)(fragmentInput, fragmentRef);
85
+ } else {
86
+ return fragmentRef;
87
+ }
88
+ }
89
+ function useRefetchableFragment(fragmentInput, fragmentRef) {
90
+ (0, import_invariant.default)(!!fragmentInput.watchQueryDocument, "useRefetchableFragment is only supported at this time when using compilation");
91
+ return (0, import_compiledHooks.useCompiledRefetchableFragment)(fragmentInput, fragmentRef);
68
92
  }
69
- function useFragment(_fragmentInput, fragmentRef) {
70
- return fragmentRef;
93
+ function usePaginationFragment(fragmentInput, fragmentRef) {
94
+ (0, import_invariant.default)(!!fragmentInput.watchQueryDocument, "usePaginationFragment is only supported at this time when using compilation");
95
+ return (0, import_compiledHooks.useCompiledPaginationFragment)(fragmentInput, fragmentRef);
71
96
  }
72
97
  function useSubscription(config) {
73
98
  const {error} = (0, import_client.useSubscription)(config.subscription, {
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/hooks.ts"],
4
+ "sourcesContent": ["import { DocumentNode } from \"graphql\";\nimport invariant from \"invariant\";\nimport {\n useSubscription as useApolloSubscription,\n useQuery as useApolloQuery,\n useMutation as useApolloMutation,\n} from \"@apollo/client\";\n\nimport {\n FetchPolicy,\n GraphQLTaggedNode,\n KeyType,\n KeyTypeData,\n OperationType,\n} from \"./types\";\nimport {\n RefetchFn,\n PaginationFn,\n useCompiledLazyLoadQuery,\n useCompiledFragment,\n useCompiledRefetchableFragment,\n useCompiledPaginationFragment,\n} from \"./storeObservation/compiledHooks\";\nimport { convertFetchPolicy } from \"./convertFetchPolicy\";\n\n/**\n * Executes a GraphQL query.\n *\n * This hook is called 'lazy' as it is used to fetch a GraphQL query _during_ render. This hook can trigger multiple\n * round trips, one for loading and one for resolving.\n *\n * @see {useFragment} This function largely follows the documentation of `useFragment`, except that this is a root of a\n * GraphQL operation and thus does not take in any props such as opaque fragment references.\n *\n * @example\n ```typescript\n import { graphql, useLazyLoadQuery } from \"@nova-facade/react-graphql\";\n import { SomeReactComponent, fragment as SomeReactComponent_someGraphQLType } from \"./SomeReactComponent\";\n import { SomeRootReactComponentQuery } from \"./__generated__/SomeRootReactComponentQuery.graphql\";\n\n const query = graphql`\n query SomeRootReactComponentQuery {\n someGraphQLType {\n ...SomeReactComponent_someGraphQLType\n }\n }\n ${SomeReactComponent_someGraphQLType}\n `;\n\n export const SomeRootReactComponent: React.FC = () => {\n const result = useLazyLoadQuery<SomeRootReactComponentQuery>(query);\n if (result.error) {\n throw result.error;\n } else if (!result.data) {\n // Loading\n return null;\n }\n\n return (\n <SomeReactComponent someGraphQLType={result.data.someGraphQLType} />\n );\n };\n ```\n *\n * @param query The query operation to perform.\n * @param variables Object containing the variable values to fetch the query. These variables need to match GraphQL\n * variables declared inside the query.\n * @param options Options passed on to the underlying implementation.\n * @returns An object with either an error, the result data, or neither while loading.\n */\nexport function useLazyLoadQuery<TQuery extends OperationType>(\n query: GraphQLTaggedNode,\n variables: TQuery[\"variables\"],\n options?: { fetchPolicy?: FetchPolicy }\n): { error?: Error; data?: TQuery[\"response\"] } {\n const apolloOptions = options && {\n ...options,\n fetchPolicy: convertFetchPolicy(options.fetchPolicy),\n };\n if (query.watchQueryDocument) {\n return useCompiledLazyLoadQuery(query as any, {\n variables,\n ...apolloOptions,\n });\n } else {\n return useApolloQuery(query, { variables, ...apolloOptions });\n }\n}\n\n/**\n * A first-class way for an individual component to express its direct data requirements using GraphQL. The fragment\n * should select all the fields that the component directly uses in its rendering or needs to pass to external\n * functions. It should *not* select data that its children need, unless those children are intended to remain their\n * pure React props as data inputs.\n *\n * For children that *do* have their own data requirements expressed using GraphQL, the fragment should ensure to\n * spread in the child's fragment.\n *\n * For each fragment defined using the `graphql` tagged template function, the Nova graphql-compiler will emit\n * TypeScript typings that correspond to the selected fields and referenced child component fragments. These typings\n * live in files in the sibling `./__generated__/` directory and are called after the fragment name. The compiler will\n * enforce some constraints about the fragment name, such that it starts with the name of the file it is defined in\n * (i.e. the name of the component) and ends with the name of the fragment reference prop that this component takes in\n * (which typically will be named after the GraphQL type that the fragment is defined on).\n *\n * The typing that has a `$key` suffix is meant to be used for the opaque fragment reference prop, whereas the typing\n * without a suffix describes the actual data and is only meant for usage internally to the file. When the opaque\n * fragment reference prop is passed to a `useFragment` call, the returned data will be unmasked and be typed according\n * to the typing without a suffix. As such, the unmasked typing is only ever needed when extracting pieces of the\n * component to the file scope. For functions extracted to different files, however, you should type those separately\n * and *not* use the emitted typings.\n *\n * @example\n ```typescript\n import { graphql, useFragment } from \"@nova-facade/react-graphql\";\n import { SomeChildReactComponent, fragment as SomeChildReactComponent_someGraphQLType } from \"./SomeChildReactComponent\";\n import { SomeReactComponent_someGraphQLType$key } from \"./__generated__/SomeReactComponent_someGraphQLType.graphql\";\n\n export const fragment = graphql`\n fragment SomeReactComponent_someGraphQLType on SomeGraphQLType {\n someDataThatThisComponentNeeds\n ...SomeChildReactComponent_someGraphQLType\n }\n ${SomeChildReactComponent_someGraphQLType}\n `;\n\n export interface SomeReactComponentProps {\n someGraphQLType: SomeReactComponent_someGraphQLType$key;\n }\n\n export const SomeReactComponent: React.FunctionComponent<SomeReactComponentProps> = props => {\n const someGraphQLType = useFragment(fragment, props.someGraphQLType);\n return (\n <div>\n <span>{someGraphQLType.someDataThatThisComponentNeeds}</span>\n <SomeChildReactComponent someGraphQLType={someGraphQLType} />\n </div>\n );\n }\n ```\n *\n * @note For now, the fragment objects should be exported such that parent's can interpolate them into their own\n * GraphQL documents. This may change in the future when/if we entirely switch to static compilation and will\n * allow us to also move the usage of the graphql tagged template function inline at the `useFragment` call-site.\n *\n * @todo 1613321: Connect useFragment hooks directly to a GraphQL client store for targeted updates. Currently the data\n * is simply unmasked at compile-time but otherwise passed through from the parent at run-time.\n *\n * @param _fragmentInput The GraphQL fragment document created using the `graphql` tagged template function.\n * @param fragmentRef The opaque fragment reference passed in by a parent component that has spread in this component's\n * fragment.\n * @returns The data corresponding to the field selections.\n */\nexport function useFragment<TKey extends KeyType>(\n fragmentInput: GraphQLTaggedNode,\n fragmentRef: TKey\n): KeyTypeData<TKey> {\n if (fragmentInput.watchQueryDocument) {\n return useCompiledFragment(fragmentInput, fragmentRef as any);\n } else {\n return fragmentRef as unknown;\n }\n}\n\nexport function useRefetchableFragment<\n TQuery extends OperationType,\n TKey extends KeyType\n>(\n fragmentInput: GraphQLTaggedNode,\n fragmentRef: TKey\n): [data: KeyTypeData<TKey>, refetch: RefetchFn<TQuery[\"variables\"]>] {\n invariant(\n !!fragmentInput.watchQueryDocument,\n \"useRefetchableFragment is only supported at this time when using compilation\"\n );\n return useCompiledRefetchableFragment(\n fragmentInput as any,\n fragmentRef as any\n );\n}\n\nexport function usePaginationFragment<\n TQuery extends OperationType,\n TKey extends KeyType\n>(\n fragmentInput: GraphQLTaggedNode,\n fragmentRef: TKey\n): {\n data: KeyTypeData<TKey>;\n loadNext: PaginationFn;\n loadPrevious: PaginationFn;\n hasNext: boolean;\n hasPrevious: boolean;\n isLoadingNext: boolean;\n isLoadingPrevious: boolean;\n refetch: RefetchFn<TQuery[\"variables\"]>;\n} {\n invariant(\n !!fragmentInput.watchQueryDocument,\n \"usePaginationFragment is only supported at this time when using compilation\"\n );\n return useCompiledPaginationFragment(\n fragmentInput as any,\n fragmentRef as any\n );\n}\n\n// https://github.com/facebook/relay/blob/master/website/docs/api-reference/types/GraphQLSubscriptionConfig.md\ninterface GraphQLSubscriptionConfig<\n TSubscriptionPayload extends OperationType\n> {\n subscription: GraphQLTaggedNode;\n variables: TSubscriptionPayload[\"variables\"];\n /**\n * Should response be nullable?\n */\n onNext?: (response: TSubscriptionPayload[\"response\"]) => void;\n onError?: (error: Error) => void;\n}\n\nexport function useSubscription<TSubscriptionPayload extends OperationType>(\n config: GraphQLSubscriptionConfig<TSubscriptionPayload>\n): void {\n const { error } = useApolloSubscription(\n // TODO: Right now we don't replace mutation documents with imported artefacts.\n config.subscription as DocumentNode,\n {\n variables: config.variables,\n onSubscriptionData: ({ subscriptionData }) => {\n // Supposedly this never gets triggered for an error by design:\n // https://github.com/apollographql/react-apollo/issues/3177#issuecomment-506758144\n invariant(\n !subscriptionData.error,\n \"Did not expect to receive an error here\"\n );\n if (subscriptionData.data && config.onNext) {\n config.onNext(subscriptionData.data);\n }\n },\n }\n );\n if (error) {\n if (config.onError) {\n config.onError(error);\n } else {\n console.warn(\n `An unhandled GraphQL subscription error occurred: ${error.message}`\n );\n }\n }\n}\n\ninterface IMutationCommitterOptions<TMutationPayload extends OperationType> {\n variables: TMutationPayload[\"variables\"];\n optimisticResponse?: Partial<TMutationPayload[\"response\"]> | null;\n}\n\ntype MutationCommiter<TMutationPayload extends OperationType> = (\n options: IMutationCommitterOptions<TMutationPayload>\n) => Promise<{ errors?: Error[]; data?: TMutationPayload[\"response\"] }>;\n\n/**\n * Declare use of a mutation within component. Returns an array of a function and loading state boolean.\n *\n * Returned function can be called to perform the actual mutation with provided variables.\n *\n * @param mutation Mutation document\n * @returns [commitMutationFn, isInFlight]\n *\n * commitMutationFn\n * @param options.variables map of variables to pass to mutation\n * @param options.optimisticResponse proposed response to apply to the store while mutation is in flight\n * @returns A Promise to an object with either errors or/and the result data\n * \n * Example\n ```\n\n const mutation = graphql`\n mutation SomeReactComponentMutation($newName: String!) {\n someMutation(newName: $newName) {\n __typeName\n id\n newName\n }\n }\n `\n\n export const SomeReactComponent: React.FunctionComponent<SomeReactComponentProps> = props => {\n const [commitMutation, isInFlight] = useMutation(mutation);\n return (\n <div>\n <button onClick={() => commitMutation({\n variables: {\n newName: \"foo\"\n },\n optimisticResponse: {\n someMutation: {\n __typename: \"SomeMutationPayload\",\n id: \"1\",\n newName: \"foo\",\n }\n }\n })} disabled={isInFlight}/>\n </div>\n );\n }\n ```\n */\nexport function useMutation<TMutationPayload extends OperationType>(\n mutation: GraphQLTaggedNode\n): [MutationCommiter<TMutationPayload>, boolean] {\n const [apolloUpdater, { loading: mutationLoading }] = useApolloMutation(\n // TODO: Right now we don't replace mutation documents with imported artefacts.\n mutation as DocumentNode\n );\n\n return [\n async (options: IMutationCommitterOptions<TMutationPayload>) => {\n const apolloResult = await apolloUpdater({\n variables: options.variables || {},\n optimisticResponse: options.optimisticResponse,\n });\n if (apolloResult.errors) {\n return {\n errors: Array.from(Object.values(apolloResult.errors)),\n data: apolloResult.data,\n };\n }\n return {\n data: apolloResult.data,\n };\n },\n mutationLoading,\n ];\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,uBAAsB;AACtB,oBAIO;AASP,2BAOO;AACP,gCAAmC;AA+C5B,0BACL,OACA,WACA,SAC8C;AAC9C,QAAM,gBAAgB,WAAW,4BAC5B,UAD4B;AAAA,IAE/B,aAAa,kDAAmB,QAAQ;AAAA;AAE1C,MAAI,MAAM,oBAAoB;AAC5B,WAAO,mDAAyB,OAAc;AAAA,MAC5C;AAAA,OACG;AAAA,SAEA;AACL,WAAO,4BAAe,OAAO,aAAE,YAAc;AAAA;AAAA;AAoE1C,qBACL,eACA,aACmB;AACnB,MAAI,cAAc,oBAAoB;AACpC,WAAO,8CAAoB,eAAe;AAAA,SACrC;AACL,WAAO;AAAA;AAAA;AAIJ,gCAIL,eACA,aACoE;AACpE,gCACE,CAAC,CAAC,cAAc,oBAChB;AAEF,SAAO,yDACL,eACA;AAAA;AAIG,+BAIL,eACA,aAUA;AACA,gCACE,CAAC,CAAC,cAAc,oBAChB;AAEF,SAAO,wDACL,eACA;AAAA;AAiBG,yBACL,QACM;AACN,QAAM,CAAE,SAAU,mCAEhB,OAAO,cACP;AAAA,IACE,WAAW,OAAO;AAAA,IAClB,oBAAoB,CAAC,CAAE,sBAAuB;AAG5C,oCACE,CAAC,iBAAiB,OAClB;AAEF,UAAI,iBAAiB,QAAQ,OAAO,QAAQ;AAC1C,eAAO,OAAO,iBAAiB;AAAA;AAAA;AAAA;AAKvC,MAAI,OAAO;AACT,QAAI,OAAO,SAAS;AAClB,aAAO,QAAQ;AAAA,WACV;AACL,cAAQ,KACN,qDAAqD,MAAM;AAAA;AAAA;AAAA;AA8D5D,qBACL,UAC+C;AAC/C,QAAM,CAAC,eAAe,CAAE,SAAS,oBAAqB,+BAEpD;AAGF,SAAO;AAAA,IACL,CAAO,YAAyD;AAC9D,YAAM,eAAe,MAAM,cAAc;AAAA,QACvC,WAAW,QAAQ,aAAa;AAAA,QAChC,oBAAoB,QAAQ;AAAA;AAE9B,UAAI,aAAa,QAAQ;AACvB,eAAO;AAAA,UACL,QAAQ,MAAM,KAAK,OAAO,OAAO,aAAa;AAAA,UAC9C,MAAM,aAAa;AAAA;AAAA;AAGvB,aAAO;AAAA,QACL,MAAM,aAAa;AAAA;AAAA;AAAA,IAGvB;AAAA;AAAA;",
6
+ "names": []
7
+ }
package/lib/hooks.mjs CHANGED
@@ -42,11 +42,39 @@ import {
42
42
  useQuery as useApolloQuery,
43
43
  useMutation as useApolloMutation
44
44
  } from "@apollo/client";
45
+ import {
46
+ useCompiledLazyLoadQuery,
47
+ useCompiledFragment,
48
+ useCompiledRefetchableFragment,
49
+ useCompiledPaginationFragment
50
+ } from "./storeObservation/compiledHooks.mjs";
51
+ import {convertFetchPolicy} from "./convertFetchPolicy.mjs";
45
52
  function useLazyLoadQuery(query, variables, options) {
46
- return useApolloQuery(query, __objSpread({variables}, options));
53
+ const apolloOptions = options && __objSpread(__objSpread({}, options), {
54
+ fetchPolicy: convertFetchPolicy(options.fetchPolicy)
55
+ });
56
+ if (query.watchQueryDocument) {
57
+ return useCompiledLazyLoadQuery(query, __objSpread({
58
+ variables
59
+ }, apolloOptions));
60
+ } else {
61
+ return useApolloQuery(query, __objSpread({variables}, apolloOptions));
62
+ }
63
+ }
64
+ function useFragment(fragmentInput, fragmentRef) {
65
+ if (fragmentInput.watchQueryDocument) {
66
+ return useCompiledFragment(fragmentInput, fragmentRef);
67
+ } else {
68
+ return fragmentRef;
69
+ }
70
+ }
71
+ function useRefetchableFragment(fragmentInput, fragmentRef) {
72
+ invariant(!!fragmentInput.watchQueryDocument, "useRefetchableFragment is only supported at this time when using compilation");
73
+ return useCompiledRefetchableFragment(fragmentInput, fragmentRef);
47
74
  }
48
- function useFragment(_fragmentInput, fragmentRef) {
49
- return fragmentRef;
75
+ function usePaginationFragment(fragmentInput, fragmentRef) {
76
+ invariant(!!fragmentInput.watchQueryDocument, "usePaginationFragment is only supported at this time when using compilation");
77
+ return useCompiledPaginationFragment(fragmentInput, fragmentRef);
50
78
  }
51
79
  function useSubscription(config) {
52
80
  const {error} = useApolloSubscription(config.subscription, {
@@ -91,5 +119,7 @@ export {
91
119
  useFragment,
92
120
  useLazyLoadQuery,
93
121
  useMutation,
122
+ usePaginationFragment,
123
+ useRefetchableFragment,
94
124
  useSubscription
95
125
  };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/hooks.ts"],
4
+ "sourcesContent": ["import { DocumentNode } from \"graphql\";\nimport invariant from \"invariant\";\nimport {\n useSubscription as useApolloSubscription,\n useQuery as useApolloQuery,\n useMutation as useApolloMutation,\n} from \"@apollo/client\";\n\nimport {\n FetchPolicy,\n GraphQLTaggedNode,\n KeyType,\n KeyTypeData,\n OperationType,\n} from \"./types\";\nimport {\n RefetchFn,\n PaginationFn,\n useCompiledLazyLoadQuery,\n useCompiledFragment,\n useCompiledRefetchableFragment,\n useCompiledPaginationFragment,\n} from \"./storeObservation/compiledHooks\";\nimport { convertFetchPolicy } from \"./convertFetchPolicy\";\n\n/**\n * Executes a GraphQL query.\n *\n * This hook is called 'lazy' as it is used to fetch a GraphQL query _during_ render. This hook can trigger multiple\n * round trips, one for loading and one for resolving.\n *\n * @see {useFragment} This function largely follows the documentation of `useFragment`, except that this is a root of a\n * GraphQL operation and thus does not take in any props such as opaque fragment references.\n *\n * @example\n ```typescript\n import { graphql, useLazyLoadQuery } from \"@nova-facade/react-graphql\";\n import { SomeReactComponent, fragment as SomeReactComponent_someGraphQLType } from \"./SomeReactComponent\";\n import { SomeRootReactComponentQuery } from \"./__generated__/SomeRootReactComponentQuery.graphql\";\n\n const query = graphql`\n query SomeRootReactComponentQuery {\n someGraphQLType {\n ...SomeReactComponent_someGraphQLType\n }\n }\n ${SomeReactComponent_someGraphQLType}\n `;\n\n export const SomeRootReactComponent: React.FC = () => {\n const result = useLazyLoadQuery<SomeRootReactComponentQuery>(query);\n if (result.error) {\n throw result.error;\n } else if (!result.data) {\n // Loading\n return null;\n }\n\n return (\n <SomeReactComponent someGraphQLType={result.data.someGraphQLType} />\n );\n };\n ```\n *\n * @param query The query operation to perform.\n * @param variables Object containing the variable values to fetch the query. These variables need to match GraphQL\n * variables declared inside the query.\n * @param options Options passed on to the underlying implementation.\n * @returns An object with either an error, the result data, or neither while loading.\n */\nexport function useLazyLoadQuery<TQuery extends OperationType>(\n query: GraphQLTaggedNode,\n variables: TQuery[\"variables\"],\n options?: { fetchPolicy?: FetchPolicy }\n): { error?: Error; data?: TQuery[\"response\"] } {\n const apolloOptions = options && {\n ...options,\n fetchPolicy: convertFetchPolicy(options.fetchPolicy),\n };\n if (query.watchQueryDocument) {\n return useCompiledLazyLoadQuery(query as any, {\n variables,\n ...apolloOptions,\n });\n } else {\n return useApolloQuery(query, { variables, ...apolloOptions });\n }\n}\n\n/**\n * A first-class way for an individual component to express its direct data requirements using GraphQL. The fragment\n * should select all the fields that the component directly uses in its rendering or needs to pass to external\n * functions. It should *not* select data that its children need, unless those children are intended to remain their\n * pure React props as data inputs.\n *\n * For children that *do* have their own data requirements expressed using GraphQL, the fragment should ensure to\n * spread in the child's fragment.\n *\n * For each fragment defined using the `graphql` tagged template function, the Nova graphql-compiler will emit\n * TypeScript typings that correspond to the selected fields and referenced child component fragments. These typings\n * live in files in the sibling `./__generated__/` directory and are called after the fragment name. The compiler will\n * enforce some constraints about the fragment name, such that it starts with the name of the file it is defined in\n * (i.e. the name of the component) and ends with the name of the fragment reference prop that this component takes in\n * (which typically will be named after the GraphQL type that the fragment is defined on).\n *\n * The typing that has a `$key` suffix is meant to be used for the opaque fragment reference prop, whereas the typing\n * without a suffix describes the actual data and is only meant for usage internally to the file. When the opaque\n * fragment reference prop is passed to a `useFragment` call, the returned data will be unmasked and be typed according\n * to the typing without a suffix. As such, the unmasked typing is only ever needed when extracting pieces of the\n * component to the file scope. For functions extracted to different files, however, you should type those separately\n * and *not* use the emitted typings.\n *\n * @example\n ```typescript\n import { graphql, useFragment } from \"@nova-facade/react-graphql\";\n import { SomeChildReactComponent, fragment as SomeChildReactComponent_someGraphQLType } from \"./SomeChildReactComponent\";\n import { SomeReactComponent_someGraphQLType$key } from \"./__generated__/SomeReactComponent_someGraphQLType.graphql\";\n\n export const fragment = graphql`\n fragment SomeReactComponent_someGraphQLType on SomeGraphQLType {\n someDataThatThisComponentNeeds\n ...SomeChildReactComponent_someGraphQLType\n }\n ${SomeChildReactComponent_someGraphQLType}\n `;\n\n export interface SomeReactComponentProps {\n someGraphQLType: SomeReactComponent_someGraphQLType$key;\n }\n\n export const SomeReactComponent: React.FunctionComponent<SomeReactComponentProps> = props => {\n const someGraphQLType = useFragment(fragment, props.someGraphQLType);\n return (\n <div>\n <span>{someGraphQLType.someDataThatThisComponentNeeds}</span>\n <SomeChildReactComponent someGraphQLType={someGraphQLType} />\n </div>\n );\n }\n ```\n *\n * @note For now, the fragment objects should be exported such that parent's can interpolate them into their own\n * GraphQL documents. This may change in the future when/if we entirely switch to static compilation and will\n * allow us to also move the usage of the graphql tagged template function inline at the `useFragment` call-site.\n *\n * @todo 1613321: Connect useFragment hooks directly to a GraphQL client store for targeted updates. Currently the data\n * is simply unmasked at compile-time but otherwise passed through from the parent at run-time.\n *\n * @param _fragmentInput The GraphQL fragment document created using the `graphql` tagged template function.\n * @param fragmentRef The opaque fragment reference passed in by a parent component that has spread in this component's\n * fragment.\n * @returns The data corresponding to the field selections.\n */\nexport function useFragment<TKey extends KeyType>(\n fragmentInput: GraphQLTaggedNode,\n fragmentRef: TKey\n): KeyTypeData<TKey> {\n if (fragmentInput.watchQueryDocument) {\n return useCompiledFragment(fragmentInput, fragmentRef as any);\n } else {\n return fragmentRef as unknown;\n }\n}\n\nexport function useRefetchableFragment<\n TQuery extends OperationType,\n TKey extends KeyType\n>(\n fragmentInput: GraphQLTaggedNode,\n fragmentRef: TKey\n): [data: KeyTypeData<TKey>, refetch: RefetchFn<TQuery[\"variables\"]>] {\n invariant(\n !!fragmentInput.watchQueryDocument,\n \"useRefetchableFragment is only supported at this time when using compilation\"\n );\n return useCompiledRefetchableFragment(\n fragmentInput as any,\n fragmentRef as any\n );\n}\n\nexport function usePaginationFragment<\n TQuery extends OperationType,\n TKey extends KeyType\n>(\n fragmentInput: GraphQLTaggedNode,\n fragmentRef: TKey\n): {\n data: KeyTypeData<TKey>;\n loadNext: PaginationFn;\n loadPrevious: PaginationFn;\n hasNext: boolean;\n hasPrevious: boolean;\n isLoadingNext: boolean;\n isLoadingPrevious: boolean;\n refetch: RefetchFn<TQuery[\"variables\"]>;\n} {\n invariant(\n !!fragmentInput.watchQueryDocument,\n \"usePaginationFragment is only supported at this time when using compilation\"\n );\n return useCompiledPaginationFragment(\n fragmentInput as any,\n fragmentRef as any\n );\n}\n\n// https://github.com/facebook/relay/blob/master/website/docs/api-reference/types/GraphQLSubscriptionConfig.md\ninterface GraphQLSubscriptionConfig<\n TSubscriptionPayload extends OperationType\n> {\n subscription: GraphQLTaggedNode;\n variables: TSubscriptionPayload[\"variables\"];\n /**\n * Should response be nullable?\n */\n onNext?: (response: TSubscriptionPayload[\"response\"]) => void;\n onError?: (error: Error) => void;\n}\n\nexport function useSubscription<TSubscriptionPayload extends OperationType>(\n config: GraphQLSubscriptionConfig<TSubscriptionPayload>\n): void {\n const { error } = useApolloSubscription(\n // TODO: Right now we don't replace mutation documents with imported artefacts.\n config.subscription as DocumentNode,\n {\n variables: config.variables,\n onSubscriptionData: ({ subscriptionData }) => {\n // Supposedly this never gets triggered for an error by design:\n // https://github.com/apollographql/react-apollo/issues/3177#issuecomment-506758144\n invariant(\n !subscriptionData.error,\n \"Did not expect to receive an error here\"\n );\n if (subscriptionData.data && config.onNext) {\n config.onNext(subscriptionData.data);\n }\n },\n }\n );\n if (error) {\n if (config.onError) {\n config.onError(error);\n } else {\n console.warn(\n `An unhandled GraphQL subscription error occurred: ${error.message}`\n );\n }\n }\n}\n\ninterface IMutationCommitterOptions<TMutationPayload extends OperationType> {\n variables: TMutationPayload[\"variables\"];\n optimisticResponse?: Partial<TMutationPayload[\"response\"]> | null;\n}\n\ntype MutationCommiter<TMutationPayload extends OperationType> = (\n options: IMutationCommitterOptions<TMutationPayload>\n) => Promise<{ errors?: Error[]; data?: TMutationPayload[\"response\"] }>;\n\n/**\n * Declare use of a mutation within component. Returns an array of a function and loading state boolean.\n *\n * Returned function can be called to perform the actual mutation with provided variables.\n *\n * @param mutation Mutation document\n * @returns [commitMutationFn, isInFlight]\n *\n * commitMutationFn\n * @param options.variables map of variables to pass to mutation\n * @param options.optimisticResponse proposed response to apply to the store while mutation is in flight\n * @returns A Promise to an object with either errors or/and the result data\n * \n * Example\n ```\n\n const mutation = graphql`\n mutation SomeReactComponentMutation($newName: String!) {\n someMutation(newName: $newName) {\n __typeName\n id\n newName\n }\n }\n `\n\n export const SomeReactComponent: React.FunctionComponent<SomeReactComponentProps> = props => {\n const [commitMutation, isInFlight] = useMutation(mutation);\n return (\n <div>\n <button onClick={() => commitMutation({\n variables: {\n newName: \"foo\"\n },\n optimisticResponse: {\n someMutation: {\n __typename: \"SomeMutationPayload\",\n id: \"1\",\n newName: \"foo\",\n }\n }\n })} disabled={isInFlight}/>\n </div>\n );\n }\n ```\n */\nexport function useMutation<TMutationPayload extends OperationType>(\n mutation: GraphQLTaggedNode\n): [MutationCommiter<TMutationPayload>, boolean] {\n const [apolloUpdater, { loading: mutationLoading }] = useApolloMutation(\n // TODO: Right now we don't replace mutation documents with imported artefacts.\n mutation as DocumentNode\n );\n\n return [\n async (options: IMutationCommitterOptions<TMutationPayload>) => {\n const apolloResult = await apolloUpdater({\n variables: options.variables || {},\n optimisticResponse: options.optimisticResponse,\n });\n if (apolloResult.errors) {\n return {\n errors: Array.from(Object.values(apolloResult.errors)),\n data: apolloResult.data,\n };\n }\n return {\n data: apolloResult.data,\n };\n },\n mutationLoading,\n ];\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AACA;AACA;AAAA;AAAA;AAAA;AAAA;AAaA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA;AA+CO,0BACL,OACA,WACA,SAC8C;AAC9C,QAAM,gBAAgB,WAAW,4BAC5B,UAD4B;AAAA,IAE/B,aAAa,mBAAmB,QAAQ;AAAA;AAE1C,MAAI,MAAM,oBAAoB;AAC5B,WAAO,yBAAyB,OAAc;AAAA,MAC5C;AAAA,OACG;AAAA,SAEA;AACL,WAAO,eAAe,OAAO,aAAE,YAAc;AAAA;AAAA;AAoE1C,qBACL,eACA,aACmB;AACnB,MAAI,cAAc,oBAAoB;AACpC,WAAO,oBAAoB,eAAe;AAAA,SACrC;AACL,WAAO;AAAA;AAAA;AAIJ,gCAIL,eACA,aACoE;AACpE,YACE,CAAC,CAAC,cAAc,oBAChB;AAEF,SAAO,+BACL,eACA;AAAA;AAIG,+BAIL,eACA,aAUA;AACA,YACE,CAAC,CAAC,cAAc,oBAChB;AAEF,SAAO,8BACL,eACA;AAAA;AAiBG,yBACL,QACM;AACN,QAAM,CAAE,SAAU,sBAEhB,OAAO,cACP;AAAA,IACE,WAAW,OAAO;AAAA,IAClB,oBAAoB,CAAC,CAAE,sBAAuB;AAG5C,gBACE,CAAC,iBAAiB,OAClB;AAEF,UAAI,iBAAiB,QAAQ,OAAO,QAAQ;AAC1C,eAAO,OAAO,iBAAiB;AAAA;AAAA;AAAA;AAKvC,MAAI,OAAO;AACT,QAAI,OAAO,SAAS;AAClB,aAAO,QAAQ;AAAA,WACV;AACL,cAAQ,KACN,qDAAqD,MAAM;AAAA;AAAA;AAAA;AA8D5D,qBACL,UAC+C;AAC/C,QAAM,CAAC,eAAe,CAAE,SAAS,oBAAqB,kBAEpD;AAGF,SAAO;AAAA,IACL,CAAO,YAAyD;AAC9D,YAAM,eAAe,MAAM,cAAc;AAAA,QACvC,WAAW,QAAQ,aAAa;AAAA,QAChC,oBAAoB,QAAQ;AAAA;AAE9B,UAAI,aAAa,QAAQ;AACvB,eAAO;AAAA,UACL,QAAQ,MAAM,KAAK,OAAO,OAAO,aAAa;AAAA,UAC9C,MAAM,aAAa;AAAA;AAAA;AAGvB,aAAO;AAAA,QACL,MAAM,aAAa;AAAA;AAAA;AAAA,IAGvB;AAAA;AAAA;",
6
+ "names": []
7
+ }
package/lib/index.d.ts CHANGED
@@ -1,3 +1,4 @@
1
1
  export * from "./hooks";
2
2
  export * from "./types";
3
+ export * from "./storeObservation";
3
4
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,cAAc,SAAS,CAAC;AACxB,cAAc,SAAS,CAAC;AACxB,cAAc,oBAAoB,CAAC"}
package/lib/index.js CHANGED
@@ -19,3 +19,4 @@ var __toModule = (module2) => {
19
19
  __markAsModule(exports);
20
20
  __reExport(exports, __toModule(require("./hooks")));
21
21
  __reExport(exports, __toModule(require("./types")));
22
+ __reExport(exports, __toModule(require("./storeObservation")));
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["export * from \"./hooks\";\nexport * from \"./types\";\nexport * from \"./storeObservation\";\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA;AAAA,oBAAc;AACd,oBAAc;AACd,oBAAc;",
6
+ "names": []
7
+ }
package/lib/index.mjs CHANGED
@@ -1,3 +1,4 @@
1
1
  // src/index.ts
2
2
  export * from "./hooks.mjs";
3
3
  export * from "./types.mjs";
4
+ export * from "./storeObservation.mjs";
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["export * from \"./hooks\";\nexport * from \"./types\";\nexport * from \"./storeObservation\";\n"],
5
+ "mappings": ";AAAA;AACA;AACA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,18 @@
1
+ import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
2
+ export declare type compiledHooks_BackwardPaginationFragment = {
3
+ readonly messages: {
4
+ readonly edges: ReadonlyArray<{
5
+ readonly node: {
6
+ readonly text: string;
7
+ };
8
+ }>;
9
+ };
10
+ readonly id: string;
11
+ readonly " $refType": "compiledHooks_BackwardPaginationFragment";
12
+ };
13
+ export declare type compiledHooks_BackwardPaginationFragment$data = compiledHooks_BackwardPaginationFragment;
14
+ export declare type compiledHooks_BackwardPaginationFragment$key = {
15
+ readonly " $data"?: compiledHooks_BackwardPaginationFragment$data;
16
+ readonly " $fragmentRefs": FragmentRefs<"compiledHooks_BackwardPaginationFragment">;
17
+ };
18
+ //# sourceMappingURL=compiledHooks_BackwardPaginationFragment.graphql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiledHooks_BackwardPaginationFragment.graphql.d.ts","sourceRoot":"","sources":["../../../src/storeObservation/__generated__/compiledHooks_BackwardPaginationFragment.graphql.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAC1E,oBAAY,wCAAwC,GAAG;IACnD,QAAQ,CAAC,QAAQ,EAAE;QACf,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC;YAC1B,QAAQ,CAAC,IAAI,EAAE;gBACX,QAAQ,CAAC,IAAI,EAAE,MAAM,CAAC;aACzB,CAAC;SACL,CAAC,CAAC;KACN,CAAC;IACF,QAAQ,CAAC,EAAE,EAAE,MAAM,CAAC;IACpB,QAAQ,CAAC,WAAW,EAAE,0CAA0C,CAAC;CACpE,CAAC;AACF,oBAAY,6CAA6C,GAAG,wCAAwC,CAAC;AACrG,oBAAY,4CAA4C,GAAG;IACvD,QAAQ,CAAC,QAAQ,CAAC,EAAE,6CAA6C,CAAC;IAClE,QAAQ,CAAC,gBAAgB,EAAE,YAAY,CAAC,0CAA0C,CAAC,CAAC;CACvF,CAAC"}
@@ -0,0 +1,4 @@
1
+ var __defProp = Object.defineProperty;
2
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
3
+ __markAsModule(exports);
4
+ ;
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../src/storeObservation/__generated__/compiledHooks_BackwardPaginationFragment.graphql.ts"],
4
+ "sourcesContent": ["/* tslint:disable */\n/* eslint-disable */\n// @ts-nocheck\n;\n\nimport { FragmentRefs } from \"@graphitation/apollo-react-relay-duct-tape\";\nexport type compiledHooks_BackwardPaginationFragment = {\n readonly messages: {\n readonly edges: ReadonlyArray<{\n readonly node: {\n readonly text: string;\n };\n }>;\n };\n readonly id: string;\n readonly \" $refType\": \"compiledHooks_BackwardPaginationFragment\";\n};\nexport type compiledHooks_BackwardPaginationFragment$data = compiledHooks_BackwardPaginationFragment;\nexport type compiledHooks_BackwardPaginationFragment$key = {\n readonly \" $data\"?: compiledHooks_BackwardPaginationFragment$data;\n readonly \" $fragmentRefs\": FragmentRefs<\"compiledHooks_BackwardPaginationFragment\">;\n};\n"],
5
+ "mappings": ";;AAAA;AAGA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": [],
4
+ "sourcesContent": [],
5
+ "mappings": "",
6
+ "names": []
7
+ }
@@ -0,0 +1,17 @@
1
+ import { FragmentRefs } from "@graphitation/apollo-react-relay-duct-tape";
2
+ export declare type compiledHooks_BackwardPaginationFragment_PaginationQueryVariables = {
3
+ messagesBackwardCount: number;
4
+ messagesBeforeCursor: string;
5
+ id: string;
6
+ };
7
+ export declare type compiledHooks_BackwardPaginationFragment_PaginationQueryResponse = {
8
+ readonly node: {
9
+ readonly " $fragmentRefs": FragmentRefs<"compiledHooks_BackwardPaginationFragment">;
10
+ } | null;
11
+ };
12
+ export declare type compiledHooks_BackwardPaginationFragment_PaginationQuery = {
13
+ readonly response: compiledHooks_BackwardPaginationFragment_PaginationQueryResponse;
14
+ readonly variables: compiledHooks_BackwardPaginationFragment_PaginationQueryVariables;
15
+ };
16
+ export declare const documents: import("relay-compiler-language-graphitation").CompiledArtefactModule;
17
+ //# sourceMappingURL=compiledHooks_BackwardPaginationFragment_PaginationQuery.graphql.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"compiledHooks_BackwardPaginationFragment_PaginationQuery.graphql.d.ts","sourceRoot":"","sources":["../../../src/storeObservation/__generated__/compiledHooks_BackwardPaginationFragment_PaginationQuery.graphql.ts"],"names":[],"mappings":"AAKA,OAAO,EAAE,YAAY,EAAE,MAAM,4CAA4C,CAAC;AAC1E,oBAAY,iEAAiE,GAAG;IAC5E,qBAAqB,EAAE,MAAM,CAAC;IAC9B,oBAAoB,EAAE,MAAM,CAAC;IAC7B,EAAE,EAAE,MAAM,CAAC;CACd,CAAC;AACF,oBAAY,gEAAgE,GAAG;IAC3E,QAAQ,CAAC,IAAI,EAAE;QACX,QAAQ,CAAC,gBAAgB,EAAE,YAAY,CAAC,0CAA0C,CAAC,CAAC;KACvF,GAAG,IAAI,CAAC;CACZ,CAAC;AACF,oBAAY,wDAAwD,GAAG;IACnE,QAAQ,CAAC,QAAQ,EAAE,gEAAgE,CAAC;IACpF,QAAQ,CAAC,SAAS,EAAE,iEAAiE,CAAC;CACzF,CAAC;AA8DF,eAAO,MAAM,SAAS,EAAE,OAAO,sCAAsC,EAAE,sBAkoBtE,CAAC"}