@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,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/storeObservation/compiledHooks.test.tsx"],
4
+ "sourcesContent": ["import React from \"react\";\nimport { ApolloClient, ApolloProvider } from \"@apollo/client\";\nimport {\n act,\n create as createTestRenderer,\n ReactTestRenderer,\n} from \"react-test-renderer\";\nimport { buildSchema } from \"graphql\";\nimport { graphql } from \"@graphitation/graphql-js-tag\";\nimport {\n ApolloMockClient,\n createMockClient,\n} from \"@graphitation/apollo-mock-client\";\nimport * as MockPayloadGenerator from \"@graphitation/graphql-js-operation-payload-generator\";\nimport * as fs from \"fs\";\nimport * as path from \"path\";\n\nimport {\n Disposable,\n RefetchFn,\n useCompiledFragment,\n useCompiledLazyLoadQuery,\n useCompiledPaginationFragment,\n useCompiledRefetchableFragment,\n} from \"./compiledHooks\";\nimport { typePolicies } from \"./typePolicies\";\n\n/**\n * NOTE: These compiler artefacts are normally imported using the transform from the createImportDocumentsTransform.ts module\n */\nimport { documents as compiledHooks_Root_executionQuery_documents } from \"./__generated__/compiledHooks_Root_executionQuery.graphql\";\nimport { documents as compiledHooks_ChildFragment_documents } from \"./__generated__/compiledHooks_ChildWatchNodeQuery.graphql\";\nimport { documents as compiledHooks_RefetchableFragment_documents } from \"./__generated__/compiledHooks_RefetchableFragment_RefetchQuery.graphql\";\nimport { documents as compiledHooks_QueryTypeFragment_documents } from \"./__generated__/compiledHooks_QueryTypeWatchNodeQuery.graphql\";\nimport { documents as compiledHooks_ForwardPaginationFragment_documents } from \"./__generated__/compiledHooks_ForwardPaginationFragment_PaginationQuery.graphql\";\nimport { documents as compiledHooks_BackwardPaginationFragment_documents } from \"./__generated__/compiledHooks_BackwardPaginationFragment_PaginationQuery.graphql\";\nimport { compiledHooks_Root_executionQueryVariables } from \"./__generated__/compiledHooks_Root_executionQuery.graphql\";\n\nconst schema = buildSchema(\n fs.readFileSync(\n path.resolve(__dirname, \"../__tests__/schema.graphql\"),\n \"utf8\"\n )\n);\n\nconst Child_fragment = graphql`\n fragment compiledHooks_ChildFragment on User {\n petName\n }\n`;\n\nconst Refetchable_fragment = graphql`\n fragment compiledHooks_RefetchableFragment on User\n @refetchable(queryName: \"compiledHooks_RefetchableFragment_RefetchQuery\") {\n petName\n avatarUrl(size: $avatarSize)\n }\n`;\n\nconst QueryType_fragment = graphql`\n fragment compiledHooks_QueryTypeFragment on Query {\n nonNode {\n id\n }\n }\n`;\n\nconst ForwardPagination_fragment = graphql`\n fragment compiledHooks_ForwardPaginationFragment on User\n @refetchable(\n queryName: \"compiledHooks_ForwardPaginationFragment_PaginationQuery\"\n )\n @argumentDefinitions(\n conversationsForwardCount: { type: \"Int!\", defaultValue: 1 }\n conversationsAfterCursor: { type: \"String!\", defaultValue: \"\" }\n ) {\n petName\n avatarUrl(size: $avatarSize)\n conversations(\n first: $conversationsForwardCount\n after: $conversationsAfterCursor\n ) @connection(key: \"compiledHooks_user_conversations\") {\n edges {\n node {\n title\n ...compiledHooks_BackwardPaginationFragment\n }\n }\n }\n }\n`;\n\nconst BackwardPagination_fragment = graphql`\n fragment compiledHooks_BackwardPaginationFragment on Conversation\n @refetchable(\n queryName: \"compiledHooks_BackwardPaginationFragment_PaginationQuery\"\n ) {\n messages(last: $messagesBackwardCount, before: $messagesBeforeCursor)\n @connection(key: \"compiledHooks_conversation_messages\") {\n edges {\n node {\n text\n }\n }\n }\n }\n`;\n\nconst Root_executionQueryDocument = graphql`\n query compiledHooks_Root_executionQuery(\n $userId: Int!\n $avatarSize: Int = 21\n $messagesBackwardCount: Int!\n $messagesBeforeCursor: String!\n ) {\n user(id: $userId) {\n name\n ...compiledHooks_ChildFragment\n ...compiledHooks_RefetchableFragment\n ...compiledHooks_ForwardPaginationFragment\n }\n ...compiledHooks_QueryTypeFragment\n }\n`;\n\ndescribe(\"compiledHooks\", () => {\n let client: ApolloMockClient;\n let testRenderer: ReactTestRenderer;\n\n let useFragmentResult: { id: number }[];\n let useRefetchableFragmentResult: ReturnType<\n typeof useCompiledRefetchableFragment\n >[];\n let forwardUsePaginationFragmentResult: ReturnType<\n typeof useCompiledPaginationFragment\n >[];\n let backwardUsePaginationFragmentResult: ReturnType<\n typeof useCompiledPaginationFragment\n >[];\n let useLazyLoadQueryResult: { data?: any; error?: Error } | null = null;\n let componentOnQueryTypeResult: {}[];\n\n const ChildComponent: React.FC<{ user: { id: any } }> = (props) => {\n const result = useCompiledFragment(\n compiledHooks_ChildFragment_documents,\n props.user\n );\n useFragmentResult.push(result as { id: number });\n return null;\n };\n\n const ChildRefetchableComponent: React.FC<{ user: { id: any } }> = (\n props\n ) => {\n const result = useCompiledRefetchableFragment(\n compiledHooks_RefetchableFragment_documents,\n props.user\n );\n useRefetchableFragmentResult.push(result);\n return null;\n };\n\n const ComponentOnQueryType: React.FC<{ query: {} }> = (props) => {\n const result = useCompiledFragment(\n compiledHooks_QueryTypeFragment_documents,\n props.query\n );\n componentOnQueryTypeResult.push(result);\n return null;\n };\n\n const ChildForwardPaginationComponent: React.FC<{ user: { id: any } }> = (\n props\n ) => {\n const result = useCompiledPaginationFragment(\n compiledHooks_ForwardPaginationFragment_documents as any,\n props.user\n );\n forwardUsePaginationFragmentResult.push(result);\n\n return result.data.conversations.edges.map((edge: any, index: number) => {\n return (\n <ChildBackwardPaginationComponent\n conversation={edge.node}\n key={index}\n />\n );\n });\n };\n\n const ChildBackwardPaginationComponent: React.FC<{\n conversation: { id: any };\n }> = (props) => {\n const result = useCompiledPaginationFragment(\n compiledHooks_BackwardPaginationFragment_documents as any,\n props.conversation\n );\n backwardUsePaginationFragmentResult.push(result);\n return null;\n };\n\n const RootComponent: React.FC<{\n variables: compiledHooks_Root_executionQueryVariables;\n }> = (props) => {\n const result = useCompiledLazyLoadQuery(\n compiledHooks_Root_executionQuery_documents,\n { variables: props.variables }\n );\n useLazyLoadQueryResult = result;\n return result.data ? (\n <>\n <ChildComponent user={result.data.user} />\n <ChildRefetchableComponent user={result.data.user} />\n <ChildForwardPaginationComponent user={result.data.user} />\n <ComponentOnQueryType query={result.data} />\n </>\n ) : null;\n };\n\n beforeEach(() => {\n useLazyLoadQueryResult = null;\n useFragmentResult = [];\n useRefetchableFragmentResult = [];\n forwardUsePaginationFragmentResult = [];\n backwardUsePaginationFragmentResult = [];\n componentOnQueryTypeResult = [];\n client = createMockClient(schema, {\n cache: {\n possibleTypes: {\n Node: [\"User\"],\n },\n typePolicies,\n },\n });\n act(() => {\n testRenderer = createTestRenderer(\n <ApolloProvider client={client}>\n <ErrorBoundary>\n <RootComponent\n variables={{\n userId: 42,\n messagesBackwardCount: 1,\n messagesBeforeCursor: \"\",\n }}\n />\n </ErrorBoundary>\n </ApolloProvider>\n );\n });\n });\n\n describe(useCompiledLazyLoadQuery, () => {\n it(\"correctly returns loading state\", async () => {\n expect(useLazyLoadQueryResult).toEqual({\n data: undefined,\n error: undefined,\n });\n await act(() =>\n client.mock.resolveMostRecentOperation((operation) =>\n MockPayloadGenerator.generate(operation)\n )\n );\n expect(useLazyLoadQueryResult).toEqual({\n data: expect.objectContaining({}),\n error: undefined,\n });\n });\n\n it(\"cancels the execution query while in-flight on unmount\", async () => {\n expect(activeQueries(client).map((query) => query.queryName)).toEqual([\n \"compiledHooks_Root_executionQuery\",\n ]);\n\n await act(async () => {\n testRenderer.unmount();\n return new Promise((resolve) => setTimeout(resolve, 0));\n });\n expect(client.getObservableQueries().size).toBe(0);\n });\n\n describe(\"once loaded\", () => {\n let executionQueryId: string;\n\n beforeEach(async () => {\n executionQueryId = last(activeQueries(client)).queryId;\n await act(() =>\n client.mock.resolveMostRecentOperation((operation) =>\n MockPayloadGenerator.generate(operation, {\n User: (options, generateId) => {\n return {\n id:\n options.parentType === \"Query\"\n ? operation.request.variables.userId\n : generateId(),\n };\n },\n Conversation: () => ({\n id: \"first-paged-conversation\",\n }),\n Message: () => ({\n id: \"first-paged-message\",\n }),\n })\n )\n );\n });\n\n it(\"unsubscribes from the execution query\", async () => {\n expect(\n activeQueries(client).map((query) => query.queryId)\n ).not.toContain(executionQueryId);\n });\n\n it(\"loads all data of the execution query into the store\", () => {\n expect(client.cache.extract()).toMatchInlineSnapshot(`\n Object {\n \"Conversation:first-paged-conversation\": Object {\n \"__typename\": \"Conversation\",\n \"id\": \"first-paged-conversation\",\n \"messages:compiledHooks_conversation_messages\": Object {\n \"__typename\": \"ConversationMessagesConnection\",\n \"edges\": Array [\n Object {\n \"__typename\": \"ConversationMessagesConnectionEdge\",\n \"cursor\": \"<mock-value-for-field-\\\\\"cursor\\\\\">\",\n \"node\": Object {\n \"__ref\": \"Message:first-paged-message\",\n },\n },\n ],\n \"pageInfo\": Object {\n \"__typename\": \"PageInfo\",\n \"hasPreviousPage\": false,\n \"startCursor\": \"<mock-value-for-field-\\\\\"startCursor\\\\\">\",\n },\n },\n \"title\": \"<mock-value-for-field-\\\\\"title\\\\\">\",\n },\n \"Message:first-paged-message\": Object {\n \"__typename\": \"Message\",\n \"id\": \"first-paged-message\",\n \"text\": \"<mock-value-for-field-\\\\\"text\\\\\">\",\n },\n \"NonNode:<mock-value-for-field-\\\\\"id\\\\\">\": Object {\n \"__typename\": \"NonNode\",\n \"id\": \"<mock-value-for-field-\\\\\"id\\\\\">\",\n },\n \"ROOT_QUERY\": Object {\n \"__typename\": \"Query\",\n \"nonNode\": Object {\n \"__ref\": \"NonNode:<mock-value-for-field-\\\\\"id\\\\\">\",\n },\n \"user({\\\\\"id\\\\\":42})\": Object {\n \"__ref\": \"User:42\",\n },\n },\n \"User:42\": Object {\n \"__typename\": \"User\",\n \"avatarUrl({\\\\\"size\\\\\":21})\": \"<mock-value-for-field-\\\\\"avatarUrl\\\\\">\",\n \"conversations:compiledHooks_user_conversations\": Object {\n \"__typename\": \"ConversationsConnection\",\n \"edges\": Array [\n Object {\n \"__typename\": \"ConversationsConnectionEdge\",\n \"cursor\": \"<mock-value-for-field-\\\\\"cursor\\\\\">\",\n \"node\": Object {\n \"__ref\": \"Conversation:first-paged-conversation\",\n },\n },\n ],\n \"pageInfo\": Object {\n \"__typename\": \"PageInfo\",\n \"endCursor\": \"<mock-value-for-field-\\\\\"endCursor\\\\\">\",\n \"hasNextPage\": false,\n },\n },\n \"id\": 42,\n \"name\": \"<mock-value-for-field-\\\\\"name\\\\\">\",\n \"petName\": \"<mock-value-for-field-\\\\\"petName\\\\\">\",\n },\n }\n `);\n });\n\n it(\"only returns the fields selected in the watch query to the component\", () => {\n expect(useLazyLoadQueryResult!.data).toMatchInlineSnapshot(`\n Object {\n \"__fragments\": Object {\n \"avatarSize\": 21,\n \"messagesBackwardCount\": 1,\n \"messagesBeforeCursor\": \"\",\n \"userId\": 42,\n },\n \"user\": Object {\n \"__fragments\": Object {\n \"avatarSize\": 21,\n \"messagesBackwardCount\": 1,\n \"messagesBeforeCursor\": \"\",\n \"userId\": 42,\n },\n \"__typename\": \"User\",\n \"id\": 42,\n \"name\": \"<mock-value-for-field-\\\\\"name\\\\\">\",\n },\n }\n `);\n });\n\n it(\"does not re-render when a field that was not selected in the watch query is updated in the store\", async () => {\n const before = useLazyLoadQueryResult!.data;\n await act(async () => {\n client.cache.modify({\n id: \"User:42\",\n fields: {\n petName: () => \"Phoenix\",\n },\n });\n return new Promise((resolve) => setTimeout(resolve, 0));\n });\n expect(useLazyLoadQueryResult!.data).toBe(before);\n });\n\n it(\"does re-render when a field that was selected in the watch query is updated in the store\", async () => {\n const before = useLazyLoadQueryResult!.data;\n await act(async () => {\n client.cache.modify({\n id: \"User:42\",\n fields: {\n name: () => \"Satya\",\n },\n });\n return new Promise((resolve) => setTimeout(resolve, 0));\n });\n expect(useLazyLoadQueryResult!.data).not.toBe(before);\n expect(useLazyLoadQueryResult!.data).toMatchInlineSnapshot(`\n Object {\n \"__fragments\": Object {\n \"avatarSize\": 21,\n \"messagesBackwardCount\": 1,\n \"messagesBeforeCursor\": \"\",\n \"userId\": 42,\n },\n \"user\": Object {\n \"__fragments\": Object {\n \"avatarSize\": 21,\n \"messagesBackwardCount\": 1,\n \"messagesBeforeCursor\": \"\",\n \"userId\": 42,\n },\n \"__typename\": \"User\",\n \"id\": 42,\n \"name\": \"Satya\",\n },\n }\n `);\n });\n\n it(\"fetches new data when variables change\", async () => {\n act(() => {\n testRenderer.update(\n <ApolloProvider client={client}>\n <ErrorBoundary>\n <RootComponent\n variables={{\n userId: 21,\n messagesBackwardCount: 1,\n messagesBeforeCursor: \"\",\n }}\n />\n </ErrorBoundary>\n </ApolloProvider>\n );\n });\n await act(() =>\n client.mock.resolveMostRecentOperation((operation) =>\n MockPayloadGenerator.generate(operation, {\n User: () => ({ id: operation.request.variables.userId }),\n })\n )\n );\n expect(client.cache.extract()[\"User:21\"]).toMatchInlineSnapshot(`\n Object {\n \"__typename\": \"User\",\n \"avatarUrl({\\\\\"size\\\\\":21})\": \"<mock-value-for-field-\\\\\"avatarUrl\\\\\">\",\n \"conversations:compiledHooks_user_conversations\": Object {\n \"__typename\": \"ConversationsConnection\",\n \"edges\": Array [\n Object {\n \"__typename\": \"ConversationsConnectionEdge\",\n \"cursor\": \"<mock-value-for-field-\\\\\"cursor\\\\\">\",\n \"node\": Object {\n \"__ref\": \"Conversation:<Conversation-mock-id-5>\",\n },\n },\n ],\n \"pageInfo\": Object {\n \"__typename\": \"PageInfo\",\n \"endCursor\": \"<mock-value-for-field-\\\\\"endCursor\\\\\">\",\n \"hasNextPage\": false,\n },\n },\n \"id\": 21,\n \"name\": \"<mock-value-for-field-\\\\\"name\\\\\">\",\n \"petName\": \"<mock-value-for-field-\\\\\"petName\\\\\">\",\n }\n `);\n });\n\n it(\"does not try to kick-off a new query when the variables object deep equals the previous one\", async () => {\n const spy = jest.spyOn(client, \"query\");\n await act(async () => {\n testRenderer.update(\n <ApolloProvider client={client}>\n <ErrorBoundary>\n <RootComponent\n variables={{\n userId: 42,\n messagesBackwardCount: 1,\n messagesBeforeCursor: \"\",\n }}\n />\n </ErrorBoundary>\n </ApolloProvider>\n );\n return new Promise((resolve) => setTimeout(resolve, 100));\n });\n expect(spy).not.toHaveBeenCalled();\n });\n\n it(\"removes all watch queries on unmount\", async () => {\n await act(async () => {\n testRenderer.unmount();\n return new Promise((resolve) => setTimeout(resolve, 0));\n });\n expect(client.getObservableQueries().size).toBe(0);\n });\n });\n });\n\n function itBehavesLikeFragment(\n returnedResults: () => { id: number }[],\n fragmentSpecificFieldSelections?: {}\n ) {\n // TODO: This should be scoped so it doesn't leak to other tests in the same parent describe\n // describe(\"behaves like useFragment\", () => {\n beforeEach(async () => {\n await act(() =>\n client.mock.resolveMostRecentOperation((operation) => {\n const result = MockPayloadGenerator.generate(operation, {\n User: () => ({\n id: 42,\n }),\n Conversation: () => ({\n id: \"first-paged-conversation\",\n }),\n Message: () => ({\n id: \"first-paged-message\",\n }),\n PageInfo: () => ({\n startCursor: \"first-page-start-cursor\",\n endCursor: \"first-page-end-cursor\",\n hasNextPage: true,\n hasPreviousPage: true,\n }),\n });\n return result;\n })\n );\n });\n\n it(\"only returns the fields selected in the watch query to the component\", () => {\n expect(last(returnedResults())).toEqual({\n __fragments: {\n avatarSize: 21,\n messagesBackwardCount: 1,\n messagesBeforeCursor: \"\",\n userId: 42,\n },\n __typename: \"User\",\n id: 42,\n petName: '<mock-value-for-field-\"petName\">',\n ...fragmentSpecificFieldSelections,\n });\n });\n\n it(\"returns the same object when a field that was not selected in the watch query is updated in the store\", async () => {\n const before = last(returnedResults());\n await act(async () => {\n client.cache.modify({\n id: \"User:42\",\n fields: {\n name: () => \"Satya\",\n },\n });\n return new Promise((resolve) => setTimeout(resolve, 0));\n });\n expect(last(returnedResults())).toBe(before);\n });\n\n it(\"returns a new object when a field that was selected in the watch query is updated in the store\", async () => {\n await act(async () => {\n client.cache.modify({\n id: \"User:42\",\n fields: {\n petName: () => \"some new value\",\n },\n });\n return new Promise((resolve) => setTimeout(resolve, 0));\n });\n expect(returnedResults().length).toBe(2);\n expect(last(returnedResults())).toMatchObject({\n petName: \"some new value\",\n });\n });\n\n it(\"returns data synchronously\", () => {\n expect(returnedResults().length).toBe(1);\n });\n\n it(\"fetches new data when variables change\", async () => {\n act(() => {\n testRenderer.update(\n <ApolloProvider client={client}>\n <ErrorBoundary>\n <RootComponent\n variables={{\n userId: 21,\n messagesBackwardCount: 1,\n messagesBeforeCursor: \"\",\n }}\n />\n </ErrorBoundary>\n </ApolloProvider>\n );\n });\n await act(() =>\n client.mock.resolveMostRecentOperation((operation) =>\n MockPayloadGenerator.generate(operation, {\n User: () => ({ id: operation.request.variables.userId }),\n })\n )\n );\n expect(last(returnedResults()).id).toBe(21);\n });\n // });\n }\n\n describe(useCompiledFragment, () => {\n itBehavesLikeFragment(() => useFragmentResult, {\n petName: '<mock-value-for-field-\"petName\">',\n });\n\n it(\"also works with fragments on the Query type\", () => {\n expect(last(componentOnQueryTypeResult)).toMatchInlineSnapshot(`\n Object {\n \"__fragments\": Object {\n \"avatarSize\": 21,\n \"messagesBackwardCount\": 1,\n \"messagesBeforeCursor\": \"\",\n \"userId\": 42,\n },\n \"nonNode\": Object {\n \"__typename\": \"NonNode\",\n \"id\": \"<mock-value-for-field-\\\\\"id\\\\\">\",\n },\n }\n `);\n });\n });\n\n function itBehavesLikeRefetchableFragment(\n returnedResults: () => [data: { id: number }, refetch: RefetchFn][]\n ) {\n it.todo(\n \"supports variables with default values on either operations or with @argumentDefinitions\"\n );\n\n describe(\"when refetching\", () => {\n let onCompleted: jest.Mock;\n let disposable: Disposable;\n\n beforeEach(() => {\n const [_data, refetch] = last(returnedResults());\n onCompleted = jest.fn();\n disposable = refetch({ avatarSize: 42 }, { onCompleted });\n });\n\n it(\"can be cancelled\", () => {\n const query = last(activeQueries(client));\n disposable.dispose();\n expect(client.getObservableQueries().has(query.queryId)).toBeFalsy();\n });\n\n it(\"cancels when unmounting\", async () => {\n await act(async () => {\n const query = last(activeQueries(client));\n testRenderer.unmount();\n await new Promise((resolve) => setTimeout(resolve, 0));\n expect(client.getObservableQueries().has(query.queryId)).toBeFalsy();\n });\n });\n\n describe(\"successfully\", () => {\n beforeEach(async () => {\n await act(() => {\n client.mock.resolveMostRecentOperation((operation) =>\n MockPayloadGenerator.generate(operation, {\n Node: () => ({\n id: 42,\n avatarUrl: `avatarUrl-with-size-${operation.request.variables.avatarSize}`,\n }),\n })\n );\n return new Promise((resolve) => setTimeout(resolve, 0));\n });\n });\n\n it(\"returns a new object from the hook\", () => {\n expect(last(returnedResults())[0]).toMatchObject({\n __typename: \"User\",\n avatarUrl: \"avatarUrl-with-size-42\",\n id: 42,\n });\n });\n\n it(\"updates the fragment reference request variables for future requests\", () => {\n expect(last(returnedResults())[0]).toMatchObject({\n __fragments: {\n avatarSize: 42,\n userId: 42,\n },\n });\n });\n\n it(\"invokes the onComplete callback without error\", () => {\n expect(onCompleted).toHaveBeenCalledWith(null);\n });\n });\n\n describe(\"and an error occurs\", () => {\n const error = new Error(\"oh noes\");\n\n beforeEach(async () => {\n await act(() => client.mock.rejectMostRecentOperation(error));\n });\n\n it(\"invokes the onComplete callback when an error occurs\", () => {\n expect(onCompleted).toHaveBeenCalledWith(error);\n });\n\n it(\"does not update the fragment reference request variables for future requests\", async () => {\n const [_data, refetch] = last(returnedResults());\n refetch({});\n expect(\n client.mock.getMostRecentOperation().request.variables.avatarSize\n ).toBe(21);\n });\n });\n });\n }\n\n describe(useCompiledRefetchableFragment, () => {\n itBehavesLikeFragment(\n () =>\n useRefetchableFragmentResult.map(\n ([data, _refetch]) => data as { id: number }\n ),\n { avatarUrl: '<mock-value-for-field-\"avatarUrl\">' }\n );\n\n itBehavesLikeRefetchableFragment(\n () =>\n useRefetchableFragmentResult as [\n data: { id: number },\n refetch: RefetchFn\n ][]\n );\n });\n\n describe(useCompiledPaginationFragment, () => {\n itBehavesLikeFragment(\n () =>\n forwardUsePaginationFragmentResult.map(\n ({ data }) => data as { id: number }\n ),\n {\n avatarUrl: '<mock-value-for-field-\"avatarUrl\">',\n conversations: {\n __typename: \"ConversationsConnection\",\n edges: [\n {\n __typename: \"ConversationsConnectionEdge\",\n cursor: '<mock-value-for-field-\"cursor\">',\n node: {\n __fragments: {\n avatarSize: 21,\n messagesBackwardCount: 1,\n messagesBeforeCursor: \"\",\n userId: 42,\n },\n __typename: \"Conversation\",\n id: \"first-paged-conversation\",\n title: '<mock-value-for-field-\"title\">',\n },\n },\n ],\n pageInfo: {\n __typename: \"PageInfo\",\n endCursor: \"first-page-end-cursor\",\n hasNextPage: true,\n },\n },\n }\n );\n\n itBehavesLikeRefetchableFragment(() =>\n forwardUsePaginationFragmentResult.map(({ data, refetch }) => [\n data as { id: number },\n refetch,\n ])\n );\n\n describe(\"when paginating forward\", () => {\n it(\"returns that next data is available\", () => {\n const { hasNext } = last(forwardUsePaginationFragmentResult);\n expect(hasNext).toBeTruthy();\n });\n\n it(\"uses the correct count and cursor values\", () => {\n act(() => {\n const { loadNext } = last(forwardUsePaginationFragmentResult);\n loadNext(123);\n });\n\n const operation = client.mock.getMostRecentOperation();\n expect(operation.request.variables).toMatchObject({\n conversationsForwardCount: 123,\n conversationsAfterCursor: \"first-page-end-cursor\",\n });\n });\n\n it(\"returns that a pagination operation is in-flight\", () => {\n act(() => {\n const { loadNext } = last(forwardUsePaginationFragmentResult);\n loadNext(123);\n });\n const { isLoadingNext } = last(forwardUsePaginationFragmentResult);\n expect(isLoadingNext).toBeTruthy();\n });\n\n it(\"can be cancelled\", () => {\n act(() => {\n const { loadNext } = last(forwardUsePaginationFragmentResult);\n const disposable = loadNext(123);\n const query = last(activeQueries(client));\n disposable.dispose();\n expect(client.getObservableQueries().has(query.queryId)).toBeFalsy();\n });\n });\n\n it(\"cancels when unmounting\", async () => {\n await act(async () => {\n const { loadNext } = last(forwardUsePaginationFragmentResult);\n loadNext(123);\n const query = last(activeQueries(client));\n\n testRenderer.unmount();\n await new Promise((resolve) => setTimeout(resolve, 0));\n\n expect(client.getObservableQueries().has(query.queryId)).toBeFalsy();\n });\n });\n\n it(\"invokes the onComplete callback when an error occurs\", async () => {\n const onCompleted = jest.fn();\n const error = new Error(\"oh noes\");\n\n const { loadNext } = last(forwardUsePaginationFragmentResult);\n await act(async () => {\n loadNext(1, { onCompleted });\n await client.mock.rejectMostRecentOperation(error);\n });\n\n expect(onCompleted).toHaveBeenCalledWith(error);\n });\n\n describe(\"and having received the response\", () => {\n let onCompleted: jest.Mock;\n\n beforeEach(async () => {\n onCompleted = jest.fn();\n await act(async () => {\n const { loadNext } = last(forwardUsePaginationFragmentResult);\n loadNext(1, { onCompleted });\n\n // Introduce a slight delay before resolving the request as a\n // regression test with a pagination requst being disposed early.\n await new Promise((resolve) => setTimeout(resolve, 0));\n\n client.mock.resolveMostRecentOperation((operation) =>\n MockPayloadGenerator.generate(operation, {\n Node: () => ({\n id: 42,\n }),\n Conversation: () => ({\n id: \"second-paged-conversation\",\n }),\n PageInfo: () => ({\n endCursor: \"second-page-end-cursor\",\n hasNextPage: false,\n }),\n })\n );\n return new Promise((resolve) => setTimeout(resolve, 0));\n });\n });\n\n it(\"returns that no pagination operation is in-flight\", () => {\n const { isLoadingNext } = last(forwardUsePaginationFragmentResult);\n expect(isLoadingNext).toBeFalsy();\n });\n\n it(\"loads the new data into the store\", () => {\n expect(client.cache.extract()).toMatchObject({\n \"Conversation:second-paged-conversation\": {\n id: \"second-paged-conversation\",\n __typename: \"Conversation\",\n title: '<mock-value-for-field-\"title\">',\n },\n });\n });\n\n it(\"returns the complete list data (previous+new) from the hook\", () => {\n const result = last(forwardUsePaginationFragmentResult);\n expect(\n (result.data as any).conversations.edges.map(\n (edge: any) => edge.node.id\n )\n ).toMatchInlineSnapshot(`\n Array [\n \"first-paged-conversation\",\n \"second-paged-conversation\",\n ]\n `);\n });\n\n it(\"uses the new cursor value\", () => {\n act(() => {\n const { loadNext } = last(forwardUsePaginationFragmentResult);\n loadNext(123);\n });\n\n const operation = client.mock.getMostRecentOperation();\n expect(operation.request.variables).toMatchObject({\n conversationsAfterCursor: \"second-page-end-cursor\",\n });\n });\n\n it(\"returns that no next data is available\", () => {\n const { hasNext } = last(forwardUsePaginationFragmentResult);\n expect(hasNext).toBeFalsy();\n });\n\n it(\"invokes the onComplete callback without error\", () => {\n expect(onCompleted).toHaveBeenCalledWith(null);\n });\n });\n });\n\n describe(\"when paginating backward\", () => {\n it(\"returns that previous data is available\", () => {\n const { hasPrevious } = last(backwardUsePaginationFragmentResult);\n expect(hasPrevious).toBeTruthy();\n });\n\n it(\"uses the correct count and cursor values\", () => {\n act(() => {\n const { loadPrevious } = last(backwardUsePaginationFragmentResult);\n loadPrevious(123);\n });\n\n const operation = client.mock.getMostRecentOperation();\n expect(operation.request.variables).toMatchObject({\n messagesBackwardCount: 123,\n messagesBeforeCursor: \"first-page-start-cursor\",\n });\n });\n\n it(\"returns that a pagination operation is in-flight\", () => {\n act(() => {\n const { loadPrevious } = last(backwardUsePaginationFragmentResult);\n loadPrevious(123);\n });\n const { isLoadingPrevious } = last(backwardUsePaginationFragmentResult);\n expect(isLoadingPrevious).toBeTruthy();\n });\n\n it(\"can be cancelled\", () => {\n act(() => {\n const { loadPrevious } = last(backwardUsePaginationFragmentResult);\n const disposable = loadPrevious(123);\n const query = last(activeQueries(client));\n disposable.dispose();\n expect(client.getObservableQueries().has(query.queryId)).toBeFalsy();\n });\n });\n\n it(\"cancels when unmounting\", async () => {\n await act(async () => {\n const { loadPrevious } = last(backwardUsePaginationFragmentResult);\n loadPrevious(123);\n const query = last(activeQueries(client));\n\n testRenderer.unmount();\n await new Promise((resolve) => setTimeout(resolve, 0));\n\n expect(client.getObservableQueries().has(query.queryId)).toBeFalsy();\n });\n });\n\n it(\"invokes the onComplete callback when an error occurs\", async () => {\n const onCompleted = jest.fn();\n const error = new Error(\"oh noes\");\n\n const { loadPrevious } = last(backwardUsePaginationFragmentResult);\n await act(async () => {\n loadPrevious(1, { onCompleted });\n await client.mock.rejectMostRecentOperation(error);\n });\n\n expect(onCompleted).toHaveBeenCalledWith(error);\n });\n\n describe(\"and having received the response\", () => {\n let onCompleted: jest.Mock;\n\n beforeEach(async () => {\n onCompleted = jest.fn();\n await act(() => {\n const { loadPrevious } = last(backwardUsePaginationFragmentResult);\n loadPrevious(1, { onCompleted });\n\n client.mock.resolveMostRecentOperation((operation) =>\n MockPayloadGenerator.generate(operation, {\n Node: () => ({\n id: 42,\n }),\n Message: () => ({\n id: \"second-paged-message\",\n }),\n PageInfo: () => ({\n startCursor: \"second-page-start-cursor\",\n hasPreviousPage: false,\n }),\n })\n );\n return new Promise((resolve) => setTimeout(resolve, 0));\n });\n });\n\n it(\"returns that no pagination operation is in-flight\", () => {\n const { isLoadingPrevious } = last(\n backwardUsePaginationFragmentResult\n );\n expect(isLoadingPrevious).toBeFalsy();\n });\n\n it(\"loads the new data into the store\", () => {\n expect(client.cache.extract()).toMatchObject({\n \"Message:second-paged-message\": {\n id: \"second-paged-message\",\n __typename: \"Message\",\n text: '<mock-value-for-field-\"text\">',\n },\n });\n });\n\n it(\"returns the complete list data (previous+new) from the hook\", () => {\n const result = last(backwardUsePaginationFragmentResult);\n expect(\n (result.data as any).messages.edges.map((edge: any) => edge.node.id)\n ).toMatchInlineSnapshot(`\n Array [\n \"second-paged-message\",\n \"first-paged-message\",\n ]\n `);\n });\n\n it(\"uses the new cursor value\", () => {\n act(() => {\n const { loadPrevious } = last(backwardUsePaginationFragmentResult);\n loadPrevious(123);\n });\n\n const operation = client.mock.getMostRecentOperation();\n expect(operation.request.variables).toMatchObject({\n messagesBeforeCursor: \"second-page-start-cursor\",\n });\n });\n\n it(\"returns that no previous data is available\", () => {\n const { hasPrevious } = last(backwardUsePaginationFragmentResult);\n expect(hasPrevious).toBeFalsy();\n });\n\n it(\"invokes the onComplete callback without error\", () => {\n expect(onCompleted).toHaveBeenCalledWith(null);\n });\n });\n });\n });\n});\n\nclass ErrorBoundary extends React.Component {\n state = { hasError: false };\n\n static getDerivedStateFromError(error: Error) {\n return { hasError: true };\n }\n\n componentDidCatch(error: Error, errorInfo: any) {\n console.error({ error, errorInfo });\n }\n\n render() {\n if (this.state.hasError) {\n return <h1>Something went wrong.</h1>;\n }\n\n return this.props.children;\n }\n}\n\nfunction last<T>(list: T[]): T {\n return list[list.length - 1];\n}\n\nfunction activeQueries(client: ApolloClient<any>) {\n return Array.from(client.getObservableQueries().values());\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;AAAA;AACA;AACA;AAAA;AAAA;AAAA;AAKA;AACA;AACA;AAAA;AAAA;AAIA;AAAA;AAAA;AACA;AAAA;AAAA;AACA;AAAA;AAAA;AAEA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQA;AAKA;AACA;AACA;AACA;AACA;AACA;AAGA,IAAM,SAAS,YACb,AAAG,aACD,AAAK,QAAQ,WAAW,gCACxB;AAIJ,IAAM,iBAAiB;AAAA;AAAA;AAAA;AAAA;AAMvB,IAAM,uBAAuB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQ7B,IAAM,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQ3B,IAAM,6BAA6B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAyBnC,IAAM,8BAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAgBpC,IAAM,8BAA8B;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAiBpC,SAAS,iBAAiB,MAAM;AAC9B,MAAI;AACJ,MAAI;AAEJ,MAAI;AACJ,MAAI;AAGJ,MAAI;AAGJ,MAAI;AAGJ,MAAI,yBAA+D;AACnE,MAAI;AAEJ,QA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K,KAAK,KACjE,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAQ1B,WAAG,6BAA6B,MAAM;AACpC,cAAI,MAAM;AACR,kBAAM,CAAE,gBAAiB,KAAK;AAC9B,yBAAa;AAAA;AAGf,gBAAM,YAAY,OAAO,KAAK;AAC9B,iBAAO,UAAU,QAAQ,WAAW,cAAc;AAAA,YAChD,sBAAsB;AAAA;AAAA;AAI1B,WAAG,8CAA8C,MAAM;AACrD,gBAAM,CAAE,eAAgB,KAAK;AAC7B,iBAAO,aAAa;AAAA;AAGtB,WAAG,iDAAiD,MAAM;AACxD,iBAAO,aAAa,qBAAqB;AAAA;AAAA;AAAA;AAAA;AAAA;AAOnD,kCAA4B,MAAM,UAAU;AAAA,EAA5C,cA1lCA;AA0lCA;AACE,iBAAQ,CAAE,UAAU;AAAA;AAAA,SAEb,yBAAyB,OAAc;AAC5C,WAAO,CAAE,UAAU;AAAA;AAAA,EAGrB,kBAAkB,OAAc,WAAgB;AAC9C,YAAQ,MAAM,CAAE,OAAO;AAAA;AAAA,EAGzB,SAAS;AACP,QAAI,KAAK,MAAM,UAAU;AACvB,aAAO,oCAAC,MAAD,MAAI;AAAA;AAGb,WAAO,KAAK,MAAM;AAAA;AAAA;AAItB,cAAiB,MAAc;AAC7B,SAAO,KAAK,KAAK,SAAS;AAAA;AAG5B,uBAAuB,QAA2B;AAChD,SAAO,MAAM,KAAK,OAAO,uBAAuB;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,9 @@
1
+ /**
2
+ * TODO:
3
+ * - Don't hardcode identifiers but check if they're aliased from their imports.
4
+ * - Support mutations and subscriptions
5
+ * - Properly emit errors from transformer, is invariant ok?
6
+ */
7
+ import * as ts from "typescript";
8
+ export declare function createImportDocumentsTransform(): ts.TransformerFactory<ts.SourceFile>;
9
+ //# sourceMappingURL=createImportDocumentsTransform.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createImportDocumentsTransform.d.ts","sourceRoot":"","sources":["../../src/storeObservation/createImportDocumentsTransform.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAGH,OAAO,KAAK,EAAE,MAAM,YAAY,CAAC;AAYjC,wBAAgB,8BAA8B,IAAI,EAAE,CAAC,kBAAkB,CAAC,EAAE,CAAC,UAAU,CAAC,CAiDrF"}
@@ -0,0 +1,107 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, {get: all[name], enumerable: true});
11
+ };
12
+ var __reExport = (target, module2, desc) => {
13
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
14
+ for (let key of __getOwnPropNames(module2))
15
+ if (!__hasOwnProp.call(target, key) && key !== "default")
16
+ __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
17
+ }
18
+ return target;
19
+ };
20
+ var __toModule = (module2) => {
21
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
22
+ };
23
+ __markAsModule(exports);
24
+ __export(exports, {
25
+ createImportDocumentsTransform: () => createImportDocumentsTransform
26
+ });
27
+ var import_invariant = __toModule(require("invariant"));
28
+ var ts = __toModule(require("typescript"));
29
+ var import_graphql = __toModule(require("graphql"));
30
+ var path = __toModule(require("path"));
31
+ var fs = __toModule(require("fs"));
32
+ const PREFIX = "__graphitation_";
33
+ const QUERIES_NAMESPACE = "generatedQueries";
34
+ function createImportDocumentsTransform() {
35
+ return (context) => {
36
+ const imports = [];
37
+ const visitor = (node) => {
38
+ if (ts.isTaggedTemplateExpression(node) && ts.isIdentifier(node.tag) && node.tag.escapedText === "graphql") {
39
+ const documentNodes = createGraphQLDocumentNodes(node);
40
+ if (documentNodes) {
41
+ const [importDeclaration, replacementNode] = documentNodes;
42
+ let emitImport = true;
43
+ const sourceFile = node.getSourceFile();
44
+ if (sourceFile) {
45
+ const artefactFile = path.join(path.dirname(sourceFile.fileName), importDeclaration.moduleSpecifier.text) + ".ts";
46
+ emitImport = fs.existsSync(artefactFile);
47
+ }
48
+ if (emitImport) {
49
+ imports.push(importDeclaration);
50
+ return replacementNode;
51
+ }
52
+ }
53
+ }
54
+ return ts.visitEachChild(node, visitor, context);
55
+ };
56
+ return (sourceFile) => {
57
+ const outputSourceFile = ts.visitNode(sourceFile, visitor);
58
+ return ts.factory.updateSourceFile(outputSourceFile, [
59
+ ...imports,
60
+ ...outputSourceFile.statements
61
+ ]);
62
+ };
63
+ };
64
+ }
65
+ function createGraphQLDocumentNodes(graphqlTagTemplateNode) {
66
+ var _a;
67
+ const graphqlDoc = ts.isNoSubstitutionTemplateLiteral(graphqlTagTemplateNode.template) ? graphqlTagTemplateNode.template.rawText : graphqlTagTemplateNode.template.head.rawText;
68
+ (0, import_invariant.default)(graphqlDoc, "Expected a GraphQL document");
69
+ const graphqlAST = (0, import_graphql.parse)(graphqlDoc);
70
+ const definitionNode = graphqlAST.definitions[0];
71
+ if (definitionNode.kind === "OperationDefinition") {
72
+ if (definitionNode.operation !== "query") {
73
+ return void 0;
74
+ }
75
+ const operationName = (_a = definitionNode.name) == null ? void 0 : _a.value;
76
+ (0, import_invariant.default)(operationName, "Operations are required to have a name");
77
+ const namespaceName = `${PREFIX}${QUERIES_NAMESPACE}_${operationName}`;
78
+ return [
79
+ ts.factory.createImportDeclaration(void 0, void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports([
80
+ ts.factory.createImportSpecifier(ts.factory.createIdentifier("documents"), ts.factory.createIdentifier(namespaceName))
81
+ ])), ts.factory.createStringLiteral(`./__generated__/${operationName}.graphql`)),
82
+ ts.factory.createIdentifier(namespaceName)
83
+ ];
84
+ } else if (definitionNode.kind === "FragmentDefinition") {
85
+ const queryName = getQueryName(definitionNode);
86
+ const fragmentName = definitionNode.name.value;
87
+ const namespaceName = `${PREFIX}${QUERIES_NAMESPACE}_${fragmentName}`;
88
+ return [
89
+ ts.factory.createImportDeclaration(void 0, void 0, ts.factory.createImportClause(false, void 0, ts.factory.createNamedImports([
90
+ ts.factory.createImportSpecifier(ts.factory.createIdentifier("documents"), ts.factory.createIdentifier(namespaceName))
91
+ ])), ts.factory.createStringLiteral(`./__generated__/${queryName}.graphql`)),
92
+ ts.factory.createIdentifier(namespaceName)
93
+ ];
94
+ }
95
+ (0, import_invariant.default)(false, `Unhandled GraphQL definition type: ${definitionNode.kind}`);
96
+ }
97
+ function getQueryName(definitionNode) {
98
+ var _a, _b, _c, _d;
99
+ const refetchableQueryNameNode = (_d = (_c = (_b = (_a = definitionNode.directives) == null ? void 0 : _a.find((directive) => directive.name.value === "refetchable")) == null ? void 0 : _b.arguments) == null ? void 0 : _c.find((arg) => arg.name.value === "queryName")) == null ? void 0 : _d.value;
100
+ if (refetchableQueryNameNode) {
101
+ return refetchableQueryNameNode.value;
102
+ } else {
103
+ const fragmentName = definitionNode.name.value;
104
+ const fragmentBaseName = fragmentName.replace(/Fragment$/, "");
105
+ return `${fragmentBaseName}WatchNodeQuery`;
106
+ }
107
+ }
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/storeObservation/createImportDocumentsTransform.ts"],
4
+ "sourcesContent": ["/**\n * TODO:\n * - Don't hardcode identifiers but check if they're aliased from their imports.\n * - Support mutations and subscriptions\n * - Properly emit errors from transformer, is invariant ok?\n */\n\nimport invariant from \"invariant\";\nimport * as ts from \"typescript\";\nimport {\n FragmentDefinitionNode,\n parse as parseGraphQL,\n StringValueNode,\n} from \"graphql\";\nimport * as path from \"path\";\nimport * as fs from \"fs\";\n\nconst PREFIX = \"__graphitation_\";\nconst QUERIES_NAMESPACE = \"generatedQueries\";\n\nexport function createImportDocumentsTransform(): ts.TransformerFactory<ts.SourceFile> {\n return (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {\n const imports: ts.ImportDeclaration[] = [];\n\n const visitor: ts.Visitor = (node: ts.Node): ts.VisitResult<ts.Node> => {\n if (\n ts.isTaggedTemplateExpression(node) &&\n ts.isIdentifier(node.tag) &&\n node.tag.escapedText === \"graphql\"\n ) {\n const documentNodes = createGraphQLDocumentNodes(node);\n if (documentNodes) {\n const [importDeclaration, replacementNode] = documentNodes;\n // Because we currently only emit new watch queries for fragments\n // on Node types, we cannot just assume the artefact exists for\n // every fragment definition. So check if it exists before emitting\n // the import.\n //\n // TODO: This file checking should not exist and is probably not\n // performant.\n //\n // NOTE: In our test case node.getSourceFile() returns undefined.\n let emitImport = true;\n const sourceFile: ts.SourceFile | undefined = node.getSourceFile();\n if (sourceFile) {\n const artefactFile =\n path.join(\n path.dirname(sourceFile.fileName),\n (importDeclaration.moduleSpecifier as ts.StringLiteral).text\n ) + \".ts\";\n emitImport = fs.existsSync(artefactFile);\n }\n if (emitImport) {\n imports.push(importDeclaration);\n return replacementNode;\n }\n }\n }\n return ts.visitEachChild(node, visitor, context);\n };\n\n return (sourceFile: ts.SourceFile) => {\n const outputSourceFile = ts.visitNode(sourceFile, visitor);\n return ts.factory.updateSourceFile(outputSourceFile, [\n ...imports,\n ...outputSourceFile.statements,\n ]);\n };\n };\n}\n\nfunction createGraphQLDocumentNodes(\n graphqlTagTemplateNode: ts.TaggedTemplateExpression\n): [ts.ImportDeclaration, ts.Identifier] | undefined {\n const graphqlDoc = ts.isNoSubstitutionTemplateLiteral(\n graphqlTagTemplateNode.template\n )\n ? graphqlTagTemplateNode.template.rawText\n : graphqlTagTemplateNode.template.head.rawText;\n invariant(graphqlDoc, \"Expected a GraphQL document\");\n const graphqlAST = parseGraphQL(graphqlDoc);\n const definitionNode = graphqlAST.definitions[0];\n if (definitionNode.kind === \"OperationDefinition\") {\n if (definitionNode.operation !== \"query\") {\n return undefined;\n }\n const operationName = definitionNode.name?.value;\n invariant(operationName, \"Operations are required to have a name\");\n const namespaceName = `${PREFIX}${QUERIES_NAMESPACE}_${operationName}`;\n return [\n ts.factory.createImportDeclaration(\n undefined,\n undefined,\n ts.factory.createImportClause(\n false,\n undefined,\n ts.factory.createNamedImports([\n ts.factory.createImportSpecifier(\n ts.factory.createIdentifier(\"documents\"),\n ts.factory.createIdentifier(namespaceName)\n ),\n ])\n ),\n ts.factory.createStringLiteral(\n `./__generated__/${operationName}.graphql`\n )\n ),\n ts.factory.createIdentifier(namespaceName),\n ];\n } else if (definitionNode.kind === \"FragmentDefinition\") {\n const queryName = getQueryName(definitionNode);\n const fragmentName = definitionNode.name.value;\n const namespaceName = `${PREFIX}${QUERIES_NAMESPACE}_${fragmentName}`;\n return [\n ts.factory.createImportDeclaration(\n undefined,\n undefined,\n ts.factory.createImportClause(\n false,\n undefined,\n ts.factory.createNamedImports([\n ts.factory.createImportSpecifier(\n ts.factory.createIdentifier(\"documents\"),\n ts.factory.createIdentifier(namespaceName)\n ),\n ])\n ),\n ts.factory.createStringLiteral(`./__generated__/${queryName}.graphql`)\n ),\n ts.factory.createIdentifier(namespaceName),\n ];\n }\n invariant(false, `Unhandled GraphQL definition type: ${definitionNode.kind}`);\n}\n\nfunction getQueryName(definitionNode: FragmentDefinitionNode) {\n const refetchableQueryNameNode = definitionNode.directives\n ?.find((directive) => directive.name.value === \"refetchable\")\n ?.arguments?.find((arg) => arg.name.value === \"queryName\")?.value as\n | StringValueNode\n | undefined;\n if (refetchableQueryNameNode) {\n return refetchableQueryNameNode.value;\n } else {\n const fragmentName = definitionNode.name.value;\n const fragmentBaseName = fragmentName.replace(/Fragment$/, \"\");\n return `${fragmentBaseName}WatchNodeQuery`;\n }\n}\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAOA,u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ACA,QACA,GAAG,QAAQ,mBACT,OACA,QACA,GAAG,QAAQ,mBAAmB;AAAA,QAC5B,GAAG,QAAQ,sBACT,GAAG,QAAQ,iBAAiB,cAC5B,GAAG,QAAQ,iBAAiB;AAAA,WAIlC,GAAG,QAAQ,oBACT,mBAAmB;AAAA,MAGvB,GAAG,QAAQ,iBAAiB;AAAA;AAAA,aAErB,eAAe,SAAS,sBAAsB;AACvD,UAAM,YAAY,aAAa;AAC/B,UAAM,eAAe,eAAe,KAAK;AACzC,UAAM,gBAAgB,GAAG,SAAS,qBAAqB;AACvD,WAAO;AAAA,MACL,GAAG,QAAQ,wBACT,QACA,QACA,GAAG,QAAQ,mBACT,OACA,QACA,GAAG,QAAQ,mBAAmB;AAAA,QAC5B,GAAG,QAAQ,sBACT,GAAG,QAAQ,iBAAiB,cAC5B,GAAG,QAAQ,iBAAiB;AAAA,WAIlC,GAAG,QAAQ,oBAAoB,mBAAmB;AAAA,MAEpD,GAAG,QAAQ,iBAAiB;AAAA;AAAA;AAGhC,gCAAU,OAAO,sCAAsC,eAAe;AAAA;AAGxE,sBAAsB,gBAAwC;AAvI9D;AAwIE,QAAM,2BAA2B,uCAAe,eAAf,mBAC7B,KAAK,CAAC,cAAc,UAAU,KAAK,UAAU,mBADhB,mBAE7B,cAF6B,mBAElB,KAAK,CAAC,QAAQ,IAAI,KAAK,UAAU,iBAFf,mBAE6B;AAG9D,MAAI,0BAA0B;AAC5B,WAAO,yBAAyB;AAAA,SAC3B;AACL,UAAM,eAAe,eAAe,KAAK;AACzC,UAAM,mBAAmB,aAAa,QAAQ,aAAa;AAC3D,WAAO,GAAG;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,99 @@
1
+ // src/storeObservation/createImportDocumentsTransform.ts
2
+ import invariant from "invariant";
3
+ import {
4
+ factory,
5
+ isIdentifier,
6
+ isNoSubstitutionTemplateLiteral,
7
+ isTaggedTemplateExpression,
8
+ visitEachChild,
9
+ visitNode
10
+ } from "typescript";
11
+ import {
12
+ parse as parseGraphQL
13
+ } from "graphql";
14
+ import {
15
+ dirname,
16
+ join
17
+ } from "path";
18
+ import {
19
+ existsSync
20
+ } from "fs";
21
+ var PREFIX = "__graphitation_";
22
+ var QUERIES_NAMESPACE = "generatedQueries";
23
+ function createImportDocumentsTransform() {
24
+ return (context) => {
25
+ const imports = [];
26
+ const visitor = (node) => {
27
+ if (isTaggedTemplateExpression(node) && isIdentifier(node.tag) && node.tag.escapedText === "graphql") {
28
+ const documentNodes = createGraphQLDocumentNodes(node);
29
+ if (documentNodes) {
30
+ const [importDeclaration, replacementNode] = documentNodes;
31
+ let emitImport = true;
32
+ const sourceFile = node.getSourceFile();
33
+ if (sourceFile) {
34
+ const artefactFile = join(dirname(sourceFile.fileName), importDeclaration.moduleSpecifier.text) + ".ts";
35
+ emitImport = existsSync(artefactFile);
36
+ }
37
+ if (emitImport) {
38
+ imports.push(importDeclaration);
39
+ return replacementNode;
40
+ }
41
+ }
42
+ }
43
+ return visitEachChild(node, visitor, context);
44
+ };
45
+ return (sourceFile) => {
46
+ const outputSourceFile = visitNode(sourceFile, visitor);
47
+ return factory.updateSourceFile(outputSourceFile, [
48
+ ...imports,
49
+ ...outputSourceFile.statements
50
+ ]);
51
+ };
52
+ };
53
+ }
54
+ function createGraphQLDocumentNodes(graphqlTagTemplateNode) {
55
+ var _a;
56
+ const graphqlDoc = isNoSubstitutionTemplateLiteral(graphqlTagTemplateNode.template) ? graphqlTagTemplateNode.template.rawText : graphqlTagTemplateNode.template.head.rawText;
57
+ invariant(graphqlDoc, "Expected a GraphQL document");
58
+ const graphqlAST = parseGraphQL(graphqlDoc);
59
+ const definitionNode = graphqlAST.definitions[0];
60
+ if (definitionNode.kind === "OperationDefinition") {
61
+ if (definitionNode.operation !== "query") {
62
+ return void 0;
63
+ }
64
+ const operationName = (_a = definitionNode.name) == null ? void 0 : _a.value;
65
+ invariant(operationName, "Operations are required to have a name");
66
+ const namespaceName = `${PREFIX}${QUERIES_NAMESPACE}_${operationName}`;
67
+ return [
68
+ factory.createImportDeclaration(void 0, void 0, factory.createImportClause(false, void 0, factory.createNamedImports([
69
+ factory.createImportSpecifier(factory.createIdentifier("documents"), factory.createIdentifier(namespaceName))
70
+ ])), factory.createStringLiteral(`./__generated__/${operationName}.graphql`)),
71
+ factory.createIdentifier(namespaceName)
72
+ ];
73
+ } else if (definitionNode.kind === "FragmentDefinition") {
74
+ const queryName = getQueryName(definitionNode);
75
+ const fragmentName = definitionNode.name.value;
76
+ const namespaceName = `${PREFIX}${QUERIES_NAMESPACE}_${fragmentName}`;
77
+ return [
78
+ factory.createImportDeclaration(void 0, void 0, factory.createImportClause(false, void 0, factory.createNamedImports([
79
+ factory.createImportSpecifier(factory.createIdentifier("documents"), factory.createIdentifier(namespaceName))
80
+ ])), factory.createStringLiteral(`./__generated__/${queryName}.graphql`)),
81
+ factory.createIdentifier(namespaceName)
82
+ ];
83
+ }
84
+ invariant(false, `Unhandled GraphQL definition type: ${definitionNode.kind}`);
85
+ }
86
+ function getQueryName(definitionNode) {
87
+ var _a, _b, _c, _d;
88
+ const refetchableQueryNameNode = (_d = (_c = (_b = (_a = definitionNode.directives) == null ? void 0 : _a.find((directive) => directive.name.value === "refetchable")) == null ? void 0 : _b.arguments) == null ? void 0 : _c.find((arg) => arg.name.value === "queryName")) == null ? void 0 : _d.value;
89
+ if (refetchableQueryNameNode) {
90
+ return refetchableQueryNameNode.value;
91
+ } else {
92
+ const fragmentName = definitionNode.name.value;
93
+ const fragmentBaseName = fragmentName.replace(/Fragment$/, "");
94
+ return `${fragmentBaseName}WatchNodeQuery`;
95
+ }
96
+ }
97
+ export {
98
+ createImportDocumentsTransform
99
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/storeObservation/createImportDocumentsTransform.ts"],
4
+ "sourcesContent": ["/**\n * TODO:\n * - Don't hardcode identifiers but check if they're aliased from their imports.\n * - Support mutations and subscriptions\n * - Properly emit errors from transformer, is invariant ok?\n */\n\nimport invariant from \"invariant\";\nimport * as ts from \"typescript\";\nimport {\n FragmentDefinitionNode,\n parse as parseGraphQL,\n StringValueNode,\n} from \"graphql\";\nimport * as path from \"path\";\nimport * as fs from \"fs\";\n\nconst PREFIX = \"__graphitation_\";\nconst QUERIES_NAMESPACE = \"generatedQueries\";\n\nexport function createImportDocumentsTransform(): ts.TransformerFactory<ts.SourceFile> {\n return (context: ts.TransformationContext): ts.Transformer<ts.SourceFile> => {\n const imports: ts.ImportDeclaration[] = [];\n\n const visitor: ts.Visitor = (node: ts.Node): ts.VisitResult<ts.Node> => {\n if (\n ts.isTaggedTemplateExpression(node) &&\n ts.isIdentifier(node.tag) &&\n node.tag.escapedText === \"graphql\"\n ) {\n const documentNodes = createGraphQLDocumentNodes(node);\n if (documentNodes) {\n const [importDeclaration, replacementNode] = documentNodes;\n // Because we currently only emit new watch queries for fragments\n // on Node types, we cannot just assume the artefact exists for\n // every fragment definition. So check if it exists before emitting\n // the import.\n //\n // TODO: This file checking should not exist and is probably not\n // performant.\n //\n // NOTE: In our test case node.getSourceFile() returns undefined.\n let emitImport = true;\n const sourceFile: ts.SourceFile | undefined = node.getSourceFile();\n if (sourceFile) {\n const artefactFile =\n path.join(\n path.dirname(sourceFile.fileName),\n (importDeclaration.moduleSpecifier as ts.StringLiteral).text\n ) + \".ts\";\n emitImport = fs.existsSync(artefactFile);\n }\n if (emitImport) {\n imports.push(importDeclaration);\n return replacementNode;\n }\n }\n }\n return ts.visitEachChild(node, visitor, context);\n };\n\n return (sourceFile: ts.SourceFile) => {\n const outputSourceFile = ts.visitNode(sourceFile, visitor);\n return ts.factory.updateSourceFile(outputSourceFile, [\n ...imports,\n ...outputSourceFile.statements,\n ]);\n };\n };\n}\n\nfunction createGraphQLDocumentNodes(\n graphqlTagTemplateNode: ts.TaggedTemplateExpression\n): [ts.ImportDeclaration, ts.Identifier] | undefined {\n const graphqlDoc = ts.isNoSubstitutionTemplateLiteral(\n graphqlTagTemplateNode.template\n )\n ? graphqlTagTemplateNode.template.rawText\n : graphqlTagTemplateNode.template.head.rawText;\n invariant(graphqlDoc, \"Expected a GraphQL document\");\n const graphqlAST = parseGraphQL(graphqlDoc);\n const definitionNode = graphqlAST.definitions[0];\n if (definitionNode.kind === \"OperationDefinition\") {\n if (definitionNode.operation !== \"query\") {\n return undefined;\n }\n const operationName = definitionNode.name?.value;\n invariant(operationName, \"Operations are required to have a name\");\n const namespaceName = `${PREFIX}${QUERIES_NAMESPACE}_${operationName}`;\n return [\n ts.factory.createImportDeclaration(\n undefined,\n undefined,\n ts.factory.createImportClause(\n false,\n undefined,\n ts.factory.createNamedImports([\n ts.factory.createImportSpecifier(\n ts.factory.createIdentifier(\"documents\"),\n ts.factory.createIdentifier(namespaceName)\n ),\n ])\n ),\n ts.factory.createStringLiteral(\n `./__generated__/${operationName}.graphql`\n )\n ),\n ts.factory.createIdentifier(namespaceName),\n ];\n } else if (definitionNode.kind === \"FragmentDefinition\") {\n const queryName = getQueryName(definitionNode);\n const fragmentName = definitionNode.name.value;\n const namespaceName = `${PREFIX}${QUERIES_NAMESPACE}_${fragmentName}`;\n return [\n ts.factory.createImportDeclaration(\n undefined,\n undefined,\n ts.factory.createImportClause(\n false,\n undefined,\n ts.factory.createNamedImports([\n ts.factory.createImportSpecifier(\n ts.factory.createIdentifier(\"documents\"),\n ts.factory.createIdentifier(namespaceName)\n ),\n ])\n ),\n ts.factory.createStringLiteral(`./__generated__/${queryName}.graphql`)\n ),\n ts.factory.createIdentifier(namespaceName),\n ];\n }\n invariant(false, `Unhandled GraphQL definition type: ${definitionNode.kind}`);\n}\n\nfunction getQueryName(definitionNode: FragmentDefinitionNode) {\n const refetchableQueryNameNode = definitionNode.directives\n ?.find((directive) => directive.name.value === \"refetchable\")\n ?.arguments?.find((arg) => arg.name.value === \"queryName\")?.value as\n | StringValueNode\n | undefined;\n if (refetchableQueryNameNode) {\n return refetchableQueryNameNode.value;\n } else {\n const fragmentName = definitionNode.name.value;\n const fragment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ransform.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"createImportDocumentsTransform.test.d.ts","sourceRoot":"","sources":["../../src/storeObservation/createImportDocumentsTransform.test.ts"],"names":[],"mappings":""}
@@ -0,0 +1,62 @@
1
+ var __create = Object.create;
2
+ var __defProp = Object.defineProperty;
3
+ var __getProtoOf = Object.getPrototypeOf;
4
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
7
+ var __markAsModule = (target) => __defProp(target, "__esModule", {value: true});
8
+ var __reExport = (target, module2, desc) => {
9
+ if (module2 && typeof module2 === "object" || typeof module2 === "function") {
10
+ for (let key of __getOwnPropNames(module2))
11
+ if (!__hasOwnProp.call(target, key) && key !== "default")
12
+ __defProp(target, key, {get: () => module2[key], enumerable: !(desc = __getOwnPropDesc(module2, key)) || desc.enumerable});
13
+ }
14
+ return target;
15
+ };
16
+ var __toModule = (module2) => {
17
+ return __reExport(__markAsModule(__defProp(module2 != null ? __create(__getProtoOf(module2)) : {}, "default", module2 && module2.__esModule && "default" in module2 ? {get: () => module2.default, enumerable: true} : {value: module2, enumerable: true})), module2);
18
+ };
19
+ var ts = __toModule(require("typescript"));
20
+ var import_createImportDocumentsTransform = __toModule(require("./createImportDocumentsTransform"));
21
+ expect.addSnapshotSerializer({
22
+ test: (val) => typeof val === "string",
23
+ print: (val) => {
24
+ return val.trimRight();
25
+ }
26
+ });
27
+ function transform(sourceText) {
28
+ const sourceFile = ts.createSourceFile("SomeComponent.tsx", sourceText, ts.ScriptTarget.Latest);
29
+ const result = ts.transform(sourceFile, [(0, import_createImportDocumentsTransform.createImportDocumentsTransform)()]);
30
+ const printer = ts.createPrinter();
31
+ return printer.printFile(result.transformed[0]);
32
+ }
33
+ describe(import_createImportDocumentsTransform.createImportDocumentsTransform, () => {
34
+ it("works with documents without interpolation", () => {
35
+ const source = `
36
+ const doc = graphql\`
37
+ fragment SomeComponentFragment on Query {
38
+ helloWorld
39
+ }
40
+ \`
41
+ `;
42
+ expect(transform(source)).toMatchInlineSnapshot(`
43
+ import { documents as __graphitation_generatedQueries_SomeComponentFragment } from "./__generated__/SomeComponentWatchNodeQuery.graphql";
44
+ const doc = __graphitation_generatedQueries_SomeComponentFragment;
45
+ `);
46
+ });
47
+ it("works with documents with interpolation", () => {
48
+ const source = `
49
+ const doc = graphql\`
50
+ query SomeComponentQuery($id: ID!) {
51
+ helloWorld
52
+ ...SomeOtherComponentFragment
53
+ }
54
+ \${SomeOtherComponentFragment}
55
+ \`
56
+ `;
57
+ expect(transform(source)).toMatchInlineSnapshot(`
58
+ import { documents as __graphitation_generatedQueries_SomeComponentQuery } from "./__generated__/SomeComponentQuery.graphql";
59
+ const doc = __graphitation_generatedQueries_SomeComponentQuery;
60
+ `);
61
+ });
62
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/storeObservation/createImportDocumentsTransform.test.ts"],
4
+ "sourcesContent": ["import * as ts from \"typescript\";\nimport { createImportDocumentsTransform } from \"./createImportDocumentsTransform\";\n\nexpect.addSnapshotSerializer({\n test: (val) => typeof val === \"string\",\n print: (val) => {\n return (val as string).trimRight();\n },\n});\n\nfunction transform(sourceText: string): string {\n const sourceFile = ts.createSourceFile(\n \"SomeComponent.tsx\",\n sourceText,\n ts.ScriptTarget.Latest\n );\n const result = ts.transform(sourceFile, [createImportDocumentsTransform()]);\n const printer = ts.createPrinter();\n return printer.printFile(result.transformed[0]);\n}\n\ndescribe(createImportDocumentsTransform, () => {\n it(\"works with documents without interpolation\", () => {\n const source = `\n const doc = graphql\\`\n fragment SomeComponentFragment on Query {\n helloWorld\n }\n \\`\n `;\n expect(transform(source)).toMatchInlineSnapshot(`\n import { documents as __graphitation_generatedQueries_SomeComponentFragment } from \"./__generated__/SomeComponentWatchNodeQuery.graphql\";\n const doc = __graphitation_generatedQueries_SomeComponentFragment;\n `);\n });\n\n it(\"works with documents with interpolation\", () => {\n const source = `\n const doc = graphql\\`\n query SomeComponentQuery($id: ID!) {\n helloWorld\n ...SomeOtherComponentFragment\n }\n \\${SomeOtherComponentFragment}\n \\`\n `;\n expect(transform(source)).toMatchInlineSnapshot(`\n import { documents as __graphitation_generatedQueries_SomeComponentQuery } from \"./__generated__/SomeComponentQuery.graphql\";\n const doc = __graphitation_generatedQueries_SomeComponentQuery;\n `);\n });\n});\n"],
5
+ "mappings": ";;;;;;;;;;;;;;;;;;AAAA,SAAoB;AACpB,4CAA+C;AAE/C,OAAO,sBAAsB;AAAA,EAC3B,MAAM,CAAC,QAAQ,OAAO,QAAQ;AAAA,EAC9B,OAAO,CAAC,QAAQ;AACd,WAAQ,IAAe;AAAA;AAAA;AAI3B,mBAAmB,YAA4B;AAC7C,QAAM,aAAa,GAAG,iBACpB,qBACA,YACA,GAAG,aAAa;AAElB,QAAM,SAAS,GAAG,UAAU,YAAY,CAAC;AACzC,QAAM,UAAU,GAAG;AACnB,SAAO,QAAQ,UAAU,OAAO,YAAY;AAAA;AAG9C,SAAS,sEAAgC,MAAM;AAC7C,KAAG,8CAA8C,MAAM;AACrD,UAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOf,WAAO,UAAU,SAAS,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAMlD,KAAG,2CAA2C,MAAM;AAClD,UAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASf,WAAO,UAAU,SAAS,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,50 @@
1
+ // src/storeObservation/createImportDocumentsTransform.test.ts
2
+ import {
3
+ ScriptTarget,
4
+ createPrinter,
5
+ createSourceFile,
6
+ transform
7
+ } from "typescript";
8
+ import {createImportDocumentsTransform} from "./createImportDocumentsTransform.mjs";
9
+ expect.addSnapshotSerializer({
10
+ test: (val) => typeof val === "string",
11
+ print: (val) => {
12
+ return val.trimRight();
13
+ }
14
+ });
15
+ function transform2(sourceText) {
16
+ const sourceFile = createSourceFile("SomeComponent.tsx", sourceText, ScriptTarget.Latest);
17
+ const result = transform(sourceFile, [createImportDocumentsTransform()]);
18
+ const printer = createPrinter();
19
+ return printer.printFile(result.transformed[0]);
20
+ }
21
+ describe(createImportDocumentsTransform, () => {
22
+ it("works with documents without interpolation", () => {
23
+ const source = `
24
+ const doc = graphql\`
25
+ fragment SomeComponentFragment on Query {
26
+ helloWorld
27
+ }
28
+ \`
29
+ `;
30
+ expect(transform2(source)).toMatchInlineSnapshot(`
31
+ import { documents as __graphitation_generatedQueries_SomeComponentFragment } from "./__generated__/SomeComponentWatchNodeQuery.graphql";
32
+ const doc = __graphitation_generatedQueries_SomeComponentFragment;
33
+ `);
34
+ });
35
+ it("works with documents with interpolation", () => {
36
+ const source = `
37
+ const doc = graphql\`
38
+ query SomeComponentQuery($id: ID!) {
39
+ helloWorld
40
+ ...SomeOtherComponentFragment
41
+ }
42
+ \${SomeOtherComponentFragment}
43
+ \`
44
+ `;
45
+ expect(transform2(source)).toMatchInlineSnapshot(`
46
+ import { documents as __graphitation_generatedQueries_SomeComponentQuery } from "./__generated__/SomeComponentQuery.graphql";
47
+ const doc = __graphitation_generatedQueries_SomeComponentQuery;
48
+ `);
49
+ });
50
+ });
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/storeObservation/createImportDocumentsTransform.test.ts"],
4
+ "sourcesContent": ["import * as ts from \"typescript\";\nimport { createImportDocumentsTransform } from \"./createImportDocumentsTransform\";\n\nexpect.addSnapshotSerializer({\n test: (val) => typeof val === \"string\",\n print: (val) => {\n return (val as string).trimRight();\n },\n});\n\nfunction transform(sourceText: string): string {\n const sourceFile = ts.createSourceFile(\n \"SomeComponent.tsx\",\n sourceText,\n ts.ScriptTarget.Latest\n );\n const result = ts.transform(sourceFile, [createImportDocumentsTransform()]);\n const printer = ts.createPrinter();\n return printer.printFile(result.transformed[0]);\n}\n\ndescribe(createImportDocumentsTransform, () => {\n it(\"works with documents without interpolation\", () => {\n const source = `\n const doc = graphql\\`\n fragment SomeComponentFragment on Query {\n helloWorld\n }\n \\`\n `;\n expect(transform(source)).toMatchInlineSnapshot(`\n import { documents as __graphitation_generatedQueries_SomeComponentFragment } from \"./__generated__/SomeComponentWatchNodeQuery.graphql\";\n const doc = __graphitation_generatedQueries_SomeComponentFragment;\n `);\n });\n\n it(\"works with documents with interpolation\", () => {\n const source = `\n const doc = graphql\\`\n query SomeComponentQuery($id: ID!) {\n helloWorld\n ...SomeOtherComponentFragment\n }\n \\${SomeOtherComponentFragment}\n \\`\n `;\n expect(transform(source)).toMatchInlineSnapshot(`\n import { documents as __graphitation_generatedQueries_SomeComponentQuery } from \"./__generated__/SomeComponentQuery.graphql\";\n const doc = __graphitation_generatedQueries_SomeComponentQuery;\n `);\n });\n});\n"],
5
+ "mappings": ";AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AACA;AAEA,OAAO,sBAAsB;AAAA,EAC3B,MAAM,CAAC,QAAQ,OAAO,QAAQ;AAAA,EAC9B,OAAO,CAAC,QAAQ;AACd,WAAQ,IAAe;AAAA;AAAA;AAI3B,oBAAmB,YAA4B;AAC7C,QAAM,aAAa,AAAG,iBACpB,qBACA,YACA,AAAG,aAAa;AAElB,QAAM,SAAS,AAAG,UAAU,YAAY,CAAC;AACzC,QAAM,UAAU,AAAG;AACnB,SAAO,QAAQ,UAAU,OAAO,YAAY;AAAA;AAG9C,SAAS,gCAAgC,MAAM;AAC7C,KAAG,8CAA8C,MAAM;AACrD,UAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAOf,WAAO,WAAU,SAAS,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAMlD,KAAG,2CAA2C,MAAM;AAClD,UAAM,SAAS;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA;AASf,WAAO,WAAU,SAAS,sBAAsB;AAAA;AAAA;AAAA;AAAA;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,3 @@
1
+ import { FieldReadFunction } from "@apollo/client";
2
+ export declare const fragmentReferencesFieldPolicy: FieldReadFunction;
3
+ //# sourceMappingURL=fragmentReferencesFieldPolicy.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fragmentReferencesFieldPolicy.d.ts","sourceRoot":"","sources":["../../src/storeObservation/fragmentReferencesFieldPolicy.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,iBAAiB,EAAE,MAAM,gBAAgB,CAAC;AAEnD,eAAO,MAAM,6BAA6B,EAAE,iBAS3C,CAAC"}
@@ -0,0 +1,13 @@
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
+ fragmentReferencesFieldPolicy: () => fragmentReferencesFieldPolicy
10
+ });
11
+ const fragmentReferencesFieldPolicy = (_existingCacheData, {variables}) => {
12
+ return !variables ? null : variables.__fragments === void 0 ? variables : variables.__fragments;
13
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/storeObservation/fragmentReferencesFieldPolicy.ts"],
4
+ "sourcesContent": ["import { FieldReadFunction } from \"@apollo/client\";\n\nexport const fragmentReferencesFieldPolicy: FieldReadFunction = (\n _existingCacheData,\n { variables }\n) => {\n return !variables\n ? null\n : variables.__fragments === undefined\n ? variables\n : variables.__fragments;\n};\n"],
5
+ "mappings": ";;;;;;AAAA;AAAA;AAAA;AAAA;AAEO,MAAM,gCAAmD,CAC9D,oBACA,CAAE,eACC;AACH,SAAO,CAAC,YACJ,OACA,UAAU,gBAAgB,SAC1B,YACA,UAAU;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,7 @@
1
+ // src/storeObservation/fragmentReferencesFieldPolicy.ts
2
+ var fragmentReferencesFieldPolicy = (_existingCacheData, {variables}) => {
3
+ return !variables ? null : variables.__fragments === void 0 ? variables : variables.__fragments;
4
+ };
5
+ export {
6
+ fragmentReferencesFieldPolicy
7
+ };
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/storeObservation/fragmentReferencesFieldPolicy.ts"],
4
+ "sourcesContent": ["import { FieldReadFunction } from \"@apollo/client\";\n\nexport const fragmentReferencesFieldPolicy: FieldReadFunction = (\n _existingCacheData,\n { variables }\n) => {\n return !variables\n ? null\n : variables.__fragments === undefined\n ? variables\n : variables.__fragments;\n};\n"],
5
+ "mappings": ";AAEO,IAAM,gCAAmD,CAC9D,oBACA,CAAE,eACC;AACH,SAAO,CAAC,YACJ,OACA,UAAU,gBAAgB,SAC1B,YACA,UAAU;AAAA;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=fragmentReferencesFieldPolicy.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fragmentReferencesFieldPolicy.test.d.ts","sourceRoot":"","sources":["../../src/storeObservation/fragmentReferencesFieldPolicy.test.ts"],"names":[],"mappings":""}