@graphql-box/connection-resolver 4.1.4 → 5.0.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 (490) hide show
  1. package/README.md +1 -5
  2. package/dist/cjs/index.cjs +703 -0
  3. package/dist/cjs/index.cjs.map +1 -0
  4. package/dist/esm/index.mjs +700 -0
  5. package/dist/esm/index.mjs.map +1 -0
  6. package/dist/types/cjs/__testUtils__/generateCursorCache.d.cts +10 -0
  7. package/dist/types/cjs/__testUtils__/generateCursorCache.d.cts.map +1 -0
  8. package/dist/types/cjs/__testUtils__/generatePageResponse.d.cts +9 -0
  9. package/dist/types/cjs/__testUtils__/generatePageResponse.d.cts.map +1 -0
  10. package/dist/types/cjs/__testUtils__/generatePages.d.cts +2 -0
  11. package/dist/types/cjs/__testUtils__/generatePages.d.cts.map +1 -0
  12. package/dist/types/cjs/helpers/cacheCursors.d.cts +12 -0
  13. package/dist/types/cjs/helpers/cacheCursors.d.cts.map +1 -0
  14. package/dist/types/cjs/helpers/extractEdges.d.cts +3 -0
  15. package/dist/types/cjs/helpers/extractEdges.d.cts.map +1 -0
  16. package/dist/types/cjs/helpers/extractNodes.d.cts +3 -0
  17. package/dist/types/cjs/helpers/extractNodes.d.cts.map +1 -0
  18. package/dist/types/cjs/helpers/getCount.d.cts +3 -0
  19. package/dist/types/cjs/helpers/getCount.d.cts.map +1 -0
  20. package/dist/types/cjs/helpers/getCurrentPageStartAndEndIndexes.d.cts +14 -0
  21. package/dist/types/cjs/helpers/getCurrentPageStartAndEndIndexes.d.cts.map +1 -0
  22. package/dist/types/cjs/helpers/getCursor.d.cts +3 -0
  23. package/dist/types/cjs/helpers/getCursor.d.cts.map +1 -0
  24. package/dist/types/cjs/helpers/getDirection.d.cts +3 -0
  25. package/dist/types/cjs/helpers/getDirection.d.cts.map +1 -0
  26. package/dist/types/cjs/helpers/getInRangeCachedEdges.d.cts +8 -0
  27. package/dist/types/cjs/helpers/getInRangeCachedEdges.d.cts.map +1 -0
  28. package/dist/types/cjs/helpers/getIndexesOnCurrentPage.d.cts +10 -0
  29. package/dist/types/cjs/helpers/getIndexesOnCurrentPage.d.cts.map +1 -0
  30. package/dist/types/cjs/helpers/getIndexesOnLastPage.d.cts +3 -0
  31. package/dist/types/cjs/helpers/getIndexesOnLastPage.d.cts.map +1 -0
  32. package/dist/types/cjs/helpers/getPageNumbersToRequest.d.cts +12 -0
  33. package/dist/types/cjs/helpers/getPageNumbersToRequest.d.cts.map +1 -0
  34. package/dist/types/cjs/helpers/getPagesMissingFromCache.d.cts +3 -0
  35. package/dist/types/cjs/helpers/getPagesMissingFromCache.d.cts.map +1 -0
  36. package/dist/types/cjs/helpers/getResultsOnLastPage.d.cts +6 -0
  37. package/dist/types/cjs/helpers/getResultsOnLastPage.d.cts.map +1 -0
  38. package/dist/types/cjs/helpers/getStartAndEndCursors.d.cts +4 -0
  39. package/dist/types/cjs/helpers/getStartAndEndCursors.d.cts.map +1 -0
  40. package/dist/types/cjs/helpers/getStartAndEndIndexes.d.cts +15 -0
  41. package/dist/types/cjs/helpers/getStartAndEndIndexes.d.cts.map +1 -0
  42. package/dist/types/cjs/helpers/getStartAndEndPageNumbers.d.cts +13 -0
  43. package/dist/types/cjs/helpers/getStartAndEndPageNumbers.d.cts.map +1 -0
  44. package/dist/types/cjs/helpers/hasPreviousNextPage.d.cts +14 -0
  45. package/dist/types/cjs/helpers/hasPreviousNextPage.d.cts.map +1 -0
  46. package/dist/types/cjs/helpers/isCursorFirst.d.cts +7 -0
  47. package/dist/types/cjs/helpers/isCursorFirst.d.cts.map +1 -0
  48. package/dist/types/cjs/helpers/isCursorLast.d.cts +10 -0
  49. package/dist/types/cjs/helpers/isCursorLast.d.cts.map +1 -0
  50. package/dist/types/cjs/helpers/isCursorSupplied.d.cts +4 -0
  51. package/dist/types/cjs/helpers/isCursorSupplied.d.cts.map +1 -0
  52. package/dist/types/cjs/helpers/isFirstPage.d.cts +2 -0
  53. package/dist/types/cjs/helpers/isFirstPage.d.cts.map +1 -0
  54. package/dist/types/cjs/helpers/isLastPage.d.cts +6 -0
  55. package/dist/types/cjs/helpers/isLastPage.d.cts.map +1 -0
  56. package/dist/types/cjs/helpers/makeEdges.d.cts +6 -0
  57. package/dist/types/cjs/helpers/makeEdges.d.cts.map +1 -0
  58. package/dist/types/cjs/helpers/makeEntry.d.cts +10 -0
  59. package/dist/types/cjs/helpers/makeEntry.d.cts.map +1 -0
  60. package/dist/types/cjs/helpers/mergeCachedEdges.d.cts +3 -0
  61. package/dist/types/cjs/helpers/mergeCachedEdges.d.cts.map +1 -0
  62. package/dist/types/cjs/helpers/removeConnectionInputOptions.d.cts +2 -0
  63. package/dist/types/cjs/helpers/removeConnectionInputOptions.d.cts.map +1 -0
  64. package/dist/types/cjs/helpers/requestAndCachePages.d.cts +21 -0
  65. package/dist/types/cjs/helpers/requestAndCachePages.d.cts.map +1 -0
  66. package/dist/types/cjs/helpers/requestOutstandingPages.d.cts +18 -0
  67. package/dist/types/cjs/helpers/requestOutstandingPages.d.cts.map +1 -0
  68. package/dist/types/cjs/helpers/resolveConnection.d.cts +24 -0
  69. package/dist/types/cjs/helpers/resolveConnection.d.cts.map +1 -0
  70. package/dist/types/cjs/helpers/retrieveCachedConnection.d.cts +25 -0
  71. package/dist/types/cjs/helpers/retrieveCachedConnection.d.cts.map +1 -0
  72. package/dist/types/cjs/helpers/retrieveCachedEdgesByPage.d.cts +11 -0
  73. package/dist/types/cjs/helpers/retrieveCachedEdgesByPage.d.cts.map +1 -0
  74. package/dist/types/cjs/helpers/retrieveEntry.d.cts +8 -0
  75. package/dist/types/cjs/helpers/retrieveEntry.d.cts.map +1 -0
  76. package/dist/types/cjs/helpers/validateCursor.d.cts +10 -0
  77. package/dist/types/cjs/helpers/validateCursor.d.cts.map +1 -0
  78. package/dist/types/cjs/index.d.cts +4 -0
  79. package/dist/types/cjs/index.d.cts.map +1 -0
  80. package/dist/types/cjs/main/index.d.cts +5 -0
  81. package/dist/types/cjs/main/index.d.cts.map +1 -0
  82. package/{lib/types/defs/index.d.ts → dist/types/cjs/types.d.cts} +22 -27
  83. package/dist/types/cjs/types.d.cts.map +1 -0
  84. package/dist/types/esm/__testUtils__/generateCursorCache.d.ts +10 -0
  85. package/dist/types/esm/__testUtils__/generateCursorCache.d.ts.map +1 -0
  86. package/dist/types/esm/__testUtils__/generatePageResponse.d.ts +9 -0
  87. package/dist/types/esm/__testUtils__/generatePageResponse.d.ts.map +1 -0
  88. package/dist/types/esm/__testUtils__/generatePages.d.ts +2 -0
  89. package/dist/types/esm/__testUtils__/generatePages.d.ts.map +1 -0
  90. package/dist/types/esm/helpers/cacheCursors.d.ts +12 -0
  91. package/dist/types/esm/helpers/cacheCursors.d.ts.map +1 -0
  92. package/dist/types/esm/helpers/extractEdges.d.ts +3 -0
  93. package/dist/types/esm/helpers/extractEdges.d.ts.map +1 -0
  94. package/dist/types/esm/helpers/extractNodes.d.ts +3 -0
  95. package/dist/types/esm/helpers/extractNodes.d.ts.map +1 -0
  96. package/dist/types/esm/helpers/getCount.d.ts +3 -0
  97. package/dist/types/esm/helpers/getCount.d.ts.map +1 -0
  98. package/{lib/types → dist/types/esm}/helpers/getCurrentPageStartAndEndIndexes.d.ts +3 -3
  99. package/dist/types/esm/helpers/getCurrentPageStartAndEndIndexes.d.ts.map +1 -0
  100. package/dist/types/esm/helpers/getCursor.d.ts +3 -0
  101. package/dist/types/esm/helpers/getCursor.d.ts.map +1 -0
  102. package/dist/types/esm/helpers/getDirection.d.ts +3 -0
  103. package/dist/types/esm/helpers/getDirection.d.ts.map +1 -0
  104. package/dist/types/esm/helpers/getInRangeCachedEdges.d.ts +8 -0
  105. package/dist/types/esm/helpers/getInRangeCachedEdges.d.ts.map +1 -0
  106. package/dist/types/esm/helpers/getIndexesOnCurrentPage.d.ts +10 -0
  107. package/dist/types/esm/helpers/getIndexesOnCurrentPage.d.ts.map +1 -0
  108. package/dist/types/esm/helpers/getIndexesOnLastPage.d.ts +3 -0
  109. package/dist/types/esm/helpers/getIndexesOnLastPage.d.ts.map +1 -0
  110. package/dist/types/esm/helpers/getPageNumbersToRequest.d.ts +12 -0
  111. package/dist/types/esm/helpers/getPageNumbersToRequest.d.ts.map +1 -0
  112. package/dist/types/esm/helpers/getPagesMissingFromCache.d.ts +3 -0
  113. package/dist/types/esm/helpers/getPagesMissingFromCache.d.ts.map +1 -0
  114. package/dist/types/esm/helpers/getResultsOnLastPage.d.ts +6 -0
  115. package/dist/types/esm/helpers/getResultsOnLastPage.d.ts.map +1 -0
  116. package/dist/types/esm/helpers/getStartAndEndCursors.d.ts +4 -0
  117. package/dist/types/esm/helpers/getStartAndEndCursors.d.ts.map +1 -0
  118. package/dist/types/esm/helpers/getStartAndEndIndexes.d.ts +15 -0
  119. package/dist/types/esm/helpers/getStartAndEndIndexes.d.ts.map +1 -0
  120. package/dist/types/esm/helpers/getStartAndEndPageNumbers.d.ts +13 -0
  121. package/dist/types/esm/helpers/getStartAndEndPageNumbers.d.ts.map +1 -0
  122. package/{lib/types → dist/types/esm}/helpers/hasPreviousNextPage.d.ts +3 -3
  123. package/dist/types/esm/helpers/hasPreviousNextPage.d.ts.map +1 -0
  124. package/dist/types/esm/helpers/isCursorFirst.d.ts +7 -0
  125. package/dist/types/esm/helpers/isCursorFirst.d.ts.map +1 -0
  126. package/dist/types/esm/helpers/isCursorLast.d.ts +10 -0
  127. package/dist/types/esm/helpers/isCursorLast.d.ts.map +1 -0
  128. package/dist/types/esm/helpers/isCursorSupplied.d.ts +4 -0
  129. package/dist/types/esm/helpers/isCursorSupplied.d.ts.map +1 -0
  130. package/dist/types/esm/helpers/isFirstPage.d.ts +2 -0
  131. package/dist/types/esm/helpers/isFirstPage.d.ts.map +1 -0
  132. package/dist/types/esm/helpers/isLastPage.d.ts +6 -0
  133. package/dist/types/esm/helpers/isLastPage.d.ts.map +1 -0
  134. package/dist/types/esm/helpers/makeEdges.d.ts +6 -0
  135. package/dist/types/esm/helpers/makeEdges.d.ts.map +1 -0
  136. package/dist/types/esm/helpers/makeEntry.d.ts +10 -0
  137. package/dist/types/esm/helpers/makeEntry.d.ts.map +1 -0
  138. package/dist/types/esm/helpers/mergeCachedEdges.d.ts +3 -0
  139. package/dist/types/esm/helpers/mergeCachedEdges.d.ts.map +1 -0
  140. package/dist/types/esm/helpers/removeConnectionInputOptions.d.ts +2 -0
  141. package/dist/types/esm/helpers/removeConnectionInputOptions.d.ts.map +1 -0
  142. package/dist/types/esm/helpers/requestAndCachePages.d.ts +21 -0
  143. package/dist/types/esm/helpers/requestAndCachePages.d.ts.map +1 -0
  144. package/dist/types/esm/helpers/requestOutstandingPages.d.ts +18 -0
  145. package/dist/types/esm/helpers/requestOutstandingPages.d.ts.map +1 -0
  146. package/dist/types/esm/helpers/resolveConnection.d.ts +24 -0
  147. package/dist/types/esm/helpers/resolveConnection.d.ts.map +1 -0
  148. package/{lib/types → dist/types/esm}/helpers/retrieveCachedConnection.d.ts +5 -6
  149. package/dist/types/esm/helpers/retrieveCachedConnection.d.ts.map +1 -0
  150. package/dist/types/esm/helpers/retrieveCachedEdgesByPage.d.ts +11 -0
  151. package/dist/types/esm/helpers/retrieveCachedEdgesByPage.d.ts.map +1 -0
  152. package/dist/types/esm/helpers/retrieveEntry.d.ts +8 -0
  153. package/dist/types/esm/helpers/retrieveEntry.d.ts.map +1 -0
  154. package/dist/types/esm/helpers/validateCursor.d.ts +10 -0
  155. package/dist/types/esm/helpers/validateCursor.d.ts.map +1 -0
  156. package/dist/types/esm/index.d.ts +4 -0
  157. package/dist/types/esm/index.d.ts.map +1 -0
  158. package/dist/types/esm/main/index.d.ts +5 -0
  159. package/dist/types/esm/main/index.d.ts.map +1 -0
  160. package/dist/types/esm/types.d.ts +77 -0
  161. package/dist/types/esm/types.d.ts.map +1 -0
  162. package/dist/types/tsconfig.build.tsbuildinfo +1 -0
  163. package/package.json +56 -38
  164. package/src/__testUtils__/generateCursorCache.ts +20 -14
  165. package/src/__testUtils__/generatePageResponse.ts +17 -12
  166. package/src/__testUtils__/generatePages.ts +5 -5
  167. package/src/helpers/cacheCursors.ts +10 -7
  168. package/src/helpers/extractEdges.ts +3 -3
  169. package/src/helpers/extractNodes.ts +2 -2
  170. package/src/helpers/getCount.test.ts +10 -6
  171. package/src/helpers/getCount.ts +2 -2
  172. package/src/helpers/getCurrentPageStartAndEndIndexes.ts +1 -1
  173. package/src/helpers/getCursor.test.ts +10 -6
  174. package/src/helpers/getCursor.ts +2 -2
  175. package/src/helpers/getDirection.test.ts +10 -6
  176. package/src/helpers/getDirection.ts +3 -1
  177. package/src/helpers/getInRangeCachedEdges.ts +10 -7
  178. package/src/helpers/getIndexesOnCurrentPage.test.ts +14 -10
  179. package/src/helpers/getIndexesOnCurrentPage.ts +11 -6
  180. package/src/helpers/getIndexesOnLastPage.test.ts +10 -6
  181. package/src/helpers/getIndexesOnLastPage.ts +3 -2
  182. package/src/helpers/getPageNumbersToRequest.test.ts +15 -11
  183. package/src/helpers/getPageNumbersToRequest.ts +17 -6
  184. package/src/helpers/getPagesMissingFromCache.ts +5 -5
  185. package/src/helpers/getResultsOnLastPage.test.ts +10 -6
  186. package/src/helpers/getResultsOnLastPage.ts +1 -1
  187. package/src/helpers/getStartAndEndCursors.ts +1 -1
  188. package/src/helpers/getStartAndEndIndexes.test.ts +77 -57
  189. package/src/helpers/getStartAndEndIndexes.ts +28 -22
  190. package/src/helpers/getStartAndEndPageNumbers.test.ts +46 -28
  191. package/src/helpers/getStartAndEndPageNumbers.ts +12 -12
  192. package/src/helpers/hasPreviousNextPage.test.ts +17 -8
  193. package/src/helpers/hasPreviousNextPage.ts +6 -4
  194. package/src/helpers/isCursorFirst.test.ts +13 -7
  195. package/src/helpers/isCursorFirst.ts +3 -2
  196. package/src/helpers/isCursorLast.test.ts +27 -23
  197. package/src/helpers/isCursorLast.ts +4 -4
  198. package/src/helpers/isCursorSupplied.test.ts +18 -10
  199. package/src/helpers/isCursorSupplied.ts +3 -2
  200. package/src/helpers/isFirstPage.test.ts +10 -6
  201. package/src/helpers/isFirstPage.ts +1 -1
  202. package/src/helpers/isLastPage.test.ts +10 -6
  203. package/src/helpers/isLastPage.ts +1 -1
  204. package/src/helpers/makeEdges.ts +3 -3
  205. package/src/helpers/makeEntry.ts +8 -5
  206. package/src/helpers/mergeCachedEdges.ts +5 -5
  207. package/src/helpers/removeConnectionInputOptions.test.ts +10 -8
  208. package/src/helpers/removeConnectionInputOptions.ts +4 -3
  209. package/src/helpers/requestAndCachePages.ts +14 -11
  210. package/src/helpers/requestOutstandingPages.ts +18 -19
  211. package/src/helpers/resolveConnection.ts +20 -34
  212. package/src/helpers/retrieveCachedConnection.test.ts +703 -338
  213. package/src/helpers/retrieveCachedConnection.ts +28 -20
  214. package/src/helpers/retrieveCachedEdgesByPage.ts +10 -10
  215. package/src/helpers/retrieveEntry.ts +32 -0
  216. package/src/helpers/validateCursor.test.ts +88 -61
  217. package/src/helpers/validateCursor.ts +30 -26
  218. package/src/index.ts +3 -3
  219. package/src/main/__snapshots__/index.test.ts.snap +258 -258
  220. package/src/main/index.test.ts +405 -287
  221. package/src/main/index.ts +37 -35
  222. package/src/{defs/index.ts → types.ts} +12 -18
  223. package/tsconfig.build.json +10 -0
  224. package/tsconfig.json +11 -0
  225. package/lib/browser/index.js +0 -2
  226. package/lib/browser/index.js.map +0 -1
  227. package/lib/browser/production.analysis.txt +0 -314
  228. package/lib/main/__testUtils__/generateCursorCache.js +0 -88
  229. package/lib/main/__testUtils__/generateCursorCache.js.map +0 -1
  230. package/lib/main/__testUtils__/generatePageResponse.js +0 -33
  231. package/lib/main/__testUtils__/generatePageResponse.js.map +0 -1
  232. package/lib/main/__testUtils__/generatePages.js +0 -23
  233. package/lib/main/__testUtils__/generatePages.js.map +0 -1
  234. package/lib/main/defs/index.js +0 -2
  235. package/lib/main/defs/index.js.map +0 -1
  236. package/lib/main/helpers/cacheCursors.js +0 -40
  237. package/lib/main/helpers/cacheCursors.js.map +0 -1
  238. package/lib/main/helpers/extractEdges.js +0 -11
  239. package/lib/main/helpers/extractEdges.js.map +0 -1
  240. package/lib/main/helpers/extractNodes.js +0 -11
  241. package/lib/main/helpers/extractNodes.js.map +0 -1
  242. package/lib/main/helpers/getCount.js +0 -14
  243. package/lib/main/helpers/getCount.js.map +0 -1
  244. package/lib/main/helpers/getCurrentPageStartAndEndIndexes.js +0 -23
  245. package/lib/main/helpers/getCurrentPageStartAndEndIndexes.js.map +0 -1
  246. package/lib/main/helpers/getCursor.js +0 -14
  247. package/lib/main/helpers/getCursor.js.map +0 -1
  248. package/lib/main/helpers/getDirection.js +0 -11
  249. package/lib/main/helpers/getDirection.js.map +0 -1
  250. package/lib/main/helpers/getInRangeCachedEdges.js +0 -36
  251. package/lib/main/helpers/getInRangeCachedEdges.js.map +0 -1
  252. package/lib/main/helpers/getIndexesOnCurrentPage.js +0 -30
  253. package/lib/main/helpers/getIndexesOnCurrentPage.js.map +0 -1
  254. package/lib/main/helpers/getIndexesOnLastPage.js +0 -21
  255. package/lib/main/helpers/getIndexesOnLastPage.js.map +0 -1
  256. package/lib/main/helpers/getPageNumbersToRequest.js +0 -43
  257. package/lib/main/helpers/getPageNumbersToRequest.js.map +0 -1
  258. package/lib/main/helpers/getPagesMissingFromCache.js +0 -19
  259. package/lib/main/helpers/getPagesMissingFromCache.js.map +0 -1
  260. package/lib/main/helpers/getResultsOnLastPage.js +0 -17
  261. package/lib/main/helpers/getResultsOnLastPage.js.map +0 -1
  262. package/lib/main/helpers/getStartAndEndCursors.js +0 -22
  263. package/lib/main/helpers/getStartAndEndCursors.js.map +0 -1
  264. package/lib/main/helpers/getStartAndEndIndexes.js +0 -105
  265. package/lib/main/helpers/getStartAndEndIndexes.js.map +0 -1
  266. package/lib/main/helpers/getStartAndEndPageNumbers.js +0 -51
  267. package/lib/main/helpers/getStartAndEndPageNumbers.js.map +0 -1
  268. package/lib/main/helpers/hasPreviousNextPage.js +0 -33
  269. package/lib/main/helpers/hasPreviousNextPage.js.map +0 -1
  270. package/lib/main/helpers/isCursorFirst.js +0 -17
  271. package/lib/main/helpers/isCursorFirst.js.map +0 -1
  272. package/lib/main/helpers/isCursorLast.js +0 -27
  273. package/lib/main/helpers/isCursorLast.js.map +0 -1
  274. package/lib/main/helpers/isCursorSupplied.js +0 -14
  275. package/lib/main/helpers/isCursorSupplied.js.map +0 -1
  276. package/lib/main/helpers/isFirstPage.js +0 -11
  277. package/lib/main/helpers/isFirstPage.js.map +0 -1
  278. package/lib/main/helpers/isLastPage.js +0 -14
  279. package/lib/main/helpers/isLastPage.js.map +0 -1
  280. package/lib/main/helpers/makeEdges.js +0 -14
  281. package/lib/main/helpers/makeEdges.js.map +0 -1
  282. package/lib/main/helpers/makeEntry.js +0 -38
  283. package/lib/main/helpers/makeEntry.js.map +0 -1
  284. package/lib/main/helpers/mergeCachedEdges.js +0 -21
  285. package/lib/main/helpers/mergeCachedEdges.js.map +0 -1
  286. package/lib/main/helpers/removeConnectionInputOptions.js +0 -17
  287. package/lib/main/helpers/removeConnectionInputOptions.js.map +0 -1
  288. package/lib/main/helpers/requestAndCachePages.js +0 -66
  289. package/lib/main/helpers/requestAndCachePages.js.map +0 -1
  290. package/lib/main/helpers/requestOutstandingPages.js +0 -67
  291. package/lib/main/helpers/requestOutstandingPages.js.map +0 -1
  292. package/lib/main/helpers/resolveConnection.js +0 -95
  293. package/lib/main/helpers/resolveConnection.js.map +0 -1
  294. package/lib/main/helpers/retrieveCachedConnection.js +0 -90
  295. package/lib/main/helpers/retrieveCachedConnection.js.map +0 -1
  296. package/lib/main/helpers/retrieveCachedEdgesByPage.js +0 -45
  297. package/lib/main/helpers/retrieveCachedEdgesByPage.js.map +0 -1
  298. package/lib/main/helpers/validateCursor.js +0 -88
  299. package/lib/main/helpers/validateCursor.js.map +0 -1
  300. package/lib/main/index.js +0 -52
  301. package/lib/main/index.js.map +0 -1
  302. package/lib/main/main/index.js +0 -100
  303. package/lib/main/main/index.js.map +0 -1
  304. package/lib/module/__testUtils__/generateCursorCache.mjs +0 -71
  305. package/lib/module/__testUtils__/generateCursorCache.mjs.map +0 -1
  306. package/lib/module/__testUtils__/generatePageResponse.mjs +0 -23
  307. package/lib/module/__testUtils__/generatePageResponse.mjs.map +0 -1
  308. package/lib/module/__testUtils__/generatePages.mjs +0 -11
  309. package/lib/module/__testUtils__/generatePages.mjs.map +0 -1
  310. package/lib/module/defs/index.mjs +0 -2
  311. package/lib/module/defs/index.mjs.map +0 -1
  312. package/lib/module/helpers/cacheCursors.mjs +0 -30
  313. package/lib/module/helpers/cacheCursors.mjs.map +0 -1
  314. package/lib/module/helpers/extractEdges.mjs +0 -2
  315. package/lib/module/helpers/extractEdges.mjs.map +0 -1
  316. package/lib/module/helpers/extractNodes.mjs +0 -2
  317. package/lib/module/helpers/extractNodes.mjs.map +0 -1
  318. package/lib/module/helpers/getCount.mjs +0 -5
  319. package/lib/module/helpers/getCount.mjs.map +0 -1
  320. package/lib/module/helpers/getCurrentPageStartAndEndIndexes.mjs +0 -11
  321. package/lib/module/helpers/getCurrentPageStartAndEndIndexes.mjs.map +0 -1
  322. package/lib/module/helpers/getCursor.mjs +0 -5
  323. package/lib/module/helpers/getCursor.mjs.map +0 -1
  324. package/lib/module/helpers/getDirection.mjs +0 -2
  325. package/lib/module/helpers/getDirection.mjs.map +0 -1
  326. package/lib/module/helpers/getInRangeCachedEdges.mjs +0 -26
  327. package/lib/module/helpers/getInRangeCachedEdges.mjs.map +0 -1
  328. package/lib/module/helpers/getIndexesOnCurrentPage.mjs +0 -17
  329. package/lib/module/helpers/getIndexesOnCurrentPage.mjs.map +0 -1
  330. package/lib/module/helpers/getIndexesOnLastPage.mjs +0 -9
  331. package/lib/module/helpers/getIndexesOnLastPage.mjs.map +0 -1
  332. package/lib/module/helpers/getPageNumbersToRequest.mjs +0 -30
  333. package/lib/module/helpers/getPageNumbersToRequest.mjs.map +0 -1
  334. package/lib/module/helpers/getPagesMissingFromCache.mjs +0 -10
  335. package/lib/module/helpers/getPagesMissingFromCache.mjs.map +0 -1
  336. package/lib/module/helpers/getResultsOnLastPage.mjs +0 -8
  337. package/lib/module/helpers/getResultsOnLastPage.mjs.map +0 -1
  338. package/lib/module/helpers/getStartAndEndCursors.mjs +0 -10
  339. package/lib/module/helpers/getStartAndEndCursors.mjs.map +0 -1
  340. package/lib/module/helpers/getStartAndEndIndexes.mjs +0 -86
  341. package/lib/module/helpers/getStartAndEndIndexes.mjs.map +0 -1
  342. package/lib/module/helpers/getStartAndEndPageNumbers.mjs +0 -35
  343. package/lib/module/helpers/getStartAndEndPageNumbers.mjs.map +0 -1
  344. package/lib/module/helpers/hasPreviousNextPage.mjs +0 -18
  345. package/lib/module/helpers/hasPreviousNextPage.mjs.map +0 -1
  346. package/lib/module/helpers/isCursorFirst.mjs +0 -8
  347. package/lib/module/helpers/isCursorFirst.mjs.map +0 -1
  348. package/lib/module/helpers/isCursorLast.mjs +0 -15
  349. package/lib/module/helpers/isCursorLast.mjs.map +0 -1
  350. package/lib/module/helpers/isCursorSupplied.mjs +0 -5
  351. package/lib/module/helpers/isCursorSupplied.mjs.map +0 -1
  352. package/lib/module/helpers/isFirstPage.mjs +0 -2
  353. package/lib/module/helpers/isFirstPage.mjs.map +0 -1
  354. package/lib/module/helpers/isLastPage.mjs +0 -5
  355. package/lib/module/helpers/isLastPage.mjs.map +0 -1
  356. package/lib/module/helpers/makeEdges.mjs +0 -5
  357. package/lib/module/helpers/makeEdges.mjs.map +0 -1
  358. package/lib/module/helpers/makeEntry.mjs +0 -25
  359. package/lib/module/helpers/makeEntry.mjs.map +0 -1
  360. package/lib/module/helpers/mergeCachedEdges.mjs +0 -12
  361. package/lib/module/helpers/mergeCachedEdges.mjs.map +0 -1
  362. package/lib/module/helpers/removeConnectionInputOptions.mjs +0 -4
  363. package/lib/module/helpers/removeConnectionInputOptions.mjs.map +0 -1
  364. package/lib/module/helpers/requestAndCachePages.mjs +0 -54
  365. package/lib/module/helpers/requestAndCachePages.mjs.map +0 -1
  366. package/lib/module/helpers/requestOutstandingPages.mjs +0 -57
  367. package/lib/module/helpers/requestOutstandingPages.mjs.map +0 -1
  368. package/lib/module/helpers/resolveConnection.mjs +0 -78
  369. package/lib/module/helpers/resolveConnection.mjs.map +0 -1
  370. package/lib/module/helpers/retrieveCachedConnection.mjs +0 -70
  371. package/lib/module/helpers/retrieveCachedConnection.mjs.map +0 -1
  372. package/lib/module/helpers/retrieveCachedEdgesByPage.mjs +0 -35
  373. package/lib/module/helpers/retrieveCachedEdgesByPage.mjs.map +0 -1
  374. package/lib/module/helpers/validateCursor.mjs +0 -71
  375. package/lib/module/helpers/validateCursor.mjs.map +0 -1
  376. package/lib/module/index.mjs +0 -4
  377. package/lib/module/index.mjs.map +0 -1
  378. package/lib/module/main/index.mjs +0 -83
  379. package/lib/module/main/index.mjs.map +0 -1
  380. package/lib/types/__testUtils__/generateCursorCache.d.ts +0 -11
  381. package/lib/types/__testUtils__/generateCursorCache.d.ts.map +0 -1
  382. package/lib/types/__testUtils__/generatePageResponse.d.ts +0 -18
  383. package/lib/types/__testUtils__/generatePageResponse.d.ts.map +0 -1
  384. package/lib/types/__testUtils__/generatePages.d.ts +0 -3
  385. package/lib/types/__testUtils__/generatePages.d.ts.map +0 -1
  386. package/lib/types/defs/index.d.ts.map +0 -1
  387. package/lib/types/helpers/cacheCursors.d.ts +0 -13
  388. package/lib/types/helpers/cacheCursors.d.ts.map +0 -1
  389. package/lib/types/helpers/extractEdges.d.ts +0 -4
  390. package/lib/types/helpers/extractEdges.d.ts.map +0 -1
  391. package/lib/types/helpers/extractNodes.d.ts +0 -4
  392. package/lib/types/helpers/extractNodes.d.ts.map +0 -1
  393. package/lib/types/helpers/getCount.d.ts +0 -4
  394. package/lib/types/helpers/getCount.d.ts.map +0 -1
  395. package/lib/types/helpers/getCount.test.d.ts +0 -2
  396. package/lib/types/helpers/getCount.test.d.ts.map +0 -1
  397. package/lib/types/helpers/getCurrentPageStartAndEndIndexes.d.ts.map +0 -1
  398. package/lib/types/helpers/getCursor.d.ts +0 -4
  399. package/lib/types/helpers/getCursor.d.ts.map +0 -1
  400. package/lib/types/helpers/getCursor.test.d.ts +0 -2
  401. package/lib/types/helpers/getCursor.test.d.ts.map +0 -1
  402. package/lib/types/helpers/getDirection.d.ts +0 -3
  403. package/lib/types/helpers/getDirection.d.ts.map +0 -1
  404. package/lib/types/helpers/getDirection.test.d.ts +0 -2
  405. package/lib/types/helpers/getDirection.test.d.ts.map +0 -1
  406. package/lib/types/helpers/getInRangeCachedEdges.d.ts +0 -9
  407. package/lib/types/helpers/getInRangeCachedEdges.d.ts.map +0 -1
  408. package/lib/types/helpers/getIndexesOnCurrentPage.d.ts +0 -7
  409. package/lib/types/helpers/getIndexesOnCurrentPage.d.ts.map +0 -1
  410. package/lib/types/helpers/getIndexesOnCurrentPage.test.d.ts +0 -2
  411. package/lib/types/helpers/getIndexesOnCurrentPage.test.d.ts.map +0 -1
  412. package/lib/types/helpers/getIndexesOnLastPage.d.ts +0 -4
  413. package/lib/types/helpers/getIndexesOnLastPage.d.ts.map +0 -1
  414. package/lib/types/helpers/getIndexesOnLastPage.test.d.ts +0 -2
  415. package/lib/types/helpers/getIndexesOnLastPage.test.d.ts.map +0 -1
  416. package/lib/types/helpers/getPageNumbersToRequest.d.ts +0 -8
  417. package/lib/types/helpers/getPageNumbersToRequest.d.ts.map +0 -1
  418. package/lib/types/helpers/getPageNumbersToRequest.test.d.ts +0 -2
  419. package/lib/types/helpers/getPageNumbersToRequest.test.d.ts.map +0 -1
  420. package/lib/types/helpers/getPagesMissingFromCache.d.ts +0 -4
  421. package/lib/types/helpers/getPagesMissingFromCache.d.ts.map +0 -1
  422. package/lib/types/helpers/getResultsOnLastPage.d.ts +0 -7
  423. package/lib/types/helpers/getResultsOnLastPage.d.ts.map +0 -1
  424. package/lib/types/helpers/getResultsOnLastPage.test.d.ts +0 -2
  425. package/lib/types/helpers/getResultsOnLastPage.test.d.ts.map +0 -1
  426. package/lib/types/helpers/getStartAndEndCursors.d.ts +0 -4
  427. package/lib/types/helpers/getStartAndEndCursors.d.ts.map +0 -1
  428. package/lib/types/helpers/getStartAndEndIndexes.d.ts +0 -10
  429. package/lib/types/helpers/getStartAndEndIndexes.d.ts.map +0 -1
  430. package/lib/types/helpers/getStartAndEndIndexes.test.d.ts +0 -2
  431. package/lib/types/helpers/getStartAndEndIndexes.test.d.ts.map +0 -1
  432. package/lib/types/helpers/getStartAndEndPageNumbers.d.ts +0 -9
  433. package/lib/types/helpers/getStartAndEndPageNumbers.d.ts.map +0 -1
  434. package/lib/types/helpers/getStartAndEndPageNumbers.test.d.ts +0 -2
  435. package/lib/types/helpers/getStartAndEndPageNumbers.test.d.ts.map +0 -1
  436. package/lib/types/helpers/hasPreviousNextPage.d.ts.map +0 -1
  437. package/lib/types/helpers/hasPreviousNextPage.test.d.ts +0 -2
  438. package/lib/types/helpers/hasPreviousNextPage.test.d.ts.map +0 -1
  439. package/lib/types/helpers/isCursorFirst.d.ts +0 -8
  440. package/lib/types/helpers/isCursorFirst.d.ts.map +0 -1
  441. package/lib/types/helpers/isCursorFirst.test.d.ts +0 -2
  442. package/lib/types/helpers/isCursorFirst.test.d.ts.map +0 -1
  443. package/lib/types/helpers/isCursorLast.d.ts +0 -11
  444. package/lib/types/helpers/isCursorLast.d.ts.map +0 -1
  445. package/lib/types/helpers/isCursorLast.test.d.ts +0 -2
  446. package/lib/types/helpers/isCursorLast.test.d.ts.map +0 -1
  447. package/lib/types/helpers/isCursorSupplied.d.ts +0 -4
  448. package/lib/types/helpers/isCursorSupplied.d.ts.map +0 -1
  449. package/lib/types/helpers/isCursorSupplied.test.d.ts +0 -2
  450. package/lib/types/helpers/isCursorSupplied.test.d.ts.map +0 -1
  451. package/lib/types/helpers/isFirstPage.d.ts +0 -3
  452. package/lib/types/helpers/isFirstPage.d.ts.map +0 -1
  453. package/lib/types/helpers/isFirstPage.test.d.ts +0 -2
  454. package/lib/types/helpers/isFirstPage.test.d.ts.map +0 -1
  455. package/lib/types/helpers/isLastPage.d.ts +0 -7
  456. package/lib/types/helpers/isLastPage.d.ts.map +0 -1
  457. package/lib/types/helpers/isLastPage.test.d.ts +0 -2
  458. package/lib/types/helpers/isLastPage.test.d.ts.map +0 -1
  459. package/lib/types/helpers/makeEdges.d.ts +0 -7
  460. package/lib/types/helpers/makeEdges.d.ts.map +0 -1
  461. package/lib/types/helpers/makeEntry.d.ts +0 -11
  462. package/lib/types/helpers/makeEntry.d.ts.map +0 -1
  463. package/lib/types/helpers/mergeCachedEdges.d.ts +0 -4
  464. package/lib/types/helpers/mergeCachedEdges.d.ts.map +0 -1
  465. package/lib/types/helpers/removeConnectionInputOptions.d.ts +0 -3
  466. package/lib/types/helpers/removeConnectionInputOptions.d.ts.map +0 -1
  467. package/lib/types/helpers/removeConnectionInputOptions.test.d.ts +0 -2
  468. package/lib/types/helpers/removeConnectionInputOptions.test.d.ts.map +0 -1
  469. package/lib/types/helpers/requestAndCachePages.d.ts +0 -21
  470. package/lib/types/helpers/requestAndCachePages.d.ts.map +0 -1
  471. package/lib/types/helpers/requestOutstandingPages.d.ts +0 -18
  472. package/lib/types/helpers/requestOutstandingPages.d.ts.map +0 -1
  473. package/lib/types/helpers/resolveConnection.d.ts +0 -24
  474. package/lib/types/helpers/resolveConnection.d.ts.map +0 -1
  475. package/lib/types/helpers/retrieveCachedConnection.d.ts.map +0 -1
  476. package/lib/types/helpers/retrieveCachedConnection.test.d.ts +0 -2
  477. package/lib/types/helpers/retrieveCachedConnection.test.d.ts.map +0 -1
  478. package/lib/types/helpers/retrieveCachedEdgesByPage.d.ts +0 -12
  479. package/lib/types/helpers/retrieveCachedEdgesByPage.d.ts.map +0 -1
  480. package/lib/types/helpers/validateCursor.d.ts +0 -11
  481. package/lib/types/helpers/validateCursor.d.ts.map +0 -1
  482. package/lib/types/helpers/validateCursor.test.d.ts +0 -2
  483. package/lib/types/helpers/validateCursor.test.d.ts.map +0 -1
  484. package/lib/types/index.d.ts +0 -4
  485. package/lib/types/index.d.ts.map +0 -1
  486. package/lib/types/main/index.d.ts +0 -5
  487. package/lib/types/main/index.d.ts.map +0 -1
  488. package/lib/types/main/index.test.d.ts +0 -2
  489. package/lib/types/main/index.test.d.ts.map +0 -1
  490. package/package-lock.json +0 -18
