@graphql-box/connection-resolver 5.3.1 → 5.4.0

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 (67) hide show
  1. package/dist/cjs/index.cjs +1 -1
  2. package/dist/cjs/index.cjs.map +1 -1
  3. package/dist/esm/index.mjs +1 -1
  4. package/dist/esm/index.mjs.map +1 -1
  5. package/dist/production.analysis.txt +145 -145
  6. package/dist/types/cjs/__testUtils__/generatePageResponse.d.cts.map +1 -1
  7. package/dist/types/cjs/helpers/getCount.d.cts.map +1 -1
  8. package/dist/types/cjs/helpers/getStartAndEndIndexes.d.cts +1 -1
  9. package/dist/types/cjs/helpers/getStartAndEndIndexes.d.cts.map +1 -1
  10. package/dist/types/cjs/helpers/getStartAndEndPageNumbers.d.cts +2 -2
  11. package/dist/types/cjs/helpers/getStartAndEndPageNumbers.d.cts.map +1 -1
  12. package/dist/types/cjs/helpers/hasPreviousNextPage.d.cts.map +1 -1
  13. package/dist/types/cjs/helpers/isFirstPage.d.cts +1 -1
  14. package/dist/types/cjs/helpers/isFirstPage.d.cts.map +1 -1
  15. package/dist/types/cjs/helpers/makeEdges.d.cts.map +1 -1
  16. package/dist/types/cjs/helpers/removeConnectionInputOptions.d.cts.map +1 -1
  17. package/dist/types/cjs/helpers/requestAndCachePages.d.cts.map +1 -1
  18. package/dist/types/cjs/helpers/resolveConnection.d.cts +1 -1
  19. package/dist/types/cjs/helpers/resolveConnection.d.cts.map +1 -1
  20. package/dist/types/cjs/helpers/retrieveCachedConnection.d.cts.map +1 -1
  21. package/dist/types/cjs/helpers/retrieveEntry.d.cts.map +1 -1
  22. package/dist/types/cjs/helpers/validateCursor.d.cts.map +1 -1
  23. package/dist/types/cjs/main/index.d.cts.map +1 -1
  24. package/dist/types/esm/__testUtils__/generatePageResponse.d.ts.map +1 -1
  25. package/dist/types/esm/helpers/getCount.d.ts.map +1 -1
  26. package/dist/types/esm/helpers/getStartAndEndIndexes.d.ts +1 -1
  27. package/dist/types/esm/helpers/getStartAndEndIndexes.d.ts.map +1 -1
  28. package/dist/types/esm/helpers/getStartAndEndPageNumbers.d.ts +2 -2
  29. package/dist/types/esm/helpers/getStartAndEndPageNumbers.d.ts.map +1 -1
  30. package/dist/types/esm/helpers/hasPreviousNextPage.d.ts.map +1 -1
  31. package/dist/types/esm/helpers/isFirstPage.d.ts +1 -1
  32. package/dist/types/esm/helpers/isFirstPage.d.ts.map +1 -1
  33. package/dist/types/esm/helpers/makeEdges.d.ts.map +1 -1
  34. package/dist/types/esm/helpers/removeConnectionInputOptions.d.ts.map +1 -1
  35. package/dist/types/esm/helpers/requestAndCachePages.d.ts.map +1 -1
  36. package/dist/types/esm/helpers/resolveConnection.d.ts +1 -1
  37. package/dist/types/esm/helpers/resolveConnection.d.ts.map +1 -1
  38. package/dist/types/esm/helpers/retrieveCachedConnection.d.ts.map +1 -1
  39. package/dist/types/esm/helpers/retrieveEntry.d.ts.map +1 -1
  40. package/dist/types/esm/helpers/validateCursor.d.ts.map +1 -1
  41. package/dist/types/esm/main/index.d.ts.map +1 -1
  42. package/dist/types/tsconfig.build.tsbuildinfo +1 -1
  43. package/package.json +16 -17
  44. package/src/__testUtils__/generateCursorCache.ts +4 -4
  45. package/src/__testUtils__/generatePageResponse.ts +1 -1
  46. package/src/helpers/cacheCursors.ts +2 -2
  47. package/src/helpers/getCount.ts +3 -0
  48. package/src/helpers/getInRangeCachedEdges.ts +1 -1
  49. package/src/helpers/getIndexesOnCurrentPage.test.ts +2 -2
  50. package/src/helpers/getPageNumbersToRequest.ts +1 -1
  51. package/src/helpers/getStartAndEndCursors.ts +1 -1
  52. package/src/helpers/getStartAndEndIndexes.ts +28 -28
  53. package/src/helpers/getStartAndEndPageNumbers.ts +4 -4
  54. package/src/helpers/hasPreviousNextPage.ts +1 -2
  55. package/src/helpers/isCursorLast.test.ts +2 -2
  56. package/src/helpers/makeEntry.ts +1 -1
  57. package/src/helpers/requestAndCachePages.ts +2 -2
  58. package/src/helpers/requestOutstandingPages.ts +1 -1
  59. package/src/helpers/resolveConnection.ts +8 -1
  60. package/src/helpers/retrieveCachedConnection.test.ts +32 -32
  61. package/src/helpers/retrieveCachedConnection.ts +6 -7
  62. package/src/helpers/retrieveEntry.ts +1 -1
  63. package/src/helpers/validateCursor.test.ts +4 -4
  64. package/src/helpers/validateCursor.ts +11 -6
  65. package/src/main/index.test.ts +11 -11
  66. package/src/main/index.ts +5 -5
  67. package/src/types.ts +4 -4
