@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.
- package/README.md +1 -5
- package/dist/cjs/index.cjs +703 -0
- package/dist/cjs/index.cjs.map +1 -0
- package/dist/esm/index.mjs +700 -0
- package/dist/esm/index.mjs.map +1 -0
- package/dist/types/cjs/__testUtils__/generateCursorCache.d.cts +10 -0
- package/dist/types/cjs/__testUtils__/generateCursorCache.d.cts.map +1 -0
- package/dist/types/cjs/__testUtils__/generatePageResponse.d.cts +9 -0
- package/dist/types/cjs/__testUtils__/generatePageResponse.d.cts.map +1 -0
- package/dist/types/cjs/__testUtils__/generatePages.d.cts +2 -0
- package/dist/types/cjs/__testUtils__/generatePages.d.cts.map +1 -0
- package/dist/types/cjs/helpers/cacheCursors.d.cts +12 -0
- package/dist/types/cjs/helpers/cacheCursors.d.cts.map +1 -0
- package/dist/types/cjs/helpers/extractEdges.d.cts +3 -0
- package/dist/types/cjs/helpers/extractEdges.d.cts.map +1 -0
- package/dist/types/cjs/helpers/extractNodes.d.cts +3 -0
- package/dist/types/cjs/helpers/extractNodes.d.cts.map +1 -0
- package/dist/types/cjs/helpers/getCount.d.cts +3 -0
- package/dist/types/cjs/helpers/getCount.d.cts.map +1 -0
- package/dist/types/cjs/helpers/getCurrentPageStartAndEndIndexes.d.cts +14 -0
- package/dist/types/cjs/helpers/getCurrentPageStartAndEndIndexes.d.cts.map +1 -0
- package/dist/types/cjs/helpers/getCursor.d.cts +3 -0
- package/dist/types/cjs/helpers/getCursor.d.cts.map +1 -0
- package/dist/types/cjs/helpers/getDirection.d.cts +3 -0
- package/dist/types/cjs/helpers/getDirection.d.cts.map +1 -0
- package/dist/types/cjs/helpers/getInRangeCachedEdges.d.cts +8 -0
- package/dist/types/cjs/helpers/getInRangeCachedEdges.d.cts.map +1 -0
- package/dist/types/cjs/helpers/getIndexesOnCurrentPage.d.cts +10 -0
- package/dist/types/cjs/helpers/getIndexesOnCurrentPage.d.cts.map +1 -0
- package/dist/types/cjs/helpers/getIndexesOnLastPage.d.cts +3 -0
- package/dist/types/cjs/helpers/getIndexesOnLastPage.d.cts.map +1 -0
- package/dist/types/cjs/helpers/getPageNumbersToRequest.d.cts +12 -0
- package/dist/types/cjs/helpers/getPageNumbersToRequest.d.cts.map +1 -0
- package/dist/types/cjs/helpers/getPagesMissingFromCache.d.cts +3 -0
- package/dist/types/cjs/helpers/getPagesMissingFromCache.d.cts.map +1 -0
- package/dist/types/cjs/helpers/getResultsOnLastPage.d.cts +6 -0
- package/dist/types/cjs/helpers/getResultsOnLastPage.d.cts.map +1 -0
- package/dist/types/cjs/helpers/getStartAndEndCursors.d.cts +4 -0
- package/dist/types/cjs/helpers/getStartAndEndCursors.d.cts.map +1 -0
- package/dist/types/cjs/helpers/getStartAndEndIndexes.d.cts +15 -0
- package/dist/types/cjs/helpers/getStartAndEndIndexes.d.cts.map +1 -0
- package/dist/types/cjs/helpers/getStartAndEndPageNumbers.d.cts +13 -0
- package/dist/types/cjs/helpers/getStartAndEndPageNumbers.d.cts.map +1 -0
- package/dist/types/cjs/helpers/hasPreviousNextPage.d.cts +14 -0
- package/dist/types/cjs/helpers/hasPreviousNextPage.d.cts.map +1 -0
- package/dist/types/cjs/helpers/isCursorFirst.d.cts +7 -0
- package/dist/types/cjs/helpers/isCursorFirst.d.cts.map +1 -0
- package/dist/types/cjs/helpers/isCursorLast.d.cts +10 -0
- package/dist/types/cjs/helpers/isCursorLast.d.cts.map +1 -0
- package/dist/types/cjs/helpers/isCursorSupplied.d.cts +4 -0
- package/dist/types/cjs/helpers/isCursorSupplied.d.cts.map +1 -0
- package/dist/types/cjs/helpers/isFirstPage.d.cts +2 -0
- package/dist/types/cjs/helpers/isFirstPage.d.cts.map +1 -0
- package/dist/types/cjs/helpers/isLastPage.d.cts +6 -0
- package/dist/types/cjs/helpers/isLastPage.d.cts.map +1 -0
- package/dist/types/cjs/helpers/makeEdges.d.cts +6 -0
- package/dist/types/cjs/helpers/makeEdges.d.cts.map +1 -0
- package/dist/types/cjs/helpers/makeEntry.d.cts +10 -0
- package/dist/types/cjs/helpers/makeEntry.d.cts.map +1 -0
- package/dist/types/cjs/helpers/mergeCachedEdges.d.cts +3 -0
- package/dist/types/cjs/helpers/mergeCachedEdges.d.cts.map +1 -0
- package/dist/types/cjs/helpers/removeConnectionInputOptions.d.cts +2 -0
- package/dist/types/cjs/helpers/removeConnectionInputOptions.d.cts.map +1 -0
- package/dist/types/cjs/helpers/requestAndCachePages.d.cts +21 -0
- package/dist/types/cjs/helpers/requestAndCachePages.d.cts.map +1 -0
- package/dist/types/cjs/helpers/requestOutstandingPages.d.cts +18 -0
- package/dist/types/cjs/helpers/requestOutstandingPages.d.cts.map +1 -0
- package/dist/types/cjs/helpers/resolveConnection.d.cts +24 -0
- package/dist/types/cjs/helpers/resolveConnection.d.cts.map +1 -0
- package/dist/types/cjs/helpers/retrieveCachedConnection.d.cts +25 -0
- package/dist/types/cjs/helpers/retrieveCachedConnection.d.cts.map +1 -0
- package/dist/types/cjs/helpers/retrieveCachedEdgesByPage.d.cts +11 -0
- package/dist/types/cjs/helpers/retrieveCachedEdgesByPage.d.cts.map +1 -0
- package/dist/types/cjs/helpers/retrieveEntry.d.cts +8 -0
- package/dist/types/cjs/helpers/retrieveEntry.d.cts.map +1 -0
- package/dist/types/cjs/helpers/validateCursor.d.cts +10 -0
- package/dist/types/cjs/helpers/validateCursor.d.cts.map +1 -0
- package/dist/types/cjs/index.d.cts +4 -0
- package/dist/types/cjs/index.d.cts.map +1 -0
- package/dist/types/cjs/main/index.d.cts +5 -0
- package/dist/types/cjs/main/index.d.cts.map +1 -0
- package/{lib/types/defs/index.d.ts → dist/types/cjs/types.d.cts} +22 -27
- package/dist/types/cjs/types.d.cts.map +1 -0
- package/dist/types/esm/__testUtils__/generateCursorCache.d.ts +10 -0
- package/dist/types/esm/__testUtils__/generateCursorCache.d.ts.map +1 -0
- package/dist/types/esm/__testUtils__/generatePageResponse.d.ts +9 -0
- package/dist/types/esm/__testUtils__/generatePageResponse.d.ts.map +1 -0
- package/dist/types/esm/__testUtils__/generatePages.d.ts +2 -0
- package/dist/types/esm/__testUtils__/generatePages.d.ts.map +1 -0
- package/dist/types/esm/helpers/cacheCursors.d.ts +12 -0
- package/dist/types/esm/helpers/cacheCursors.d.ts.map +1 -0
- package/dist/types/esm/helpers/extractEdges.d.ts +3 -0
- package/dist/types/esm/helpers/extractEdges.d.ts.map +1 -0
- package/dist/types/esm/helpers/extractNodes.d.ts +3 -0
- package/dist/types/esm/helpers/extractNodes.d.ts.map +1 -0
- package/dist/types/esm/helpers/getCount.d.ts +3 -0
- package/dist/types/esm/helpers/getCount.d.ts.map +1 -0
- package/{lib/types → dist/types/esm}/helpers/getCurrentPageStartAndEndIndexes.d.ts +3 -3
- package/dist/types/esm/helpers/getCurrentPageStartAndEndIndexes.d.ts.map +1 -0
- package/dist/types/esm/helpers/getCursor.d.ts +3 -0
- package/dist/types/esm/helpers/getCursor.d.ts.map +1 -0
- package/dist/types/esm/helpers/getDirection.d.ts +3 -0
- package/dist/types/esm/helpers/getDirection.d.ts.map +1 -0
- package/dist/types/esm/helpers/getInRangeCachedEdges.d.ts +8 -0
- package/dist/types/esm/helpers/getInRangeCachedEdges.d.ts.map +1 -0
- package/dist/types/esm/helpers/getIndexesOnCurrentPage.d.ts +10 -0
- package/dist/types/esm/helpers/getIndexesOnCurrentPage.d.ts.map +1 -0
- package/dist/types/esm/helpers/getIndexesOnLastPage.d.ts +3 -0
- package/dist/types/esm/helpers/getIndexesOnLastPage.d.ts.map +1 -0
- package/dist/types/esm/helpers/getPageNumbersToRequest.d.ts +12 -0
- package/dist/types/esm/helpers/getPageNumbersToRequest.d.ts.map +1 -0
- package/dist/types/esm/helpers/getPagesMissingFromCache.d.ts +3 -0
- package/dist/types/esm/helpers/getPagesMissingFromCache.d.ts.map +1 -0
- package/dist/types/esm/helpers/getResultsOnLastPage.d.ts +6 -0
- package/dist/types/esm/helpers/getResultsOnLastPage.d.ts.map +1 -0
- package/dist/types/esm/helpers/getStartAndEndCursors.d.ts +4 -0
- package/dist/types/esm/helpers/getStartAndEndCursors.d.ts.map +1 -0
- package/dist/types/esm/helpers/getStartAndEndIndexes.d.ts +15 -0
- package/dist/types/esm/helpers/getStartAndEndIndexes.d.ts.map +1 -0
- package/dist/types/esm/helpers/getStartAndEndPageNumbers.d.ts +13 -0
- package/dist/types/esm/helpers/getStartAndEndPageNumbers.d.ts.map +1 -0
- package/{lib/types → dist/types/esm}/helpers/hasPreviousNextPage.d.ts +3 -3
- package/dist/types/esm/helpers/hasPreviousNextPage.d.ts.map +1 -0
- package/dist/types/esm/helpers/isCursorFirst.d.ts +7 -0
- package/dist/types/esm/helpers/isCursorFirst.d.ts.map +1 -0
- package/dist/types/esm/helpers/isCursorLast.d.ts +10 -0
- package/dist/types/esm/helpers/isCursorLast.d.ts.map +1 -0
- package/dist/types/esm/helpers/isCursorSupplied.d.ts +4 -0
- package/dist/types/esm/helpers/isCursorSupplied.d.ts.map +1 -0
- package/dist/types/esm/helpers/isFirstPage.d.ts +2 -0
- package/dist/types/esm/helpers/isFirstPage.d.ts.map +1 -0
- package/dist/types/esm/helpers/isLastPage.d.ts +6 -0
- package/dist/types/esm/helpers/isLastPage.d.ts.map +1 -0
- package/dist/types/esm/helpers/makeEdges.d.ts +6 -0
- package/dist/types/esm/helpers/makeEdges.d.ts.map +1 -0
- package/dist/types/esm/helpers/makeEntry.d.ts +10 -0
- package/dist/types/esm/helpers/makeEntry.d.ts.map +1 -0
- package/dist/types/esm/helpers/mergeCachedEdges.d.ts +3 -0
- package/dist/types/esm/helpers/mergeCachedEdges.d.ts.map +1 -0
- package/dist/types/esm/helpers/removeConnectionInputOptions.d.ts +2 -0
- package/dist/types/esm/helpers/removeConnectionInputOptions.d.ts.map +1 -0
- package/dist/types/esm/helpers/requestAndCachePages.d.ts +21 -0
- package/dist/types/esm/helpers/requestAndCachePages.d.ts.map +1 -0
- package/dist/types/esm/helpers/requestOutstandingPages.d.ts +18 -0
- package/dist/types/esm/helpers/requestOutstandingPages.d.ts.map +1 -0
- package/dist/types/esm/helpers/resolveConnection.d.ts +24 -0
- package/dist/types/esm/helpers/resolveConnection.d.ts.map +1 -0
- package/{lib/types → dist/types/esm}/helpers/retrieveCachedConnection.d.ts +5 -6
- package/dist/types/esm/helpers/retrieveCachedConnection.d.ts.map +1 -0
- package/dist/types/esm/helpers/retrieveCachedEdgesByPage.d.ts +11 -0
- package/dist/types/esm/helpers/retrieveCachedEdgesByPage.d.ts.map +1 -0
- package/dist/types/esm/helpers/retrieveEntry.d.ts +8 -0
- package/dist/types/esm/helpers/retrieveEntry.d.ts.map +1 -0
- package/dist/types/esm/helpers/validateCursor.d.ts +10 -0
- package/dist/types/esm/helpers/validateCursor.d.ts.map +1 -0
- package/dist/types/esm/index.d.ts +4 -0
- package/dist/types/esm/index.d.ts.map +1 -0
- package/dist/types/esm/main/index.d.ts +5 -0
- package/dist/types/esm/main/index.d.ts.map +1 -0
- package/dist/types/esm/types.d.ts +77 -0
- package/dist/types/esm/types.d.ts.map +1 -0
- package/dist/types/tsconfig.build.tsbuildinfo +1 -0
- package/package.json +56 -38
- package/src/__testUtils__/generateCursorCache.ts +20 -14
- package/src/__testUtils__/generatePageResponse.ts +17 -12
- package/src/__testUtils__/generatePages.ts +5 -5
- package/src/helpers/cacheCursors.ts +10 -7
- package/src/helpers/extractEdges.ts +3 -3
- package/src/helpers/extractNodes.ts +2 -2
- package/src/helpers/getCount.test.ts +10 -6
- package/src/helpers/getCount.ts +2 -2
- package/src/helpers/getCurrentPageStartAndEndIndexes.ts +1 -1
- package/src/helpers/getCursor.test.ts +10 -6
- package/src/helpers/getCursor.ts +2 -2
- package/src/helpers/getDirection.test.ts +10 -6
- package/src/helpers/getDirection.ts +3 -1
- package/src/helpers/getInRangeCachedEdges.ts +10 -7
- package/src/helpers/getIndexesOnCurrentPage.test.ts +14 -10
- package/src/helpers/getIndexesOnCurrentPage.ts +11 -6
- package/src/helpers/getIndexesOnLastPage.test.ts +10 -6
- package/src/helpers/getIndexesOnLastPage.ts +3 -2
- package/src/helpers/getPageNumbersToRequest.test.ts +15 -11
- package/src/helpers/getPageNumbersToRequest.ts +17 -6
- package/src/helpers/getPagesMissingFromCache.ts +5 -5
- package/src/helpers/getResultsOnLastPage.test.ts +10 -6
- package/src/helpers/getResultsOnLastPage.ts +1 -1
- package/src/helpers/getStartAndEndCursors.ts +1 -1
- package/src/helpers/getStartAndEndIndexes.test.ts +77 -57
- package/src/helpers/getStartAndEndIndexes.ts +28 -22
- package/src/helpers/getStartAndEndPageNumbers.test.ts +46 -28
- package/src/helpers/getStartAndEndPageNumbers.ts +12 -12
- package/src/helpers/hasPreviousNextPage.test.ts +17 -8
- package/src/helpers/hasPreviousNextPage.ts +6 -4
- package/src/helpers/isCursorFirst.test.ts +13 -7
- package/src/helpers/isCursorFirst.ts +3 -2
- package/src/helpers/isCursorLast.test.ts +27 -23
- package/src/helpers/isCursorLast.ts +4 -4
- package/src/helpers/isCursorSupplied.test.ts +18 -10
- package/src/helpers/isCursorSupplied.ts +3 -2
- package/src/helpers/isFirstPage.test.ts +10 -6
- package/src/helpers/isFirstPage.ts +1 -1
- package/src/helpers/isLastPage.test.ts +10 -6
- package/src/helpers/isLastPage.ts +1 -1
- package/src/helpers/makeEdges.ts +3 -3
- package/src/helpers/makeEntry.ts +8 -5
- package/src/helpers/mergeCachedEdges.ts +5 -5
- package/src/helpers/removeConnectionInputOptions.test.ts +10 -8
- package/src/helpers/removeConnectionInputOptions.ts +4 -3
- package/src/helpers/requestAndCachePages.ts +14 -11
- package/src/helpers/requestOutstandingPages.ts +18 -19
- package/src/helpers/resolveConnection.ts +20 -34
- package/src/helpers/retrieveCachedConnection.test.ts +703 -338
- package/src/helpers/retrieveCachedConnection.ts +28 -20
- package/src/helpers/retrieveCachedEdgesByPage.ts +10 -10
- package/src/helpers/retrieveEntry.ts +32 -0
- package/src/helpers/validateCursor.test.ts +88 -61
- package/src/helpers/validateCursor.ts +30 -26
- package/src/index.ts +3 -3
- package/src/main/__snapshots__/index.test.ts.snap +258 -258
- package/src/main/index.test.ts +405 -287
- package/src/main/index.ts +37 -35
- package/src/{defs/index.ts → types.ts} +12 -18
- package/tsconfig.build.json +10 -0
- package/tsconfig.json +11 -0
- package/lib/browser/index.js +0 -2
- package/lib/browser/index.js.map +0 -1
- package/lib/browser/production.analysis.txt +0 -314
- package/lib/main/__testUtils__/generateCursorCache.js +0 -88
- package/lib/main/__testUtils__/generateCursorCache.js.map +0 -1
- package/lib/main/__testUtils__/generatePageResponse.js +0 -33
- package/lib/main/__testUtils__/generatePageResponse.js.map +0 -1
- package/lib/main/__testUtils__/generatePages.js +0 -23
- package/lib/main/__testUtils__/generatePages.js.map +0 -1
- package/lib/main/defs/index.js +0 -2
- package/lib/main/defs/index.js.map +0 -1
- package/lib/main/helpers/cacheCursors.js +0 -40
- package/lib/main/helpers/cacheCursors.js.map +0 -1
- package/lib/main/helpers/extractEdges.js +0 -11
- package/lib/main/helpers/extractEdges.js.map +0 -1
- package/lib/main/helpers/extractNodes.js +0 -11
- package/lib/main/helpers/extractNodes.js.map +0 -1
- package/lib/main/helpers/getCount.js +0 -14
- package/lib/main/helpers/getCount.js.map +0 -1
- package/lib/main/helpers/getCurrentPageStartAndEndIndexes.js +0 -23
- package/lib/main/helpers/getCurrentPageStartAndEndIndexes.js.map +0 -1
- package/lib/main/helpers/getCursor.js +0 -14
- package/lib/main/helpers/getCursor.js.map +0 -1
- package/lib/main/helpers/getDirection.js +0 -11
- package/lib/main/helpers/getDirection.js.map +0 -1
- package/lib/main/helpers/getInRangeCachedEdges.js +0 -36
- package/lib/main/helpers/getInRangeCachedEdges.js.map +0 -1
- package/lib/main/helpers/getIndexesOnCurrentPage.js +0 -30
- package/lib/main/helpers/getIndexesOnCurrentPage.js.map +0 -1
- package/lib/main/helpers/getIndexesOnLastPage.js +0 -21
- package/lib/main/helpers/getIndexesOnLastPage.js.map +0 -1
- package/lib/main/helpers/getPageNumbersToRequest.js +0 -43
- package/lib/main/helpers/getPageNumbersToRequest.js.map +0 -1
- package/lib/main/helpers/getPagesMissingFromCache.js +0 -19
- package/lib/main/helpers/getPagesMissingFromCache.js.map +0 -1
- package/lib/main/helpers/getResultsOnLastPage.js +0 -17
- package/lib/main/helpers/getResultsOnLastPage.js.map +0 -1
- package/lib/main/helpers/getStartAndEndCursors.js +0 -22
- package/lib/main/helpers/getStartAndEndCursors.js.map +0 -1
- package/lib/main/helpers/getStartAndEndIndexes.js +0 -105
- package/lib/main/helpers/getStartAndEndIndexes.js.map +0 -1
- package/lib/main/helpers/getStartAndEndPageNumbers.js +0 -51
- package/lib/main/helpers/getStartAndEndPageNumbers.js.map +0 -1
- package/lib/main/helpers/hasPreviousNextPage.js +0 -33
- package/lib/main/helpers/hasPreviousNextPage.js.map +0 -1
- package/lib/main/helpers/isCursorFirst.js +0 -17
- package/lib/main/helpers/isCursorFirst.js.map +0 -1
- package/lib/main/helpers/isCursorLast.js +0 -27
- package/lib/main/helpers/isCursorLast.js.map +0 -1
- package/lib/main/helpers/isCursorSupplied.js +0 -14
- package/lib/main/helpers/isCursorSupplied.js.map +0 -1
- package/lib/main/helpers/isFirstPage.js +0 -11
- package/lib/main/helpers/isFirstPage.js.map +0 -1
- package/lib/main/helpers/isLastPage.js +0 -14
- package/lib/main/helpers/isLastPage.js.map +0 -1
- package/lib/main/helpers/makeEdges.js +0 -14
- package/lib/main/helpers/makeEdges.js.map +0 -1
- package/lib/main/helpers/makeEntry.js +0 -38
- package/lib/main/helpers/makeEntry.js.map +0 -1
- package/lib/main/helpers/mergeCachedEdges.js +0 -21
- package/lib/main/helpers/mergeCachedEdges.js.map +0 -1
- package/lib/main/helpers/removeConnectionInputOptions.js +0 -17
- package/lib/main/helpers/removeConnectionInputOptions.js.map +0 -1
- package/lib/main/helpers/requestAndCachePages.js +0 -66
- package/lib/main/helpers/requestAndCachePages.js.map +0 -1
- package/lib/main/helpers/requestOutstandingPages.js +0 -67
- package/lib/main/helpers/requestOutstandingPages.js.map +0 -1
- package/lib/main/helpers/resolveConnection.js +0 -95
- package/lib/main/helpers/resolveConnection.js.map +0 -1
- package/lib/main/helpers/retrieveCachedConnection.js +0 -90
- package/lib/main/helpers/retrieveCachedConnection.js.map +0 -1
- package/lib/main/helpers/retrieveCachedEdgesByPage.js +0 -45
- package/lib/main/helpers/retrieveCachedEdgesByPage.js.map +0 -1
- package/lib/main/helpers/validateCursor.js +0 -88
- package/lib/main/helpers/validateCursor.js.map +0 -1
- package/lib/main/index.js +0 -52
- package/lib/main/index.js.map +0 -1
- package/lib/main/main/index.js +0 -100
- package/lib/main/main/index.js.map +0 -1
- package/lib/module/__testUtils__/generateCursorCache.mjs +0 -71
- package/lib/module/__testUtils__/generateCursorCache.mjs.map +0 -1
- package/lib/module/__testUtils__/generatePageResponse.mjs +0 -23
- package/lib/module/__testUtils__/generatePageResponse.mjs.map +0 -1
- package/lib/module/__testUtils__/generatePages.mjs +0 -11
- package/lib/module/__testUtils__/generatePages.mjs.map +0 -1
- package/lib/module/defs/index.mjs +0 -2
- package/lib/module/defs/index.mjs.map +0 -1
- package/lib/module/helpers/cacheCursors.mjs +0 -30
- package/lib/module/helpers/cacheCursors.mjs.map +0 -1
- package/lib/module/helpers/extractEdges.mjs +0 -2
- package/lib/module/helpers/extractEdges.mjs.map +0 -1
- package/lib/module/helpers/extractNodes.mjs +0 -2
- package/lib/module/helpers/extractNodes.mjs.map +0 -1
- package/lib/module/helpers/getCount.mjs +0 -5
- package/lib/module/helpers/getCount.mjs.map +0 -1
- package/lib/module/helpers/getCurrentPageStartAndEndIndexes.mjs +0 -11
- package/lib/module/helpers/getCurrentPageStartAndEndIndexes.mjs.map +0 -1
- package/lib/module/helpers/getCursor.mjs +0 -5
- package/lib/module/helpers/getCursor.mjs.map +0 -1
- package/lib/module/helpers/getDirection.mjs +0 -2
- package/lib/module/helpers/getDirection.mjs.map +0 -1
- package/lib/module/helpers/getInRangeCachedEdges.mjs +0 -26
- package/lib/module/helpers/getInRangeCachedEdges.mjs.map +0 -1
- package/lib/module/helpers/getIndexesOnCurrentPage.mjs +0 -17
- package/lib/module/helpers/getIndexesOnCurrentPage.mjs.map +0 -1
- package/lib/module/helpers/getIndexesOnLastPage.mjs +0 -9
- package/lib/module/helpers/getIndexesOnLastPage.mjs.map +0 -1
- package/lib/module/helpers/getPageNumbersToRequest.mjs +0 -30
- package/lib/module/helpers/getPageNumbersToRequest.mjs.map +0 -1
- package/lib/module/helpers/getPagesMissingFromCache.mjs +0 -10
- package/lib/module/helpers/getPagesMissingFromCache.mjs.map +0 -1
- package/lib/module/helpers/getResultsOnLastPage.mjs +0 -8
- package/lib/module/helpers/getResultsOnLastPage.mjs.map +0 -1
- package/lib/module/helpers/getStartAndEndCursors.mjs +0 -10
- package/lib/module/helpers/getStartAndEndCursors.mjs.map +0 -1
- package/lib/module/helpers/getStartAndEndIndexes.mjs +0 -86
- package/lib/module/helpers/getStartAndEndIndexes.mjs.map +0 -1
- package/lib/module/helpers/getStartAndEndPageNumbers.mjs +0 -35
- package/lib/module/helpers/getStartAndEndPageNumbers.mjs.map +0 -1
- package/lib/module/helpers/hasPreviousNextPage.mjs +0 -18
- package/lib/module/helpers/hasPreviousNextPage.mjs.map +0 -1
- package/lib/module/helpers/isCursorFirst.mjs +0 -8
- package/lib/module/helpers/isCursorFirst.mjs.map +0 -1
- package/lib/module/helpers/isCursorLast.mjs +0 -15
- package/lib/module/helpers/isCursorLast.mjs.map +0 -1
- package/lib/module/helpers/isCursorSupplied.mjs +0 -5
- package/lib/module/helpers/isCursorSupplied.mjs.map +0 -1
- package/lib/module/helpers/isFirstPage.mjs +0 -2
- package/lib/module/helpers/isFirstPage.mjs.map +0 -1
- package/lib/module/helpers/isLastPage.mjs +0 -5
- package/lib/module/helpers/isLastPage.mjs.map +0 -1
- package/lib/module/helpers/makeEdges.mjs +0 -5
- package/lib/module/helpers/makeEdges.mjs.map +0 -1
- package/lib/module/helpers/makeEntry.mjs +0 -25
- package/lib/module/helpers/makeEntry.mjs.map +0 -1
- package/lib/module/helpers/mergeCachedEdges.mjs +0 -12
- package/lib/module/helpers/mergeCachedEdges.mjs.map +0 -1
- package/lib/module/helpers/removeConnectionInputOptions.mjs +0 -4
- package/lib/module/helpers/removeConnectionInputOptions.mjs.map +0 -1
- package/lib/module/helpers/requestAndCachePages.mjs +0 -54
- package/lib/module/helpers/requestAndCachePages.mjs.map +0 -1
- package/lib/module/helpers/requestOutstandingPages.mjs +0 -57
- package/lib/module/helpers/requestOutstandingPages.mjs.map +0 -1
- package/lib/module/helpers/resolveConnection.mjs +0 -78
- package/lib/module/helpers/resolveConnection.mjs.map +0 -1
- package/lib/module/helpers/retrieveCachedConnection.mjs +0 -70
- package/lib/module/helpers/retrieveCachedConnection.mjs.map +0 -1
- package/lib/module/helpers/retrieveCachedEdgesByPage.mjs +0 -35
- package/lib/module/helpers/retrieveCachedEdgesByPage.mjs.map +0 -1
- package/lib/module/helpers/validateCursor.mjs +0 -71
- package/lib/module/helpers/validateCursor.mjs.map +0 -1
- package/lib/module/index.mjs +0 -4
- package/lib/module/index.mjs.map +0 -1
- package/lib/module/main/index.mjs +0 -83
- package/lib/module/main/index.mjs.map +0 -1
- package/lib/types/__testUtils__/generateCursorCache.d.ts +0 -11
- package/lib/types/__testUtils__/generateCursorCache.d.ts.map +0 -1
- package/lib/types/__testUtils__/generatePageResponse.d.ts +0 -18
- package/lib/types/__testUtils__/generatePageResponse.d.ts.map +0 -1
- package/lib/types/__testUtils__/generatePages.d.ts +0 -3
- package/lib/types/__testUtils__/generatePages.d.ts.map +0 -1
- package/lib/types/defs/index.d.ts.map +0 -1
- package/lib/types/helpers/cacheCursors.d.ts +0 -13
- package/lib/types/helpers/cacheCursors.d.ts.map +0 -1
- package/lib/types/helpers/extractEdges.d.ts +0 -4
- package/lib/types/helpers/extractEdges.d.ts.map +0 -1
- package/lib/types/helpers/extractNodes.d.ts +0 -4
- package/lib/types/helpers/extractNodes.d.ts.map +0 -1
- package/lib/types/helpers/getCount.d.ts +0 -4
- package/lib/types/helpers/getCount.d.ts.map +0 -1
- package/lib/types/helpers/getCount.test.d.ts +0 -2
- package/lib/types/helpers/getCount.test.d.ts.map +0 -1
- package/lib/types/helpers/getCurrentPageStartAndEndIndexes.d.ts.map +0 -1
- package/lib/types/helpers/getCursor.d.ts +0 -4
- package/lib/types/helpers/getCursor.d.ts.map +0 -1
- package/lib/types/helpers/getCursor.test.d.ts +0 -2
- package/lib/types/helpers/getCursor.test.d.ts.map +0 -1
- package/lib/types/helpers/getDirection.d.ts +0 -3
- package/lib/types/helpers/getDirection.d.ts.map +0 -1
- package/lib/types/helpers/getDirection.test.d.ts +0 -2
- package/lib/types/helpers/getDirection.test.d.ts.map +0 -1
- package/lib/types/helpers/getInRangeCachedEdges.d.ts +0 -9
- package/lib/types/helpers/getInRangeCachedEdges.d.ts.map +0 -1
- package/lib/types/helpers/getIndexesOnCurrentPage.d.ts +0 -7
- package/lib/types/helpers/getIndexesOnCurrentPage.d.ts.map +0 -1
- package/lib/types/helpers/getIndexesOnCurrentPage.test.d.ts +0 -2
- package/lib/types/helpers/getIndexesOnCurrentPage.test.d.ts.map +0 -1
- package/lib/types/helpers/getIndexesOnLastPage.d.ts +0 -4
- package/lib/types/helpers/getIndexesOnLastPage.d.ts.map +0 -1
- package/lib/types/helpers/getIndexesOnLastPage.test.d.ts +0 -2
- package/lib/types/helpers/getIndexesOnLastPage.test.d.ts.map +0 -1
- package/lib/types/helpers/getPageNumbersToRequest.d.ts +0 -8
- package/lib/types/helpers/getPageNumbersToRequest.d.ts.map +0 -1
- package/lib/types/helpers/getPageNumbersToRequest.test.d.ts +0 -2
- package/lib/types/helpers/getPageNumbersToRequest.test.d.ts.map +0 -1
- package/lib/types/helpers/getPagesMissingFromCache.d.ts +0 -4
- package/lib/types/helpers/getPagesMissingFromCache.d.ts.map +0 -1
- package/lib/types/helpers/getResultsOnLastPage.d.ts +0 -7
- package/lib/types/helpers/getResultsOnLastPage.d.ts.map +0 -1
- package/lib/types/helpers/getResultsOnLastPage.test.d.ts +0 -2
- package/lib/types/helpers/getResultsOnLastPage.test.d.ts.map +0 -1
- package/lib/types/helpers/getStartAndEndCursors.d.ts +0 -4
- package/lib/types/helpers/getStartAndEndCursors.d.ts.map +0 -1
- package/lib/types/helpers/getStartAndEndIndexes.d.ts +0 -10
- package/lib/types/helpers/getStartAndEndIndexes.d.ts.map +0 -1
- package/lib/types/helpers/getStartAndEndIndexes.test.d.ts +0 -2
- package/lib/types/helpers/getStartAndEndIndexes.test.d.ts.map +0 -1
- package/lib/types/helpers/getStartAndEndPageNumbers.d.ts +0 -9
- package/lib/types/helpers/getStartAndEndPageNumbers.d.ts.map +0 -1
- package/lib/types/helpers/getStartAndEndPageNumbers.test.d.ts +0 -2
- package/lib/types/helpers/getStartAndEndPageNumbers.test.d.ts.map +0 -1
- package/lib/types/helpers/hasPreviousNextPage.d.ts.map +0 -1
- package/lib/types/helpers/hasPreviousNextPage.test.d.ts +0 -2
- package/lib/types/helpers/hasPreviousNextPage.test.d.ts.map +0 -1
- package/lib/types/helpers/isCursorFirst.d.ts +0 -8
- package/lib/types/helpers/isCursorFirst.d.ts.map +0 -1
- package/lib/types/helpers/isCursorFirst.test.d.ts +0 -2
- package/lib/types/helpers/isCursorFirst.test.d.ts.map +0 -1
- package/lib/types/helpers/isCursorLast.d.ts +0 -11
- package/lib/types/helpers/isCursorLast.d.ts.map +0 -1
- package/lib/types/helpers/isCursorLast.test.d.ts +0 -2
- package/lib/types/helpers/isCursorLast.test.d.ts.map +0 -1
- package/lib/types/helpers/isCursorSupplied.d.ts +0 -4
- package/lib/types/helpers/isCursorSupplied.d.ts.map +0 -1
- package/lib/types/helpers/isCursorSupplied.test.d.ts +0 -2
- package/lib/types/helpers/isCursorSupplied.test.d.ts.map +0 -1
- package/lib/types/helpers/isFirstPage.d.ts +0 -3
- package/lib/types/helpers/isFirstPage.d.ts.map +0 -1
- package/lib/types/helpers/isFirstPage.test.d.ts +0 -2
- package/lib/types/helpers/isFirstPage.test.d.ts.map +0 -1
- package/lib/types/helpers/isLastPage.d.ts +0 -7
- package/lib/types/helpers/isLastPage.d.ts.map +0 -1
- package/lib/types/helpers/isLastPage.test.d.ts +0 -2
- package/lib/types/helpers/isLastPage.test.d.ts.map +0 -1
- package/lib/types/helpers/makeEdges.d.ts +0 -7
- package/lib/types/helpers/makeEdges.d.ts.map +0 -1
- package/lib/types/helpers/makeEntry.d.ts +0 -11
- package/lib/types/helpers/makeEntry.d.ts.map +0 -1
- package/lib/types/helpers/mergeCachedEdges.d.ts +0 -4
- package/lib/types/helpers/mergeCachedEdges.d.ts.map +0 -1
- package/lib/types/helpers/removeConnectionInputOptions.d.ts +0 -3
- package/lib/types/helpers/removeConnectionInputOptions.d.ts.map +0 -1
- package/lib/types/helpers/removeConnectionInputOptions.test.d.ts +0 -2
- package/lib/types/helpers/removeConnectionInputOptions.test.d.ts.map +0 -1
- package/lib/types/helpers/requestAndCachePages.d.ts +0 -21
- package/lib/types/helpers/requestAndCachePages.d.ts.map +0 -1
- package/lib/types/helpers/requestOutstandingPages.d.ts +0 -18
- package/lib/types/helpers/requestOutstandingPages.d.ts.map +0 -1
- package/lib/types/helpers/resolveConnection.d.ts +0 -24
- package/lib/types/helpers/resolveConnection.d.ts.map +0 -1
- package/lib/types/helpers/retrieveCachedConnection.d.ts.map +0 -1
- package/lib/types/helpers/retrieveCachedConnection.test.d.ts +0 -2
- package/lib/types/helpers/retrieveCachedConnection.test.d.ts.map +0 -1
- package/lib/types/helpers/retrieveCachedEdgesByPage.d.ts +0 -12
- package/lib/types/helpers/retrieveCachedEdgesByPage.d.ts.map +0 -1
- package/lib/types/helpers/validateCursor.d.ts +0 -11
- package/lib/types/helpers/validateCursor.d.ts.map +0 -1
- package/lib/types/helpers/validateCursor.test.d.ts +0 -2
- package/lib/types/helpers/validateCursor.test.d.ts.map +0 -1
- package/lib/types/index.d.ts +0 -4
- package/lib/types/index.d.ts.map +0 -1
- package/lib/types/main/index.d.ts +0 -5
- package/lib/types/main/index.d.ts.map +0 -1
- package/lib/types/main/index.test.d.ts +0 -2
- package/lib/types/main/index.test.d.ts.map +0 -1
- package/package-lock.json +0 -18
package/src/main/index.test.ts
CHANGED
@@ -1,350 +1,468 @@
|
|
1
|
-
import
|
2
|
-
import map from
|
3
|
-
import {
|
4
|
-
import {
|
5
|
-
import
|
6
|
-
import
|
7
|
-
import
|
8
|
-
import {
|
9
|
-
import removeConnectionInputOptions from
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
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
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
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
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
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
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
-
|
71
|
-
|
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
|
-
|
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
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
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
|
-
|
110
|
-
|
111
|
-
createResourceResolver,
|
112
|
-
cursorCache,
|
113
|
-
getters,
|
114
|
-
resultsPerPage,
|
157
|
+
it('should return the correct result', () => {
|
158
|
+
expect(result).toMatchSnapshot();
|
115
159
|
});
|
116
160
|
|
117
|
-
|
118
|
-
|
119
|
-
|
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
|
-
|
124
|
-
|
125
|
-
|
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(
|
131
|
-
|
132
|
-
|
133
|
-
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
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
|
-
|
147
|
-
|
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
|
-
|
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
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
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
|
-
|
185
|
-
|
186
|
-
createResourceResolver,
|
187
|
-
cursorCache,
|
188
|
-
getters,
|
189
|
-
resultsPerPage,
|
254
|
+
it('should return the correct result', () => {
|
255
|
+
expect(result).toMatchSnapshot();
|
190
256
|
});
|
191
257
|
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
};
|
258
|
+
it('should call the resource resolver the correct number of times', () => {
|
259
|
+
expect(mock).toHaveBeenCalledTimes(1);
|
260
|
+
});
|
196
261
|
|
197
|
-
|
198
|
-
|
199
|
-
|
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
|
-
|
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
|
-
|
206
|
-
|
207
|
-
|
208
|
-
|
209
|
-
|
210
|
-
|
211
|
-
|
212
|
-
|
213
|
-
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
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
|
-
|
221
|
-
|
222
|
-
createResourceResolver,
|
223
|
-
cursorCache,
|
224
|
-
getters,
|
225
|
-
resultsPerPage,
|
304
|
+
it('should return the correct result', () => {
|
305
|
+
expect(result).toMatchSnapshot();
|
226
306
|
});
|
227
307
|
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
};
|
308
|
+
it('should call the resource resolver the correct number of times', () => {
|
309
|
+
expect(mock).toHaveBeenCalledTimes(1);
|
310
|
+
});
|
232
311
|
|
233
|
-
|
234
|
-
|
235
|
-
|
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(
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
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
|
-
|
257
|
-
|
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
|
-
|
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
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
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
|
-
|
295
|
-
|
296
|
-
createResourceResolver,
|
297
|
-
cursorCache,
|
298
|
-
getters,
|
299
|
-
resultsPerPage,
|
401
|
+
it('should return the correct result', () => {
|
402
|
+
expect(result).toMatchSnapshot();
|
300
403
|
});
|
301
404
|
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
};
|
405
|
+
it('should call the resource resolver the correct number of times', () => {
|
406
|
+
expect(mock).toHaveBeenCalledTimes(1);
|
407
|
+
});
|
306
408
|
|
307
|
-
|
308
|
-
|
309
|
-
|
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
|
-
|
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
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
325
|
-
|
326
|
-
|
327
|
-
|
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
|
-
|
331
|
-
|
332
|
-
createResourceResolver,
|
333
|
-
cursorCache,
|
334
|
-
getters,
|
335
|
-
resultsPerPage,
|
451
|
+
it('should return the correct result', () => {
|
452
|
+
expect(result).toMatchSnapshot();
|
336
453
|
});
|
337
454
|
|
338
|
-
|
339
|
-
|
340
|
-
|
341
|
-
};
|
455
|
+
it('should call the resource resolver the correct number of times', () => {
|
456
|
+
expect(mock).toHaveBeenCalledTimes(2);
|
457
|
+
});
|
342
458
|
|
343
|
-
|
344
|
-
|
345
|
-
|
346
|
-
|
347
|
-
|
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
|
});
|