@@ -1,350 +1,468 @@
1
- import Cachemap from "@cachemap/core";
2
- import map from "@cachemap/map";
3
- import { GraphQLError, GraphQLResolveInfo } from "graphql";
4
- import { encode } from "js-base64";
5
- import makeConnectionResolver from ".";
6
- import generateCursorCache from "../__testUtils__/generateCursorCache";
7
- import generatePageResponse from "../__testUtils__/generatePageResponse";
8
- import { PlainObject } from "../defs";
9
- import removeConnectionInputOptions from "../helpers/removeConnectionInputOptions";
10
-
11
- describe("connectionResolver", () => {
12
- const createMakeCursors = (_source: PlainObject, args: PlainObject) => ({
13
- makeGroupCursor: () => encode(JSON.stringify(removeConnectionInputOptions(args))),
14
- makeIDCursor: (id: string | number) => encode(`${id}::${JSON.stringify(removeConnectionInputOptions(args))}`),
15
- });
1
+ import { Core } from '@cachemap/core';
2
+ import { init as map } from '@cachemap/map';
3
+ import type { PlainObject } from '@graphql-box/core';
4
+ import { expect, jest } from '@jest/globals';
5
+ import { GraphQLError, type GraphQLResolveInfo } from 'graphql';
6
+ import { encode } from 'js-base64';
7
+ import { generateCursorCache } from '../__testUtils__/generateCursorCache.ts';
8
+ import { generatePageResponse } from '../__testUtils__/generatePageResponse.ts';
9
+ import { removeConnectionInputOptions } from '../helpers/removeConnectionInputOptions.ts';
10
+ import type { Getters, Node, ResourceResponse } from '../types.ts';
11
+ import { makeConnectionResolver } from './index.ts';
12
+
13
+ const createMakeCursors = (_source: PlainObject, args: PlainObject) => ({
14
+ makeGroupCursor: () => encode(JSON.stringify(removeConnectionInputOptions(args))),
15
+ makeIDCursor: (id: string | number) => encode(`${id}::${JSON.stringify(removeConnectionInputOptions(args))}`),
16
+ });
16
17
 
17
- const getters = {
18
- nodes: ({ results }: PlainObject) => results,
19
- page: ({ page }: PlainObject) => page,
20
- totalPages: ({ totalPages }: PlainObject) => totalPages,
21
- totalResults: ({ totalResults }: PlainObject) => totalResults,
22
- };
23
-
24
- const resultsPerPage = 10;
25
-
26
- describe("when a cursor is supplied", () => {
27
- test("when the cursor is invalid", async () => {
28
- const createResourceResolver = (_obj: PlainObject, args: PlainObject, { restClient }: PlainObject) => {
29
- return async ({ page }: { page: number }) => restClient({ ...removeConnectionInputOptions(args), page });
30
- };
31
-
32
- const connectionResolver = makeConnectionResolver({
33
- createMakeCursors,
34
- createResourceResolver,
35
- cursorCache: new Cachemap({
36
- name: "GRAPHQL_BOX_CONNECTION_RESOLVER",
37
- store: map(),
38
- type: "CONNECTION_RESOLVER",
39
- }),
40
- getters,
41
- resultsPerPage,
18
+ const getters = {
19
+ nodes: ({ results }: PlainObject) => results,
20
+ page: ({ page }: PlainObject) => page,
21
+ totalPages: ({ totalPages }: PlainObject) => totalPages,
22
+ totalResults: ({ totalResults }: PlainObject) => totalResults,
23
+ } as Getters<PlainObject, Node>;
24
+
25
+ const resultsPerPage = 10;
26
+
27
+ describe('connectionResolver', () => {
28
+ describe('when a cursor is supplied', () => {
29
+ describe('when the cursor is invalid', () => {
30
+ let result: Awaited<ReturnType<ReturnType<typeof import('./index.ts')['makeConnectionResolver']>>>;
31
+
32
+ beforeAll(async () => {
33
+ const createResourceResolver =
34
+ (_obj: PlainObject, _args: PlainObject, _ctx: PlainObject) =>
35
+ ({ page }: { page: number }) =>
36
+ Promise.resolve({ data: { page } }) as unknown as Promise<ResourceResponse<PlainObject>>;
37
+
38
+ const connectionResolver = makeConnectionResolver({
39
+ createMakeCursors,
40
+ createResourceResolver,
41
+ cursorCache: new Core({
42
+ name: 'GRAPHQL_BOX_CONNECTION_RESOLVER',
43
+ store: map(),
44
+ type: 'CONNECTION_RESOLVER',
45
+ }),
46
+ getters,
47
+ resultsPerPage,
48
+ });
49
+
50
+ const args = { before: 'abcdefg', first: 5, query: 'Hello world!' };
51
+ const info = {};
52
+ result = await connectionResolver({}, args, {}, info as GraphQLResolveInfo);
42
53
  });
43
54
 
44
- const args = { before: "abcdefg", first: 5, query: "Hello world!" };
45
- const info = {};
46
-
47
- try {
48
- await connectionResolver({}, args, {}, info as GraphQLResolveInfo);
49
- } catch (e) {
50
- expect(e).toBeInstanceOf(GraphQLError);
51
- expect(e.message.startsWith("Invalid connection argument combination")).toBe(true);
52
- }
55
+ it('should return the correct result', () => {
56
+ expect(result).toEqual({
57
+ edges: [],
58
+ errors: [
59
+ new GraphQLError(
60
+ 'Invalid connection argument combination. `before` cannot be used in combination with `first`.'
61
+ ),
62
+ ],
63
+ nodes: [],
64
+ pageInfo: {
65
+ hasNextPage: false,
66
+ hasPreviousPage: false,
67
+ },
68
+ totalCount: 0,
69
+ });
70
+ });
53
71
  });
54
72
 
55
- test("when there are NO missing pages in the cache", async () => {
56
- const createResourceResolver = (_obj: PlainObject, args: PlainObject, { restClient }: PlainObject) => {
57
- return async ({ page }: { page: number }) => restClient({ ...removeConnectionInputOptions(args), page });
58
- };
59
-
60
- const groupCursor = encode(JSON.stringify({ query: "Hello world!" }));
61
-
62
- const cursorCache = await generateCursorCache({
63
- group: groupCursor,
64
- pageRanges: ["1-10"],
65
- resultsPerPage,
66
- totalPages: 10,
67
- totalResults: 100,
73
+ describe('when there are NO missing pages in the cache', () => {
74
+ let result: Awaited<ReturnType<ReturnType<typeof import('./index.ts')['makeConnectionResolver']>>>;
75
+
76
+ beforeAll(async () => {
77
+ const createResourceResolver =
78
+ (_obj: PlainObject, _args: PlainObject, _ctx: PlainObject) =>
79
+ ({ page }: { page: number }) =>
80
+ Promise.resolve({ data: { page } }) as unknown as Promise<ResourceResponse<PlainObject>>;
81
+
82
+ const groupCursor = encode(JSON.stringify({ query: 'Hello world!' }));
83
+
84
+ const cursorCache = await generateCursorCache({
85
+ group: groupCursor,
86
+ pageRanges: ['1-10'],
87
+ resultsPerPage,
88
+ totalPages: 10,
89
+ totalResults: 100,
90
+ });
91
+
92
+ const connectionResolver = makeConnectionResolver({
93
+ createMakeCursors,
94
+ createResourceResolver,
95
+ cursorCache,
96
+ getters,
97
+ resultsPerPage,
98
+ });
99
+
100
+ const args = {
101
+ after: `${encode(`0::1`)}::${groupCursor}`,
102
+ first: 5,
103
+ query: 'Hello world!',
104
+ };
105
+
106
+ const info = {};
107
+ result = await connectionResolver({}, args, {}, info as GraphQLResolveInfo);
68
108
  });
69
109
 
70
- const connectionResolver = makeConnectionResolver({
71
- createMakeCursors,
72
- createResourceResolver,
73
- cursorCache,
74
- getters,
75
- resultsPerPage,
110
+ it('should return the correct result', () => {
111
+ expect(result).toMatchSnapshot();
76
112
  });
77
-
78
- const args = {
79
- after: `${encode(`0::1`)}::${groupCursor}`,
80
- first: 5,
81
- query: "Hello world!",
82
- };
83
-
84
- const info = {};
85
- expect(await connectionResolver({}, args, {}, info as GraphQLResolveInfo)).toMatchSnapshot();
86
113
  });
87
114
 
88
- test("when there are missing pages in the cache", async () => {
115
+ describe('when there are missing pages in the cache', () => {
116
+ let result: Awaited<ReturnType<ReturnType<typeof import('./index.ts')['makeConnectionResolver']>>>;
89
117
  const pageResponse = generatePageResponse({ resultsPerPage, totalPages: 10, totalResults: 100 });
90
- const mock = jest.fn().mockImplementation(page => pageResponse(page));
91
-
92
- const createResourceResolver = (
93
- _obj: PlainObject,
94
- _args: PlainObject,
95
- _context: PlainObject,
96
- _info: GraphQLResolveInfo,
97
- ) => async ({ page }: { page: number }) => mock(page);
98
-
99
- const groupCursor = encode(JSON.stringify({ query: "Hello world!" }));
100
-
101
- const cursorCache = await generateCursorCache({
102
- group: groupCursor,
103
- pageRanges: ["1", "3-10"],
104
- resultsPerPage,
105
- totalPages: 10,
106
- totalResults: 100,
118
+
119
+ const mock = jest
120
+ .fn<(value: number) => Promise<ResourceResponse<PlainObject>>>()
121
+ .mockImplementation(page => pageResponse(page));
122
+
123
+ beforeAll(async () => {
124
+ const createResourceResolver =
125
+ (_obj: PlainObject, _args: PlainObject, _context: PlainObject, _info: GraphQLResolveInfo) =>
126
+ ({ page }: { page: number }) =>
127
+ mock(page);
128
+
129
+ const groupCursor = encode(JSON.stringify({ query: 'Hello world!' }));
130
+
131
+ const cursorCache = await generateCursorCache({
132
+ group: groupCursor,
133
+ pageRanges: ['1', '3-10'],
134
+ resultsPerPage,
135
+ totalPages: 10,
136
+ totalResults: 100,
137
+ });
138
+
139
+ const connectionResolver = makeConnectionResolver({
140
+ createMakeCursors,
141
+ createResourceResolver,
142
+ cursorCache,
143
+ getters,
144
+ resultsPerPage,
145
+ });
146
+
147
+ const args = {
148
+ after: `${encode(`0::1`)}::${groupCursor}`,
149
+ first: 35,
150
+ query: 'Hello world!',
151
+ };
152
+
153
+ const info = {};
154
+ result = await connectionResolver({}, args, {}, info as GraphQLResolveInfo);
107
155
  });
108
156
 
109
- const connectionResolver = makeConnectionResolver({
110
- createMakeCursors,
111
- createResourceResolver,
112
- cursorCache,
113
- getters,
114
- resultsPerPage,
157
+ it('should return the correct result', () => {
158
+ expect(result).toMatchSnapshot();
115
159
  });
116
160
 
117
- const args = {
118
- after: `${encode(`0::1`)}::${groupCursor}`,
119
- first: 35,
120
- query: "Hello world!",
121
- };
161
+ it('should call the resource resolver the correct number of times', () => {
162
+ expect(mock).toHaveBeenCalledTimes(1);
163
+ });
122
164
 
123
- const info = {};
124
- expect(await connectionResolver({}, args, {}, info as GraphQLResolveInfo)).toMatchSnapshot();
125
- expect(mock).toHaveBeenCalledTimes(1);
126
- expect(mock).toHaveBeenCalledWith(2);
165
+ it('should call the resource resolver with the correct argument', () => {
166
+ expect(mock).toHaveBeenCalledWith(2);
167
+ });
127
168
  });
128
169
  });
129
170
 
130
- describe("when the first [X] number are requested", () => {
131
- test("when there is a fresh cache and there are NO missing pages in the cache", async () => {
132
- const createResourceResolver = (_obj: PlainObject, args: PlainObject, { restClient }: PlainObject) => {
133
- return async ({ page }: { page: number }) => restClient({ ...removeConnectionInputOptions(args), page });
134
- };
135
-
136
- const groupCursor = encode(JSON.stringify({ query: "Hello world!" }));
137
-
138
- const cursorCache = await generateCursorCache({
139
- group: groupCursor,
140
- pageRanges: ["1-10"],
141
- resultsPerPage,
142
- totalPages: 10,
143
- totalResults: 100,
171
+ describe('when the first [X] number are requested', () => {
172
+ describe('when there is a fresh cache and there are NO missing pages in the cache', () => {
173
+ let result: Awaited<ReturnType<ReturnType<typeof import('./index.ts')['makeConnectionResolver']>>>;
174
+
175
+ beforeAll(async () => {
176
+ const createResourceResolver =
177
+ (_obj: PlainObject, _args: PlainObject, _ctx: PlainObject) =>
178
+ ({ page }: { page: number }) =>
179
+ Promise.resolve({ data: { page } }) as unknown as Promise<ResourceResponse<PlainObject>>;
180
+
181
+ const groupCursor = encode(JSON.stringify({ query: 'Hello world!' }));
182
+
183
+ const cursorCache = await generateCursorCache({
184
+ group: groupCursor,
185
+ pageRanges: ['1-10'],
186
+ resultsPerPage,
187
+ totalPages: 10,
188
+ totalResults: 100,
189
+ });
190
+
191
+ const connectionResolver = makeConnectionResolver({
192
+ createMakeCursors,
193
+ createResourceResolver,
194
+ cursorCache,
195
+ getters,
196
+ resultsPerPage,
197
+ });
198
+
199
+ const args = {
200
+ first: 5,
201
+ query: 'Hello world!',
202
+ };
203
+
204
+ const info = {};
205
+ result = await connectionResolver({}, args, {}, info as GraphQLResolveInfo);
144
206
  });
145
207
 
146
- const connectionResolver = makeConnectionResolver({
147
- createMakeCursors,
148
- createResourceResolver,
149
- cursorCache,
150
- getters,
151
- resultsPerPage,
208
+ it('should return the correct result', () => {
209
+ expect(result).toMatchSnapshot();
152
210
  });
153
-
154
- const args = {
155
- first: 5,
156
- query: "Hello world!",
157
- };
158
-
159
- const info = {};
160
- expect(await connectionResolver({}, args, {}, info as GraphQLResolveInfo)).toMatchSnapshot();
161
211
  });
162
212
 
163
- test("when there is a fresh cache and there are missing pages in the cache", async () => {
213
+ describe('when there is a fresh cache and there are missing pages in the cache', () => {
214
+ let result: Awaited<ReturnType<ReturnType<typeof import('./index.ts')['makeConnectionResolver']>>>;
164
215
  const pageResponse = generatePageResponse({ resultsPerPage, totalPages: 10, totalResults: 100 });
165
- const mock = jest.fn().mockImplementation(page => pageResponse(page));
166
-
167
- const createResourceResolver = (
168
- _obj: PlainObject,
169
- _args: PlainObject,
170
- _context: PlainObject,
171
- _info: GraphQLResolveInfo,
172
- ) => async ({ page }: { page: number }) => mock(page);
173
-
174
- const groupCursor = encode(JSON.stringify({ query: "Hello world!" }));
175
-
176
- const cursorCache = await generateCursorCache({
177
- group: groupCursor,
178
- pageRanges: ["2-10"],
179
- resultsPerPage,
180
- totalPages: 10,
181
- totalResults: 100,
216
+
217
+ const mock = jest
218
+ .fn<(value: number) => Promise<ResourceResponse<PlainObject>>>()
219
+ .mockImplementation(page => pageResponse(page));
220
+
221
+ beforeAll(async () => {
222
+ const createResourceResolver =
223
+ (_obj: PlainObject, _args: PlainObject, _context: PlainObject, _info: GraphQLResolveInfo) =>
224
+ ({ page }: { page: number }) =>
225
+ mock(page);
226
+
227
+ const groupCursor = encode(JSON.stringify({ query: 'Hello world!' }));
228
+
229
+ const cursorCache = await generateCursorCache({
230
+ group: groupCursor,
231
+ pageRanges: ['2-10'],
232
+ resultsPerPage,
233
+ totalPages: 10,
234
+ totalResults: 100,
235
+ });
236
+
237
+ const connectionResolver = makeConnectionResolver({
238
+ createMakeCursors,
239
+ createResourceResolver,
240
+ cursorCache,
241
+ getters,
242
+ resultsPerPage,
243
+ });
244
+
245
+ const args = {
246
+ first: 5,
247
+ query: 'Hello world!',
248
+ };
249
+
250
+ const info = {};
251
+ result = await connectionResolver({}, args, {}, info as GraphQLResolveInfo);
182
252
  });
183
253
 
184
- const connectionResolver = makeConnectionResolver({
185
- createMakeCursors,
186
- createResourceResolver,
187
- cursorCache,
188
- getters,
189
- resultsPerPage,
254
+ it('should return the correct result', () => {
255
+ expect(result).toMatchSnapshot();
190
256
  });
191
257
 
192
- const args = {
193
- first: 5,
194
- query: "Hello world!",
195
- };
258
+ it('should call the resource resolver the correct number of times', () => {
259
+ expect(mock).toHaveBeenCalledTimes(1);
260
+ });
196
261
 
197
- const info = {};
198
- expect(await connectionResolver({}, args, {}, info as GraphQLResolveInfo)).toMatchSnapshot();
199
- expect(mock).toHaveBeenCalledTimes(1);
200
- expect(mock).toHaveBeenCalledWith(1);
262
+ it('should call the resource resolver with the correct argument', () => {
263
+ expect(mock).toHaveBeenCalledWith(1);
264
+ });
201
265
  });
202
266
 
203
- test("when there is NOT a fresh cache", async () => {
267
+ describe('when there is NOT a fresh cache', () => {
268
+ let result: Awaited<ReturnType<ReturnType<typeof import('./index.ts')['makeConnectionResolver']>>>;
204
269
  const pageResponse = generatePageResponse({ resultsPerPage, totalPages: 10, totalResults: 100 });
205
- const mock = jest.fn().mockImplementation(page => pageResponse(page));
206
-
207
- const createResourceResolver = (
208
- _obj: PlainObject,
209
- _args: PlainObject,
210
- _context: PlainObject,
211
- _info: GraphQLResolveInfo,
212
- ) => async ({ page }: { page: number }) => mock(page);
213
-
214
- const cursorCache = new Cachemap({
215
- name: "cursorCache",
216
- store: map(),
217
- type: "someType",
270
+
271
+ const mock = jest
272
+ .fn<(value: number) => Promise<ResourceResponse<PlainObject>>>()
273
+ .mockImplementation(page => pageResponse(page));
274
+
275
+ beforeAll(async () => {
276
+ const createResourceResolver =
277
+ (_obj: PlainObject, _args: PlainObject, _context: PlainObject, _info: GraphQLResolveInfo) =>
278
+ ({ page }: { page: number }) =>
279
+ mock(page);
280
+
281
+ const cursorCache = new Core({
282
+ name: 'cursorCache',
283
+ store: map(),
284
+ type: 'someType',
285
+ });
286
+
287
+ const connectionResolver = makeConnectionResolver({
288
+ createMakeCursors,
289
+ createResourceResolver,
290
+ cursorCache,
291
+ getters,
292
+ resultsPerPage,
293
+ });
294
+
295
+ const args = {
296
+ first: 5,
297
+ query: 'Hello world!',
298
+ };
299
+
300
+ const info = {};
301
+ result = await connectionResolver({}, args, {}, info as GraphQLResolveInfo);
218
302
  });
219
303
 
220
- const connectionResolver = makeConnectionResolver({
221
- createMakeCursors,
222
- createResourceResolver,
223
- cursorCache,
224
- getters,
225
- resultsPerPage,
304
+ it('should return the correct result', () => {
305
+ expect(result).toMatchSnapshot();
226
306
  });
227
307
 
228
- const args = {
229
- first: 5,
230
- query: "Hello world!",
231
- };
308
+ it('should call the resource resolver the correct number of times', () => {
309
+ expect(mock).toHaveBeenCalledTimes(1);
310
+ });
232
311
 
233
- const info = {};
234
- expect(await connectionResolver({}, args, {}, info as GraphQLResolveInfo)).toMatchSnapshot();
235
- expect(mock).toHaveBeenCalledTimes(1);
236
- expect(mock).toHaveBeenCalledWith(1);
312
+ it('should call the resource resolver with the correct argument', () => {
313
+ expect(mock).toHaveBeenCalledWith(1);
314
+ });
237
315
  });
238
316
  });
239
317
 
240
- describe("when the last [X] number are requested", () => {
241
- test("when there is a fresh cache and there are NO missing pages in the cache", async () => {
242
- const createResourceResolver = (_obj: PlainObject, args: PlainObject, { restClient }: PlainObject) => {
243
- return async ({ page }: { page: number }) => restClient({ ...removeConnectionInputOptions(args), page });
244
- };
245
-
246
- const groupCursor = encode(JSON.stringify({ query: "Hello world!" }));
247
-
248
- const cursorCache = await generateCursorCache({
249
- group: groupCursor,
250
- pageRanges: ["1-10"],
251
- resultsPerPage,
252
- totalPages: 10,
253
- totalResults: 100,
318
+ describe('when the last [X] number are requested', () => {
319
+ describe('when there is a fresh cache and there are NO missing pages in the cache', () => {
320
+ let result: Awaited<ReturnType<ReturnType<typeof import('./index.ts')['makeConnectionResolver']>>>;
321
+
322
+ beforeAll(async () => {
323
+ const createResourceResolver =
324
+ (_obj: PlainObject, _args: PlainObject, _ctx: PlainObject) =>
325
+ async ({ page }: { page: number }) =>
326
+ Promise.resolve({ data: { page } }) as unknown as Promise<ResourceResponse<PlainObject>>;
327
+
328
+ const groupCursor = encode(JSON.stringify({ query: 'Hello world!' }));
329
+
330
+ const cursorCache = await generateCursorCache({
331
+ group: groupCursor,
332
+ pageRanges: ['1-10'],
333
+ resultsPerPage,
334
+ totalPages: 10,
335
+ totalResults: 100,
336
+ });
337
+
338
+ const connectionResolver = makeConnectionResolver({
339
+ createMakeCursors,
340
+ createResourceResolver,
341
+ cursorCache,
342
+ getters,
343
+ resultsPerPage,
344
+ });
345
+
346
+ const args = {
347
+ last: 5,
348
+ query: 'Hello world!',
349
+ };
350
+
351
+ const info = {};
352
+ result = await connectionResolver({}, args, {}, info as GraphQLResolveInfo);
254
353
  });
255
354
 
256
- const connectionResolver = makeConnectionResolver({
257
- createMakeCursors,
258
- createResourceResolver,
259
- cursorCache,
260
- getters,
261
- resultsPerPage,
355
+ it('should return the correct result', () => {
356
+ expect(result).toMatchSnapshot();
262
357
  });
263
-
264
- const args = {
265
- last: 5,
266
- query: "Hello world!",
267
- };
268
-
269
- const info = {};
270
- expect(await connectionResolver({}, args, {}, info as GraphQLResolveInfo)).toMatchSnapshot();
271
358
  });
272
359
 
273
- test("when there is a fresh cache and there are missing pages in the cache", async () => {
360
+ describe('when there is a fresh cache and there are missing pages in the cache', () => {
361
+ let result: Awaited<ReturnType<ReturnType<typeof import('./index.ts')['makeConnectionResolver']>>>;
274
362
  const pageResponse = generatePageResponse({ resultsPerPage, totalPages: 10, totalResults: 100 });
275
- const mock = jest.fn().mockImplementation(page => pageResponse(page));
276
-
277
- const createResourceResolver = (
278
- _obj: PlainObject,
279
- _args: PlainObject,
280
- _context: PlainObject,
281
- _info: GraphQLResolveInfo,
282
- ) => async ({ page }: { page: number }) => mock(page);
283
-
284
- const groupCursor = encode(JSON.stringify({ query: "Hello world!" }));
285
-
286
- const cursorCache = await generateCursorCache({
287
- group: groupCursor,
288
- pageRanges: ["1-9"],
289
- resultsPerPage,
290
- totalPages: 10,
291
- totalResults: 100,
363
+
364
+ const mock = jest
365
+ .fn<(value: number) => Promise<ResourceResponse<PlainObject>>>()
366
+ .mockImplementation(page => pageResponse(page));
367
+
368
+ beforeAll(async () => {
369
+ const createResourceResolver =
370
+ (_obj: PlainObject, _args: PlainObject, _context: PlainObject, _info: GraphQLResolveInfo) =>
371
+ ({ page }: { page: number }) =>
372
+ mock(page);
373
+
374
+ const groupCursor = encode(JSON.stringify({ query: 'Hello world!' }));
375
+
376
+ const cursorCache = await generateCursorCache({
377
+ group: groupCursor,
378
+ pageRanges: ['1-9'],
379
+ resultsPerPage,
380
+ totalPages: 10,
381
+ totalResults: 100,
382
+ });
383
+
384
+ const connectionResolver = makeConnectionResolver({
385
+ createMakeCursors,
386
+ createResourceResolver,
387
+ cursorCache,
388
+ getters,
389
+ resultsPerPage,
390
+ });
391
+
392
+ const args = {
393
+ last: 5,
394
+ query: 'Hello world!',
395
+ };
396
+
397
+ const info = {};
398
+ result = await connectionResolver({}, args, {}, info as GraphQLResolveInfo);
292
399
  });
293
400
 
294
- const connectionResolver = makeConnectionResolver({
295
- createMakeCursors,
296
- createResourceResolver,
297
- cursorCache,
298
- getters,
299
- resultsPerPage,
401
+ it('should return the correct result', () => {
402
+ expect(result).toMatchSnapshot();
300
403
  });
301
404
 
302
- const args = {
303
- last: 5,
304
- query: "Hello world!",
305
- };
405
+ it('should call the resource resolver the correct number of times', () => {
406
+ expect(mock).toHaveBeenCalledTimes(1);
407
+ });
306
408
 
307
- const info = {};
308
- expect(await connectionResolver({}, args, {}, info as GraphQLResolveInfo)).toMatchSnapshot();
309
- expect(mock).toHaveBeenCalledTimes(1);
310
- expect(mock).toHaveBeenCalledWith(10);
409
+ it('should call the resource resolver with the correct argument', () => {
410
+ expect(mock).toHaveBeenCalledWith(10);
411
+ });
311
412
  });
312
413
 
313
- test("when there is NOT a fresh cache", async () => {
414
+ describe('when there is NOT a fresh cache', () => {
415
+ let result: Awaited<ReturnType<ReturnType<typeof import('./index.ts')['makeConnectionResolver']>>>;
314
416
  const pageResponse = generatePageResponse({ resultsPerPage, totalPages: 10, totalResults: 100 });
315
- const mock = jest.fn().mockImplementation(page => pageResponse(page));
316
-
317
- const createResourceResolver = (
318
- _obj: PlainObject,
319
- _args: PlainObject,
320
- _context: PlainObject,
321
- _info: GraphQLResolveInfo,
322
- ) => async ({ page }: { page: number }) => mock(page);
323
-
324
- const cursorCache = new Cachemap({
325
- name: "cursorCache",
326
- store: map(),
327
- type: "someType",
417
+
418
+ const mock = jest
419
+ .fn<(value: number) => Promise<ResourceResponse<PlainObject>>>()
420
+ .mockImplementation(page => pageResponse(page));
421
+
422
+ beforeAll(async () => {
423
+ const createResourceResolver =
424
+ (_obj: PlainObject, _args: PlainObject, _context: PlainObject, _info: GraphQLResolveInfo) =>
425
+ ({ page }: { page: number }) =>
426
+ mock(page);
427
+
428
+ const cursorCache = new Core({
429
+ name: 'cursorCache',
430
+ store: map(),
431
+ type: 'someType',
432
+ });
433
+
434
+ const connectionResolver = makeConnectionResolver({
435
+ createMakeCursors,
436
+ createResourceResolver,
437
+ cursorCache,
438
+ getters,
439
+ resultsPerPage,
440
+ });
441
+
442
+ const args = {
443
+ last: 5,
444
+ query: 'Hello world!',
445
+ };
446
+
447
+ const info = {};
448
+ result = await connectionResolver({}, args, {}, info as GraphQLResolveInfo);
328
449
  });
329
450
 
330
- const connectionResolver = makeConnectionResolver({
331
- createMakeCursors,
332
- createResourceResolver,
333
- cursorCache,
334
- getters,
335
- resultsPerPage,
451
+ it('should return the correct result', () => {
452
+ expect(result).toMatchSnapshot();
336
453
  });
337
454
 
338
- const args = {
339
- last: 5,
340
- query: "Hello world!",
341
- };
455
+ it('should call the resource resolver the correct number of times', () => {
456
+ expect(mock).toHaveBeenCalledTimes(2);
457
+ });
342
458
 
343
- const info = {};
344
- expect(await connectionResolver({}, args, {}, info as GraphQLResolveInfo)).toMatchSnapshot();
345
- expect(mock).toHaveBeenCalledTimes(2);
346
- expect(mock).toHaveBeenCalledWith(1);
347
- expect(mock).toHaveBeenCalledWith(10);
459
+ it('should call the resource resolver with the correct argument first', () => {
460
+ expect(mock).toHaveBeenNthCalledWith(1, 1);
461
+ });
462
+
463
+ it('should call the resource resolver with the correct argument second', () => {
464
+ expect(mock).toHaveBeenNthCalledWith(2, 10);
465
+ });
348
466
  });
349
467
  });
350
468
  });