@@ -10,7 +10,7 @@ describe('retrieveCachedConnection', () => {
10
10
 
11
11
  describe('retrieving edges after a cursor', () => {
12
12
  describe('when 5 cursors on the same page are requested', () => {
13
- let result: Awaited<ReturnType<typeof import('./retrieveCachedConnection.ts')['retrieveCachedConnection']>>;
13
+ let result: Awaited<ReturnType<(typeof import('./retrieveCachedConnection.ts'))['retrieveCachedConnection']>>;
14
14
 
15
15
  beforeAll(async () => {
16
16
  const cursorCache = await generateCursorCache({
@@ -45,7 +45,7 @@ describe('retrieveCachedConnection', () => {
45
45
 
46
46
  it('should return the correct last edge', () => {
47
47
  const edges = extractEdges(result.cachedEdges);
48
- expect(decode((edges[edges.length - 1]!.node.id as string).split('::')[0]!)).toBe('5::1');
48
+ expect(decode((edges.at(-1)!.node.id as string).split('::')[0]!)).toBe('5::1');
49
49
  });
50
50
 
51
51
  it('should return hasPreviousPage as true', () => {
@@ -62,7 +62,7 @@ describe('retrieveCachedConnection', () => {
62
62
  });
63
63
 
64
64
  describe('when 15 cursors covering multiple pages are requested', () => {
65
- let result: Awaited<ReturnType<typeof import('./retrieveCachedConnection.ts')['retrieveCachedConnection']>>;
65
+ let result: Awaited<ReturnType<(typeof import('./retrieveCachedConnection.ts'))['retrieveCachedConnection']>>;
66
66
 
67
67
  beforeAll(async () => {
68
68
  const cursorCache = await generateCursorCache({
@@ -97,7 +97,7 @@ describe('retrieveCachedConnection', () => {
97
97
 
98
98
  it('should return the correct last edge', () => {
99
99
  const edges = extractEdges(result.cachedEdges);
100
- expect(decode((edges[edges.length - 1]!.node.id as string).split('::')[0]!)).toBe('0::3');
100
+ expect(decode((edges.at(-1)!.node.id as string).split('::')[0]!)).toBe('0::3');
101
101
  });
102
102
 
103
103
  it('should return hasPreviousPage as true', () => {
@@ -114,7 +114,7 @@ describe('retrieveCachedConnection', () => {
114
114
  });
115
115
 
116
116
  describe('when 15 cursors going over the last page are requested', () => {
117
- let result: Awaited<ReturnType<typeof import('./retrieveCachedConnection.ts')['retrieveCachedConnection']>>;
117
+ let result: Awaited<ReturnType<(typeof import('./retrieveCachedConnection.ts'))['retrieveCachedConnection']>>;
118
118
 
119
119
  beforeAll(async () => {
120
120
  const cursorCache = await generateCursorCache({
@@ -149,7 +149,7 @@ describe('retrieveCachedConnection', () => {
149
149
 
150
150
  it('should return the correct last edge', () => {
151
151
  const edges = extractEdges(result.cachedEdges);
152
- expect(decode((edges[edges.length - 1]!.node.id as string).split('::')[0]!)).toBe('9::10');
152
+ expect(decode((edges.at(-1)!.node.id as string).split('::')[0]!)).toBe('9::10');
153
153
  });
154
154
 
155
155
  it('should return hasPreviousPage as true', () => {
@@ -167,7 +167,7 @@ describe('retrieveCachedConnection', () => {
167
167
 
168
168
  describe('when 35 cursors covering multiple pages and going OVER the last page are requested', () => {
169
169
  describe('when last page has full page of results', () => {
170
- let result: Awaited<ReturnType<typeof import('./retrieveCachedConnection.ts')['retrieveCachedConnection']>>;
170
+ let result: Awaited<ReturnType<(typeof import('./retrieveCachedConnection.ts'))['retrieveCachedConnection']>>;
171
171
 
172
172
  beforeAll(async () => {
173
173
  const cursorCache = await generateCursorCache({
@@ -202,7 +202,7 @@ describe('retrieveCachedConnection', () => {
202
202
 
203
203
  it('should return the correct last edge', () => {
204
204
  const edges = extractEdges(result.cachedEdges);
205
- expect(decode((edges[edges.length - 1]!.node.id as string).split('::')[0]!)).toBe('9::10');
205
+ expect(decode((edges.at(-1)!.node.id as string).split('::')[0]!)).toBe('9::10');
206
206
  });
207
207
 
208
208
  it('should return hasPreviousPage as true', () => {
@@ -219,7 +219,7 @@ describe('retrieveCachedConnection', () => {
219
219
  });
220
220
 
221
221
  describe('when last page has partial page of results', () => {
222
- let result: Awaited<ReturnType<typeof import('./retrieveCachedConnection.ts')['retrieveCachedConnection']>>;
222
+ let result: Awaited<ReturnType<(typeof import('./retrieveCachedConnection.ts'))['retrieveCachedConnection']>>;
223
223
 
224
224
  beforeAll(async () => {
225
225
  const cursorCache = await generateCursorCache({
@@ -254,7 +254,7 @@ describe('retrieveCachedConnection', () => {
254
254
 
255
255
  it('should return the correct last edge', () => {
256
256
  const edges = extractEdges(result.cachedEdges);
257
- expect(decode((edges[edges.length - 1]!.node.id as string).split('::')[0]!)).toBe('5::10');
257
+ expect(decode((edges.at(-1)!.node.id as string).split('::')[0]!)).toBe('5::10');
258
258
  });
259
259
 
260
260
  it('should return hasPreviousPage as true', () => {
@@ -273,7 +273,7 @@ describe('retrieveCachedConnection', () => {
273
273
 
274
274
  describe('when 25 cursors covering multiple pages and going UP TO the last page are requested', () => {
275
275
  describe('when last page has full page of results', () => {
276
- let result: Awaited<ReturnType<typeof import('./retrieveCachedConnection.ts')['retrieveCachedConnection']>>;
276
+ let result: Awaited<ReturnType<(typeof import('./retrieveCachedConnection.ts'))['retrieveCachedConnection']>>;
277
277
 
278
278
  beforeAll(async () => {
279
279
  const cursorCache = await generateCursorCache({
@@ -308,7 +308,7 @@ describe('retrieveCachedConnection', () => {
308
308
 
309
309
  it('should return the correct last edge', () => {
310
310
  const edges = extractEdges(result.cachedEdges);
311
- expect(decode((edges[edges.length - 1]!.node.id as string).split('::')[0]!)).toBe('5::10');
311
+ expect(decode((edges.at(-1)!.node.id as string).split('::')[0]!)).toBe('5::10');
312
312
  });
313
313
 
314
314
  it('should return hasPreviousPage as true', () => {
@@ -325,7 +325,7 @@ describe('retrieveCachedConnection', () => {
325
325
  });
326
326
 
327
327
  describe('when last page has partial page of results', () => {
328
- let result: Awaited<ReturnType<typeof import('./retrieveCachedConnection.ts')['retrieveCachedConnection']>>;
328
+ let result: Awaited<ReturnType<(typeof import('./retrieveCachedConnection.ts'))['retrieveCachedConnection']>>;
329
329
 
330
330
  beforeAll(async () => {
331
331
  const cursorCache = await generateCursorCache({
@@ -360,7 +360,7 @@ describe('retrieveCachedConnection', () => {
360
360
 
361
361
  it('should return the correct last edge', () => {
362
362
  const edges = extractEdges(result.cachedEdges);
363
- expect(decode((edges[edges.length - 1]!.node.id as string).split('::')[0]!)).toBe('5::10');
363
+ expect(decode((edges.at(-1)!.node.id as string).split('::')[0]!)).toBe('5::10');
364
364
  });
365
365
 
366
366
  it('should return hasPreviousPage as true', () => {
@@ -379,7 +379,7 @@ describe('retrieveCachedConnection', () => {
379
379
 
380
380
  describe('when there are missing pages', () => {
381
381
  describe('when 35 cursors covering multiple pages and going OVER the last page are requested', () => {
382
- let result: Awaited<ReturnType<typeof import('./retrieveCachedConnection.ts')['retrieveCachedConnection']>>;
382
+ let result: Awaited<ReturnType<(typeof import('./retrieveCachedConnection.ts'))['retrieveCachedConnection']>>;
383
383
 
384
384
  beforeAll(async () => {
385
385
  const cursorCache = await generateCursorCache({
@@ -414,7 +414,7 @@ describe('retrieveCachedConnection', () => {
414
414
 
415
415
  it('should return the correct last edge', () => {
416
416
  const edges = extractEdges(result.cachedEdges);
417
- expect(decode((edges[edges.length - 1]!.node.id as string).split('::')[0]!)).toBe('9::10');
417
+ expect(decode((edges.at(-1)!.node.id as string).split('::')[0]!)).toBe('9::10');
418
418
  });
419
419
 
420
420
  it('should return hasPreviousPage as true', () => {
@@ -431,7 +431,7 @@ describe('retrieveCachedConnection', () => {
431
431
  });
432
432
 
433
433
  describe('when 25 cursors covering multiple pages and going UP TO the last page are requested', () => {
434
- let result: Awaited<ReturnType<typeof import('./retrieveCachedConnection.ts')['retrieveCachedConnection']>>;
434
+ let result: Awaited<ReturnType<(typeof import('./retrieveCachedConnection.ts'))['retrieveCachedConnection']>>;
435
435
 
436
436
  beforeAll(async () => {
437
437
  const cursorCache = await generateCursorCache({
@@ -466,7 +466,7 @@ describe('retrieveCachedConnection', () => {
466
466
 
467
467
  it('should return the correct last edge', () => {
468
468
  const edges = extractEdges(result.cachedEdges);
469
- expect(decode((edges[edges.length - 1]!.node.id as string).split('::')[0]!)).toBe('9::10');
469
+ expect(decode((edges.at(-1)!.node.id as string).split('::')[0]!)).toBe('9::10');
470
470
  });
471
471
 
472
472
  it('should return hasPreviousPage as true', () => {
@@ -486,7 +486,7 @@ describe('retrieveCachedConnection', () => {
486
486
 
487
487
  describe('retrieving edges before a cursor', () => {
488
488
  describe('when 5 cursors on the same page are requested', () => {
489
- let result: Awaited<ReturnType<typeof import('./retrieveCachedConnection.ts')['retrieveCachedConnection']>>;
489
+ let result: Awaited<ReturnType<(typeof import('./retrieveCachedConnection.ts'))['retrieveCachedConnection']>>;
490
490
 
491
491
  beforeAll(async () => {
492
492
  const cursorCache = await generateCursorCache({
@@ -521,7 +521,7 @@ describe('retrieveCachedConnection', () => {
521
521
 
522
522
  it('should return the correct last edge', () => {
523
523
  const edges = extractEdges(result.cachedEdges);
524
- expect(decode((edges[edges.length - 1]!.node.id as string).split('::')[0]!)).toBe('8::10');
524
+ expect(decode((edges.at(-1)!.node.id as string).split('::')[0]!)).toBe('8::10');
525
525
  });
526
526
 
527
527
  it('should return hasPreviousPage as true', () => {
@@ -538,7 +538,7 @@ describe('retrieveCachedConnection', () => {
538
538
  });
539
539
 
540
540
  describe('when 15 cursors covering multiple pages are requested', () => {
541
- let result: Awaited<ReturnType<typeof import('./retrieveCachedConnection.ts')['retrieveCachedConnection']>>;
541
+ let result: Awaited<ReturnType<(typeof import('./retrieveCachedConnection.ts'))['retrieveCachedConnection']>>;
542
542
 
543
543
  beforeAll(async () => {
544
544
  const cursorCache = await generateCursorCache({
@@ -573,7 +573,7 @@ describe('retrieveCachedConnection', () => {
573
573
 
574
574
  it('should return the correct last edge', () => {
575
575
  const edges = extractEdges(result.cachedEdges);
576
- expect(decode((edges[edges.length - 1]!.node.id as string).split('::')[0]!)).toBe('8::10');
576
+ expect(decode((edges.at(-1)!.node.id as string).split('::')[0]!)).toBe('8::10');
577
577
  });
578
578
 
579
579
  it('should return hasPreviousPage as true', () => {
@@ -590,7 +590,7 @@ describe('retrieveCachedConnection', () => {
590
590
  });
591
591
 
592
592
  describe('when 15 cursors going under the first page are requested', () => {
593
- let result: Awaited<ReturnType<typeof import('./retrieveCachedConnection.ts')['retrieveCachedConnection']>>;
593
+ let result: Awaited<ReturnType<(typeof import('./retrieveCachedConnection.ts'))['retrieveCachedConnection']>>;
594
594
 
595
595
  beforeAll(async () => {
596
596
  const cursorCache = await generateCursorCache({
@@ -625,7 +625,7 @@ describe('retrieveCachedConnection', () => {
625
625
 
626
626
  it('should return the correct last edge', () => {
627
627
  const edges = extractEdges(result.cachedEdges);
628
- expect(decode((edges[edges.length - 1]!.node.id as string).split('::')[0]!)).toBe('8::1');
628
+ expect(decode((edges.at(-1)!.node.id as string).split('::')[0]!)).toBe('8::1');
629
629
  });
630
630
 
631
631
  it('should return hasPreviousPage as false', () => {
@@ -642,7 +642,7 @@ describe('retrieveCachedConnection', () => {
642
642
  });
643
643
 
644
644
  describe('when 35 cursors covering multiple pages and going UNDER the first page are requested', () => {
645
- let result: Awaited<ReturnType<typeof import('./retrieveCachedConnection.ts')['retrieveCachedConnection']>>;
645
+ let result: Awaited<ReturnType<(typeof import('./retrieveCachedConnection.ts'))['retrieveCachedConnection']>>;
646
646
 
647
647
  beforeAll(async () => {
648
648
  const cursorCache = await generateCursorCache({
@@ -677,7 +677,7 @@ describe('retrieveCachedConnection', () => {
677
677
 
678
678
  it('should return the correct last edge', () => {
679
679
  const edges = extractEdges(result.cachedEdges);
680
- expect(decode((edges[edges.length - 1]!.node.id as string).split('::')[0]!)).toBe('6::3');
680
+ expect(decode((edges.at(-1)!.node.id as string).split('::')[0]!)).toBe('6::3');
681
681
  });
682
682
 
683
683
  it('should return hasPreviousPage as false', () => {
@@ -694,7 +694,7 @@ describe('retrieveCachedConnection', () => {
694
694
  });
695
695
 
696
696
  describe('when 25 cursors covering multiple pages and going DOWN TO the first page are requested', () => {
697
- let result: Awaited<ReturnType<typeof import('./retrieveCachedConnection.ts')['retrieveCachedConnection']>>;
697
+ let result: Awaited<ReturnType<(typeof import('./retrieveCachedConnection.ts'))['retrieveCachedConnection']>>;
698
698
 
699
699
  beforeAll(async () => {
700
700
  const cursorCache = await generateCursorCache({
@@ -729,7 +729,7 @@ describe('retrieveCachedConnection', () => {
729
729
 
730
730
  it('should return the correct last edge', () => {
731
731
  const edges = extractEdges(result.cachedEdges);
732
- expect(decode((edges[edges.length - 1]!.node.id as string).split('::')[0]!)).toBe('6::3');
732
+ expect(decode((edges.at(-1)!.node.id as string).split('::')[0]!)).toBe('6::3');
733
733
  });
734
734
 
735
735
  it('should return hasPreviousPage as true', () => {
@@ -747,7 +747,7 @@ describe('retrieveCachedConnection', () => {
747
747
 
748
748
  describe('when there are missing pages', () => {
749
749
  describe('when 35 cursors covering multiple pages and going UNDER the first page are requested', () => {
750
- let result: Awaited<ReturnType<typeof import('./retrieveCachedConnection.ts')['retrieveCachedConnection']>>;
750
+ let result: Awaited<ReturnType<(typeof import('./retrieveCachedConnection.ts'))['retrieveCachedConnection']>>;
751
751
 
752
752
  beforeAll(async () => {
753
753
  const cursorCache = await generateCursorCache({
@@ -782,7 +782,7 @@ describe('retrieveCachedConnection', () => {
782
782
 
783
783
  it('should return the correct last edge', () => {
784
784
  const edges = extractEdges(result.cachedEdges);
785
- expect(decode((edges[edges.length - 1]!.node.id as string).split('::')[0]!)).toBe('9::3');
785
+ expect(decode((edges.at(-1)!.node.id as string).split('::')[0]!)).toBe('9::3');
786
786
  });
787
787
 
788
788
  it('should return hasPreviousPage as false', () => {
@@ -799,7 +799,7 @@ describe('retrieveCachedConnection', () => {
799
799
  });
800
800
 
801
801
  describe('when 25 cursors covering multiple pages and going DOWN TO the first page are requested', () => {
802
- let result: Awaited<ReturnType<typeof import('./retrieveCachedConnection.ts')['retrieveCachedConnection']>>;
802
+ let result: Awaited<ReturnType<(typeof import('./retrieveCachedConnection.ts'))['retrieveCachedConnection']>>;
803
803
 
804
804
  beforeAll(async () => {
805
805
  const cursorCache = await generateCursorCache({
@@ -834,7 +834,7 @@ describe('retrieveCachedConnection', () => {
834
834
 
835
835
  it('should return the correct last edge', () => {
836
836
  const edges = extractEdges(result.cachedEdges);
837
- expect(decode((edges[edges.length - 1]!.node.id as string).split('::')[0]!)).toBe('9::3');
837
+ expect(decode((edges.at(-1)!.node.id as string).split('::')[0]!)).toBe('9::3');
838
838
  });
839
839
 
840
840
  it('should return hasPreviousPage as true', () => {
@@ -16,14 +16,13 @@ export type Context = {
16
16
 
17
17
  export const retrieveCachedConnection = async (
18
18
  args: ConnectionInputOptions,
19
- { cursorCache, groupCursor, resultsPerPage }: Context
19
+ { cursorCache, groupCursor, resultsPerPage }: Context,
20
20
  ) => {
21
- /**
22
- * At this point the cache will always have metadata because `retrieveCachedConnection`
23
- * is called from `resolveConnection` and is only called if there is a cursor, either
24
- * after a direct check or after calling `validateCursor` or `requestAndCachePages`,
25
- * which check and set the metadata respectively.
26
- */
21
+ // At this point the cache will always have metadata because `retrieveCachedConnection`
22
+ // is called from `resolveConnection` and is only called if there is a cursor, either
23
+ // after a direct check or after calling `validateCursor` or `requestAndCachePages`,
24
+ // which check and set the metadata respectively.
25
+ // eslint-disable-next-line @typescript-eslint/no-non-null-assertion
27
26
  const metadata = (await cursorCache.get<CursorGroupMetadata>(`${groupCursor}-metadata`))!;
28
27
  const entry = await retrieveEntry(args, metadata, { cursorCache, resultsPerPage });
29
28
  const startIndex = getStartIndex(args, { entry, resultsPerPage });
@@ -16,7 +16,7 @@ export type Context = {
16
16
  export const retrieveEntry = async (
17
17
  args: ConnectionInputOptions,
18
18
  metadata: CursorGroupMetadata,
19
- { cursorCache, resultsPerPage }: Context
19
+ { cursorCache, resultsPerPage }: Context,
20
20
  ): Promise<PartialCursorCacheEntry> => {
21
21
  const cursor = getCursor(args);
22
22
 
@@ -25,7 +25,7 @@ describe('validateCursor', () => {
25
25
  const result = await validateCursor({ after: 'abcdefg' }, info as GraphQLResolveInfo, ctx);
26
26
 
27
27
  expect(result?.message).toBe(
28
- 'Invalid connection argument combination. `after` must be used in combination with `first`.'
28
+ 'Invalid connection argument combination. `after` must be used in combination with `first`.',
29
29
  );
30
30
  });
31
31
  });
@@ -37,7 +37,7 @@ describe('validateCursor', () => {
37
37
  const result = await validateCursor({ after: 'abcdefg', last: 5 }, info as GraphQLResolveInfo, ctx);
38
38
 
39
39
  expect(result?.message).toBe(
40
- 'Invalid connection argument combination. `after` cannot be used in combination with `last`.'
40
+ 'Invalid connection argument combination. `after` cannot be used in combination with `last`.',
41
41
  );
42
42
  });
43
43
  });
@@ -49,7 +49,7 @@ describe('validateCursor', () => {
49
49
  const result = await validateCursor({ before: 'abcdefg' }, info as GraphQLResolveInfo, ctx);
50
50
 
51
51
  expect(result?.message).toBe(
52
- 'Invalid connection argument combination. `before` must be used in combination with `last`.'
52
+ 'Invalid connection argument combination. `before` must be used in combination with `last`.',
53
53
  );
54
54
  });
55
55
  });
@@ -61,7 +61,7 @@ describe('validateCursor', () => {
61
61
  const result = await validateCursor({ before: 'abcdefg', first: 5 }, info as GraphQLResolveInfo, ctx);
62
62
 
63
63
  expect(result?.message).toBe(
64
- 'Invalid connection argument combination. `before` cannot be used in combination with `first`.'
64
+ 'Invalid connection argument combination. `before` cannot be used in combination with `first`.',
65
65
  );
66
66
  });
67
67
  });
@@ -15,33 +15,33 @@ export type Context = {
15
15
  export const validateCursor = async (
16
16
  { after, before, first, last }: ConnectionInputOptions,
17
17
  { fieldNodes }: GraphQLResolveInfo,
18
- { cursorCache, groupCursor, resultsPerPage }: Context
18
+ { cursorCache, groupCursor, resultsPerPage }: Context,
19
19
  ) => {
20
20
  if (after && !first && !last) {
21
21
  return new GraphQLError(
22
22
  'Invalid connection argument combination. `after` must be used in combination with `first`.',
23
- { nodes: fieldNodes }
23
+ { nodes: fieldNodes },
24
24
  );
25
25
  }
26
26
 
27
27
  if (after && last) {
28
28
  return new GraphQLError(
29
29
  'Invalid connection argument combination. `after` cannot be used in combination with `last`.',
30
- { nodes: fieldNodes }
30
+ { nodes: fieldNodes },
31
31
  );
32
32
  }
33
33
 
34
34
  if (before && !last && !first) {
35
35
  return new GraphQLError(
36
36
  'Invalid connection argument combination. `before` must be used in combination with `last`.',
37
- { nodes: fieldNodes }
37
+ { nodes: fieldNodes },
38
38
  );
39
39
  }
40
40
 
41
41
  if (before && first) {
42
42
  return new GraphQLError(
43
43
  'Invalid connection argument combination. `before` cannot be used in combination with `first`.',
44
- { nodes: fieldNodes }
44
+ { nodes: fieldNodes },
45
45
  );
46
46
  }
47
47
 
@@ -51,7 +51,12 @@ export const validateCursor = async (
51
51
  return new GraphQLError('Curser cannot be supplied without previously being provided.', { nodes: fieldNodes });
52
52
  }
53
53
 
54
- const cursor = getCursor({ after, before })!;
54
+ const cursor = getCursor({ after, before });
55
+
56
+ if (!cursor) {
57
+ return new GraphQLError(`The cursor could not be found.`, { nodes: fieldNodes });
58
+ }
59
+
55
60
  const entry = await cursorCache.get<CursorCacheEntry>(cursor);
56
61
 
57
62
  if (!entry) {
@@ -12,7 +12,7 @@ import { makeConnectionResolver } from './index.ts';
12
12
 
13
13
  const createMakeCursors = (_source: PlainObject, args: PlainObject) => ({
14
14
  makeGroupCursor: () => encode(JSON.stringify(removeConnectionInputOptions(args))),
15
- makeIDCursor: (id: string | number) => encode(`${id}::${JSON.stringify(removeConnectionInputOptions(args))}`),
15
+ makeIDCursor: (id: string | number) => encode(`${String(id)}::${JSON.stringify(removeConnectionInputOptions(args))}`),
16
16
  });
17
17
 
18
18
  const getters = {
@@ -27,7 +27,7 @@ const resultsPerPage = 10;
27
27
  describe('connectionResolver', () => {
28
28
  describe('when a cursor is supplied', () => {
29
29
  describe('when the cursor is invalid', () => {
30
- let result: Awaited<ReturnType<ReturnType<typeof import('./index.ts')['makeConnectionResolver']>>>;
30
+ let result: Awaited<ReturnType<ReturnType<(typeof import('./index.ts'))['makeConnectionResolver']>>>;
31
31
 
32
32
  beforeAll(async () => {
33
33
  const createResourceResolver =
@@ -57,7 +57,7 @@ describe('connectionResolver', () => {
57
57
  edges: [],
58
58
  errors: [
59
59
  new GraphQLError(
60
- 'Invalid connection argument combination. `before` cannot be used in combination with `first`.'
60
+ 'Invalid connection argument combination. `before` cannot be used in combination with `first`.',
61
61
  ),
62
62
  ],
63
63
  nodes: [],
@@ -71,7 +71,7 @@ describe('connectionResolver', () => {
71
71
  });
72
72
 
73
73
  describe('when there are NO missing pages in the cache', () => {
74
- let result: Awaited<ReturnType<ReturnType<typeof import('./index.ts')['makeConnectionResolver']>>>;
74
+ let result: Awaited<ReturnType<ReturnType<(typeof import('./index.ts'))['makeConnectionResolver']>>>;
75
75
 
76
76
  beforeAll(async () => {
77
77
  const createResourceResolver =
@@ -113,7 +113,7 @@ describe('connectionResolver', () => {
113
113
  });
114
114
 
115
115
  describe('when there are missing pages in the cache', () => {
116
- let result: Awaited<ReturnType<ReturnType<typeof import('./index.ts')['makeConnectionResolver']>>>;
116
+ let result: Awaited<ReturnType<ReturnType<(typeof import('./index.ts'))['makeConnectionResolver']>>>;
117
117
  const pageResponse = generatePageResponse({ resultsPerPage, totalPages: 10, totalResults: 100 });
118
118
 
119
119
  const mock = jest
@@ -170,7 +170,7 @@ describe('connectionResolver', () => {
170
170
 
171
171
  describe('when the first [X] number are requested', () => {
172
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']>>>;
173
+ let result: Awaited<ReturnType<ReturnType<(typeof import('./index.ts'))['makeConnectionResolver']>>>;
174
174
 
175
175
  beforeAll(async () => {
176
176
  const createResourceResolver =
@@ -211,7 +211,7 @@ describe('connectionResolver', () => {
211
211
  });
212
212
 
213
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']>>>;
214
+ let result: Awaited<ReturnType<ReturnType<(typeof import('./index.ts'))['makeConnectionResolver']>>>;
215
215
  const pageResponse = generatePageResponse({ resultsPerPage, totalPages: 10, totalResults: 100 });
216
216
 
217
217
  const mock = jest
@@ -265,7 +265,7 @@ describe('connectionResolver', () => {
265
265
  });
266
266
 
267
267
  describe('when there is NOT a fresh cache', () => {
268
- let result: Awaited<ReturnType<ReturnType<typeof import('./index.ts')['makeConnectionResolver']>>>;
268
+ let result: Awaited<ReturnType<ReturnType<(typeof import('./index.ts'))['makeConnectionResolver']>>>;
269
269
  const pageResponse = generatePageResponse({ resultsPerPage, totalPages: 10, totalResults: 100 });
270
270
 
271
271
  const mock = jest
@@ -317,7 +317,7 @@ describe('connectionResolver', () => {
317
317
 
318
318
  describe('when the last [X] number are requested', () => {
319
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']>>>;
320
+ let result: Awaited<ReturnType<ReturnType<(typeof import('./index.ts'))['makeConnectionResolver']>>>;
321
321
 
322
322
  beforeAll(async () => {
323
323
  const createResourceResolver =
@@ -358,7 +358,7 @@ describe('connectionResolver', () => {
358
358
  });
359
359
 
360
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']>>>;
361
+ let result: Awaited<ReturnType<ReturnType<(typeof import('./index.ts'))['makeConnectionResolver']>>>;
362
362
  const pageResponse = generatePageResponse({ resultsPerPage, totalPages: 10, totalResults: 100 });
363
363
 
364
364
  const mock = jest
@@ -412,7 +412,7 @@ describe('connectionResolver', () => {
412
412
  });
413
413
 
414
414
  describe('when there is NOT a fresh cache', () => {
415
- let result: Awaited<ReturnType<ReturnType<typeof import('./index.ts')['makeConnectionResolver']>>>;
415
+ let result: Awaited<ReturnType<ReturnType<(typeof import('./index.ts'))['makeConnectionResolver']>>>;
416
416
  const pageResponse = generatePageResponse({ resultsPerPage, totalPages: 10, totalResults: 100 });
417
417
 
418
418
  const mock = jest
package/src/main/index.ts CHANGED
@@ -17,7 +17,7 @@ export const makeConnectionResolver =
17
17
  Args extends PlainObject,
18
18
  Ctx extends PlainObject,
19
19
  Resource extends PlainObject,
20
- ResourceNode extends Node
20
+ ResourceNode extends Node,
21
21
  >({
22
22
  createMakeCursors,
23
23
  createResourceResolver,
@@ -30,7 +30,7 @@ export const makeConnectionResolver =
30
30
  source: Source,
31
31
  args: Args & ConnectionInputOptions,
32
32
  context: Ctx,
33
- info: GraphQLResolveInfo
33
+ info: GraphQLResolveInfo,
34
34
  ): Promise<Connection> => {
35
35
  const { makeGroupCursor, makeIDCursor } = createMakeCursors(source, args, context, info);
36
36
  const resourceResolver = createResourceResolver(source, args, context, info);
@@ -64,7 +64,7 @@ export const makeConnectionResolver =
64
64
  makeIDCursor,
65
65
  resourceResolver,
66
66
  resultsPerPage,
67
- })
67
+ }),
68
68
  );
69
69
  }
70
70
 
@@ -77,7 +77,7 @@ export const makeConnectionResolver =
77
77
  makeIDCursor,
78
78
  resourceResolver,
79
79
  resultsPerPage,
80
- })
80
+ }),
81
81
  );
82
82
  }
83
83
 
@@ -97,6 +97,6 @@ export const makeConnectionResolver =
97
97
  makeIDCursor,
98
98
  resourceResolver,
99
99
  resultsPerPage,
100
- })
100
+ }),
101
101
  );
102
102
  };
package/src/types.ts CHANGED
@@ -64,7 +64,7 @@ export type CreateResourceResolver<
64
64
  Source extends PlainObject | undefined,
65
65
  Args extends PlainObject,
66
66
  Ctx extends PlainObject,
67
- Resource extends PlainObject
67
+ Resource extends PlainObject,
68
68
  > = (source: Source, args: Args, context: Ctx, info: GraphQLResolveInfo) => ResourceResolver<Resource>;
69
69
 
70
70
  export interface Getters<Resource extends PlainObject, ResourceNode extends Node> {
@@ -79,13 +79,13 @@ export interface ConnectionResolverUserOptions<
79
79
  Args extends PlainObject,
80
80
  Ctx extends PlainObject,
81
81
  Resource extends PlainObject,
82
- ResourceNode extends Node
82
+ ResourceNode extends Node,
83
83
  > {
84
84
  createMakeCursors: (
85
85
  source: Source,
86
86
  args: Args,
87
87
  context: Ctx,
88
- info: GraphQLResolveInfo
88
+ info: GraphQLResolveInfo,
89
89
  ) => {
90
90
  makeGroupCursor: () => string;
91
91
  makeIDCursor: (id: string | number) => string;
@@ -101,7 +101,7 @@ export type ConnectionResolver = (
101
101
  source: PlainObject,
102
102
  args: PlainObject & ConnectionInputOptions,
103
103
  context: PlainObject,
104
- info: GraphQLResolveInfo
104
+ info: GraphQLResolveInfo,
105
105
  ) => Promise<Connection>;
106
106
 
107
107
  export type ConnectionInputOptions = {