@graphql-box/connection-resolver 0.1.2 → 0.1.6

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 (39) hide show
  1. package/lib/browser/index.js +1 -1
  2. package/lib/browser/index.js.map +1 -1
  3. package/lib/browser/production.analysis.txt +29 -29
  4. package/lib/main/helpers/isCursorSupplied.js.map +1 -1
  5. package/lib/main/helpers/requestAndCachePages.js +2 -1
  6. package/lib/main/helpers/requestAndCachePages.js.map +1 -1
  7. package/lib/main/helpers/resolveConnection.js +2 -1
  8. package/lib/main/helpers/resolveConnection.js.map +1 -1
  9. package/lib/main/main/index.js +3 -2
  10. package/lib/main/main/index.js.map +1 -1
  11. package/lib/module/helpers/isCursorSupplied.js.map +1 -1
  12. package/lib/module/helpers/requestAndCachePages.js +5 -2
  13. package/lib/module/helpers/requestAndCachePages.js.map +1 -1
  14. package/lib/module/helpers/resolveConnection.js +5 -2
  15. package/lib/module/helpers/resolveConnection.js.map +1 -1
  16. package/lib/module/main/index.js +6 -3
  17. package/lib/module/main/index.js.map +1 -1
  18. package/lib/types/defs/index.d.ts +25 -22
  19. package/lib/types/defs/index.d.ts.map +1 -1
  20. package/lib/types/helpers/extractNodes.d.ts +1 -1
  21. package/lib/types/helpers/isCursorSupplied.d.ts +2 -2
  22. package/lib/types/helpers/isCursorSupplied.d.ts.map +1 -1
  23. package/lib/types/helpers/requestAndCachePages.d.ts +7 -7
  24. package/lib/types/helpers/requestAndCachePages.d.ts.map +1 -1
  25. package/lib/types/helpers/resolveConnection.d.ts +7 -7
  26. package/lib/types/helpers/resolveConnection.d.ts.map +1 -1
  27. package/lib/types/main/index.d.ts +3 -3
  28. package/lib/types/main/index.d.ts.map +1 -1
  29. package/package-lock.json +18 -0
  30. package/package.json +1 -1
  31. package/src/defs/index.ts +43 -31
  32. package/src/helpers/getPageNumbersToRequest.test.ts +2 -2
  33. package/src/helpers/getStartAndEndIndexes.test.ts +10 -10
  34. package/src/helpers/isCursorSupplied.ts +2 -2
  35. package/src/helpers/requestAndCachePages.ts +8 -6
  36. package/src/helpers/resolveConnection.ts +17 -8
  37. package/src/helpers/retrieveCachedConnection.test.ts +32 -32
  38. package/src/main/index.test.ts +34 -59
  39. package/src/main/index.ts +16 -8
@@ -1,19 +1,19 @@
1
1
  import Cachemap from "@cachemap/core";
2
- import { Getters, ResourceResolver } from "../defs";
2
+ import { Getters, Node, PlainObject, ResourceResolver } from "../defs";
3
3
  import cacheCursors from "./cacheCursors";
4
4
  import makeEdges from "./makeEdges";
5
5
 
6
- export type Context = {
6
+ export type Context<Resource extends PlainObject, ResourceNode extends Node> = {
7
7
  cursorCache: Cachemap;
8
- getters: Getters;
8
+ getters: Getters<Resource, ResourceNode>;
9
9
  groupCursor: string;
10
10
  makeIDCursor: (id: string | number) => string;
11
- resourceResolver: ResourceResolver;
11
+ resourceResolver: ResourceResolver<Resource>;
12
12
  };
13
13
 
14
- export default async (
14
+ const requestAndCachePages = async <Resource extends PlainObject, ResourceNode extends Node>(
15
15
  pages: number[],
16
- { cursorCache, getters, groupCursor, makeIDCursor, resourceResolver }: Context,
16
+ { cursorCache, getters, groupCursor, makeIDCursor, resourceResolver }: Context<Resource, ResourceNode>,
17
17
  ) => {
18
18
  const errors: Error[] = [];
19
19
 
@@ -48,3 +48,5 @@ export default async (
48
48
 
49
49
  return { cachedEdges, errors };
50
50
  };
51
+
52
+ export default requestAndCachePages;
@@ -1,5 +1,5 @@
1
1
  import Cachemap from "@cachemap/core";
2
- import { ConnectionInputOptions, Getters, ResourceResolver } from "../defs";
2
+ import { ConnectionInputOptions, Getters, Node, PlainObject, ResourceResolver } from "../defs";
3
3
  import extractEdges from "./extractEdges";
4
4
  import extractNodes from "./extractNodes";
5
5
  import getInRangeCachedEdges from "./getInRangeCachedEdges";
@@ -8,18 +8,25 @@ import mergeCachedEdges from "./mergeCachedEdges";
8
8
  import requestAndCachePages from "./requestAndCachePages";
9
9
  import retrieveCachedConnection from "./retrieveCachedConnection";
10
10
 
11
- export type Context = {
11
+ export type Context<Resource extends PlainObject, ResourceNode extends Node> = {
12
12
  cursorCache: Cachemap;
13
- getters: Getters;
13
+ getters: Getters<Resource, ResourceNode>;
14
14
  groupCursor: string;
15
15
  makeIDCursor: (id: string | number) => string;
16
- resourceResolver: ResourceResolver;
16
+ resourceResolver: ResourceResolver<Resource>;
17
17
  resultsPerPage: number;
18
18
  };
19
19
 
20
- export default async (
21
- args: Record<string, any> & ConnectionInputOptions,
22
- { cursorCache, getters, groupCursor, makeIDCursor, resourceResolver, resultsPerPage }: Context,
20
+ const resolveConnection = async <Resource extends PlainObject, ResourceNode extends Node>(
21
+ args: PlainObject & ConnectionInputOptions,
22
+ {
23
+ cursorCache,
24
+ getters,
25
+ groupCursor,
26
+ makeIDCursor,
27
+ resourceResolver,
28
+ resultsPerPage,
29
+ }: Context<Resource, ResourceNode>,
23
30
  ) => {
24
31
  const {
25
32
  cachedEdges,
@@ -51,7 +58,7 @@ export default async (
51
58
  };
52
59
  }
53
60
 
54
- const { cachedEdges: missingCachedEdges, errors } = await requestAndCachePages(missingPages, {
61
+ const { cachedEdges: missingCachedEdges, errors } = await requestAndCachePages<Resource, ResourceNode>(missingPages, {
55
62
  cursorCache,
56
63
  getters,
57
64
  groupCursor,
@@ -80,3 +87,5 @@ export default async (
80
87
  totalCount: totalResults,
81
88
  };
82
89
  };
90
+
91
+ export default resolveConnection;
@@ -30,8 +30,8 @@ describe("retrieveCachedConnection", () => {
30
30
 
31
31
  const edges = extractEdges(cachedEdges);
32
32
  expect(edges.length).toBe(5);
33
- expect(decode(edges[0].node.id.split("::")[0])).toBe("1::1");
34
- expect(decode(edges[edges.length - 1].node.id.split("::")[0])).toBe("5::1");
33
+ expect(decode((edges[0].node.id as string).split("::")[0])).toBe("1::1");
34
+ expect(decode((edges[edges.length - 1].node.id as string).split("::")[0])).toBe("5::1");
35
35
  expect(hasPreviousPage).toBe(true);
36
36
  expect(hasNextPage).toBe(true);
37
37
  expect(missingPages.length).toBe(0);
@@ -59,8 +59,8 @@ describe("retrieveCachedConnection", () => {
59
59
 
60
60
  const edges = extractEdges(cachedEdges);
61
61
  expect(edges.length).toBe(15);
62
- expect(decode(edges[0].node.id.split("::")[0])).toBe("6::1");
63
- expect(decode(edges[edges.length - 1].node.id.split("::")[0])).toBe("0::3");
62
+ expect(decode((edges[0].node.id as string).split("::")[0])).toBe("6::1");
63
+ expect(decode((edges[edges.length - 1].node.id as string).split("::")[0])).toBe("0::3");
64
64
  expect(hasPreviousPage).toBe(true);
65
65
  expect(hasNextPage).toBe(true);
66
66
  expect(missingPages.length).toBe(0);
@@ -88,8 +88,8 @@ describe("retrieveCachedConnection", () => {
88
88
 
89
89
  const edges = extractEdges(cachedEdges);
90
90
  expect(edges.length).toBe(9);
91
- expect(decode(edges[0].node.id.split("::")[0])).toBe("1::10");
92
- expect(decode(edges[edges.length - 1].node.id.split("::")[0])).toBe("9::10");
91
+ expect(decode((edges[0].node.id as string).split("::")[0])).toBe("1::10");
92
+ expect(decode((edges[edges.length - 1].node.id as string).split("::")[0])).toBe("9::10");
93
93
  expect(hasPreviousPage).toBe(true);
94
94
  expect(hasNextPage).toBe(false);
95
95
  expect(missingPages.length).toBe(0);
@@ -118,8 +118,8 @@ describe("retrieveCachedConnection", () => {
118
118
 
119
119
  const edges = extractEdges(cachedEdges);
120
120
  expect(edges.length).toBe(29);
121
- expect(decode(edges[0].node.id.split("::")[0])).toBe("1::8");
122
- expect(decode(edges[edges.length - 1].node.id.split("::")[0])).toBe("9::10");
121
+ expect(decode((edges[0].node.id as string).split("::")[0])).toBe("1::8");
122
+ expect(decode((edges[edges.length - 1].node.id as string).split("::")[0])).toBe("9::10");
123
123
  expect(hasPreviousPage).toBe(true);
124
124
  expect(hasNextPage).toBe(false);
125
125
  expect(missingPages.length).toBe(0);
@@ -147,8 +147,8 @@ describe("retrieveCachedConnection", () => {
147
147
 
148
148
  const edges = extractEdges(cachedEdges);
149
149
  expect(edges.length).toBe(25);
150
- expect(decode(edges[0].node.id.split("::")[0])).toBe("1::8");
151
- expect(decode(edges[edges.length - 1].node.id.split("::")[0])).toBe("5::10");
150
+ expect(decode((edges[0].node.id as string).split("::")[0])).toBe("1::8");
151
+ expect(decode((edges[edges.length - 1].node.id as string).split("::")[0])).toBe("5::10");
152
152
  expect(hasPreviousPage).toBe(true);
153
153
  expect(hasNextPage).toBe(false);
154
154
  expect(missingPages.length).toBe(0);
@@ -178,8 +178,8 @@ describe("retrieveCachedConnection", () => {
178
178
 
179
179
  const edges = extractEdges(cachedEdges);
180
180
  expect(edges.length).toBe(25);
181
- expect(decode(edges[0].node.id.split("::")[0])).toBe("1::8");
182
- expect(decode(edges[edges.length - 1].node.id.split("::")[0])).toBe("5::10");
181
+ expect(decode((edges[0].node.id as string).split("::")[0])).toBe("1::8");
182
+ expect(decode((edges[edges.length - 1].node.id as string).split("::")[0])).toBe("5::10");
183
183
  expect(hasPreviousPage).toBe(true);
184
184
  expect(hasNextPage).toBe(true);
185
185
  expect(missingPages.length).toBe(0);
@@ -207,8 +207,8 @@ describe("retrieveCachedConnection", () => {
207
207
 
208
208
  const edges = extractEdges(cachedEdges);
209
209
  expect(edges.length).toBe(25);
210
- expect(decode(edges[0].node.id.split("::")[0])).toBe("1::8");
211
- expect(decode(edges[edges.length - 1].node.id.split("::")[0])).toBe("5::10");
210
+ expect(decode((edges[0].node.id as string).split("::")[0])).toBe("1::8");
211
+ expect(decode((edges[edges.length - 1].node.id as string).split("::")[0])).toBe("5::10");
212
212
  expect(hasPreviousPage).toBe(true);
213
213
  expect(hasNextPage).toBe(false);
214
214
  expect(missingPages.length).toBe(0);
@@ -238,8 +238,8 @@ describe("retrieveCachedConnection", () => {
238
238
 
239
239
  const edges = extractEdges(cachedEdges);
240
240
  expect(edges.length).toBe(20);
241
- expect(decode(edges[0].node.id.split("::")[0])).toBe("0::8");
242
- expect(decode(edges[edges.length - 1].node.id.split("::")[0])).toBe("9::10");
241
+ expect(decode((edges[0].node.id as string).split("::")[0])).toBe("0::8");
242
+ expect(decode((edges[edges.length - 1].node.id as string).split("::")[0])).toBe("9::10");
243
243
  expect(hasPreviousPage).toBe(true);
244
244
  expect(hasNextPage).toBe(false);
245
245
  expect(missingPages.length).toBe(1);
@@ -268,8 +268,8 @@ describe("retrieveCachedConnection", () => {
268
268
 
269
269
  const edges = extractEdges(cachedEdges);
270
270
  expect(edges.length).toBe(20);
271
- expect(decode(edges[0].node.id.split("::")[0])).toBe("0::8");
272
- expect(decode(edges[edges.length - 1].node.id.split("::")[0])).toBe("9::10");
271
+ expect(decode((edges[0].node.id as string).split("::")[0])).toBe("0::8");
272
+ expect(decode((edges[edges.length - 1].node.id as string).split("::")[0])).toBe("9::10");
273
273
  expect(hasPreviousPage).toBe(true);
274
274
  expect(hasNextPage).toBe(true);
275
275
  expect(missingPages.length).toBe(1);
@@ -301,8 +301,8 @@ describe("retrieveCachedConnection", () => {
301
301
 
302
302
  const edges = extractEdges(cachedEdges);
303
303
  expect(edges.length).toBe(5);
304
- expect(decode(edges[0].node.id.split("::")[0])).toBe("4::10");
305
- expect(decode(edges[edges.length - 1].node.id.split("::")[0])).toBe("8::10");
304
+ expect(decode((edges[0].node.id as string).split("::")[0])).toBe("4::10");
305
+ expect(decode((edges[edges.length - 1].node.id as string).split("::")[0])).toBe("8::10");
306
306
  expect(hasPreviousPage).toBe(true);
307
307
  expect(hasNextPage).toBe(true);
308
308
  expect(missingPages.length).toBe(0);
@@ -330,8 +330,8 @@ describe("retrieveCachedConnection", () => {
330
330
 
331
331
  const edges = extractEdges(cachedEdges);
332
332
  expect(edges.length).toBe(15);
333
- expect(decode(edges[0].node.id.split("::")[0])).toBe("4::9");
334
- expect(decode(edges[edges.length - 1].node.id.split("::")[0])).toBe("8::10");
333
+ expect(decode((edges[0].node.id as string).split("::")[0])).toBe("4::9");
334
+ expect(decode((edges[edges.length - 1].node.id as string).split("::")[0])).toBe("8::10");
335
335
  expect(hasPreviousPage).toBe(true);
336
336
  expect(hasNextPage).toBe(true);
337
337
  expect(missingPages.length).toBe(0);
@@ -359,8 +359,8 @@ describe("retrieveCachedConnection", () => {
359
359
 
360
360
  const edges = extractEdges(cachedEdges);
361
361
  expect(edges.length).toBe(9);
362
- expect(decode(edges[0].node.id.split("::")[0])).toBe("0::1");
363
- expect(decode(edges[edges.length - 1].node.id.split("::")[0])).toBe("8::1");
362
+ expect(decode((edges[0].node.id as string).split("::")[0])).toBe("0::1");
363
+ expect(decode((edges[edges.length - 1].node.id as string).split("::")[0])).toBe("8::1");
364
364
  expect(hasPreviousPage).toBe(false);
365
365
  expect(hasNextPage).toBe(true);
366
366
  expect(missingPages.length).toBe(0);
@@ -388,8 +388,8 @@ describe("retrieveCachedConnection", () => {
388
388
 
389
389
  const edges = extractEdges(cachedEdges);
390
390
  expect(edges.length).toBe(27);
391
- expect(decode(edges[0].node.id.split("::")[0])).toBe("0::1");
392
- expect(decode(edges[edges.length - 1].node.id.split("::")[0])).toBe("6::3");
391
+ expect(decode((edges[0].node.id as string).split("::")[0])).toBe("0::1");
392
+ expect(decode((edges[edges.length - 1].node.id as string).split("::")[0])).toBe("6::3");
393
393
  expect(hasPreviousPage).toBe(false);
394
394
  expect(hasNextPage).toBe(true);
395
395
  expect(missingPages.length).toBe(0);
@@ -417,8 +417,8 @@ describe("retrieveCachedConnection", () => {
417
417
 
418
418
  const edges = extractEdges(cachedEdges);
419
419
  expect(edges.length).toBe(25);
420
- expect(decode(edges[0].node.id.split("::")[0])).toBe("2::1");
421
- expect(decode(edges[edges.length - 1].node.id.split("::")[0])).toBe("6::3");
420
+ expect(decode((edges[0].node.id as string).split("::")[0])).toBe("2::1");
421
+ expect(decode((edges[edges.length - 1].node.id as string).split("::")[0])).toBe("6::3");
422
422
  expect(hasPreviousPage).toBe(true);
423
423
  expect(hasNextPage).toBe(true);
424
424
  expect(missingPages.length).toBe(0);
@@ -447,8 +447,8 @@ describe("retrieveCachedConnection", () => {
447
447
 
448
448
  const edges = extractEdges(cachedEdges);
449
449
  expect(edges.length).toBe(20);
450
- expect(decode(edges[0].node.id.split("::")[0])).toBe("0::1");
451
- expect(decode(edges[edges.length - 1].node.id.split("::")[0])).toBe("9::3");
450
+ expect(decode((edges[0].node.id as string).split("::")[0])).toBe("0::1");
451
+ expect(decode((edges[edges.length - 1].node.id as string).split("::")[0])).toBe("9::3");
452
452
  expect(hasPreviousPage).toBe(false);
453
453
  expect(hasNextPage).toBe(true);
454
454
  expect(missingPages.length).toBe(1);
@@ -477,8 +477,8 @@ describe("retrieveCachedConnection", () => {
477
477
 
478
478
  const edges = extractEdges(cachedEdges);
479
479
  expect(edges.length).toBe(20);
480
- expect(decode(edges[0].node.id.split("::")[0])).toBe("0::1");
481
- expect(decode(edges[edges.length - 1].node.id.split("::")[0])).toBe("9::3");
480
+ expect(decode((edges[0].node.id as string).split("::")[0])).toBe("0::1");
481
+ expect(decode((edges[edges.length - 1].node.id as string).split("::")[0])).toBe("9::3");
482
482
  expect(hasPreviousPage).toBe(true);
483
483
  expect(hasNextPage).toBe(true);
484
484
  expect(missingPages.length).toBe(1);
@@ -5,31 +5,27 @@ import { encode } from "js-base64";
5
5
  import makeConnectionResolver from ".";
6
6
  import generateCursorCache from "../__testUtils__/generateCursorCache";
7
7
  import generatePageResponse from "../__testUtils__/generatePageResponse";
8
- import { Getters } from "../defs";
8
+ import { PlainObject } from "../defs";
9
9
  import removeConnectionInputOptions from "../helpers/removeConnectionInputOptions";
10
10
 
11
11
  describe("connectionResolver", () => {
12
- const createMakeCursors = (_source: Record<string, any>, args: Record<string, any>) => ({
12
+ const createMakeCursors = (_source: PlainObject, args: PlainObject) => ({
13
13
  makeGroupCursor: () => encode(JSON.stringify(removeConnectionInputOptions(args))),
14
14
  makeIDCursor: (id: string | number) => encode(`${id}::${JSON.stringify(removeConnectionInputOptions(args))}`),
15
15
  });
16
16
 
17
- const getters: Getters = {
18
- nodes: ({ results }) => results,
19
- page: ({ page }) => page,
20
- totalPages: ({ totalPages }) => totalPages,
21
- totalResults: ({ totalResults }) => totalResults,
17
+ const getters = {
18
+ nodes: ({ results }: PlainObject) => results,
19
+ page: ({ page }: PlainObject) => page,
20
+ totalPages: ({ totalPages }: PlainObject) => totalPages,
21
+ totalResults: ({ totalResults }: PlainObject) => totalResults,
22
22
  };
23
23
 
24
24
  const resultsPerPage = 10;
25
25
 
26
26
  describe("when a cursor is supplied", () => {
27
27
  test("when the cursor is invalid", async () => {
28
- const createResourceResolver = (
29
- _obj: Record<string, any>,
30
- args: Record<string, any>,
31
- { restClient }: Record<string, any>,
32
- ) => {
28
+ const createResourceResolver = (_obj: PlainObject, args: PlainObject, { restClient }: PlainObject) => {
33
29
  return async ({ page }: { page: number }) => restClient({ ...removeConnectionInputOptions(args), page });
34
30
  };
35
31
 
@@ -41,7 +37,6 @@ describe("connectionResolver", () => {
41
37
  store: map(),
42
38
  }),
43
39
  getters,
44
- resolver: result => result,
45
40
  resultsPerPage,
46
41
  });
47
42
 
@@ -57,11 +52,7 @@ describe("connectionResolver", () => {
57
52
  });
58
53
 
59
54
  test("when there are NO missing pages in the cache", async () => {
60
- const createResourceResolver = (
61
- _obj: Record<string, any>,
62
- args: Record<string, any>,
63
- { restClient }: Record<string, any>,
64
- ) => {
55
+ const createResourceResolver = (_obj: PlainObject, args: PlainObject, { restClient }: PlainObject) => {
65
56
  return async ({ page }: { page: number }) => restClient({ ...removeConnectionInputOptions(args), page });
66
57
  };
67
58
 
@@ -79,8 +70,7 @@ describe("connectionResolver", () => {
79
70
  createMakeCursors,
80
71
  createResourceResolver,
81
72
  cursorCache,
82
- getters: (getters as unknown) as Getters,
83
- resolver: result => result,
73
+ getters,
84
74
  resultsPerPage,
85
75
  });
86
76
 
@@ -99,9 +89,9 @@ describe("connectionResolver", () => {
99
89
  const mock = jest.fn().mockImplementation(page => pageResponse(page));
100
90
 
101
91
  const createResourceResolver = (
102
- _obj: Record<string, any>,
103
- _args: Record<string, any>,
104
- _context: Record<string, any>,
92
+ _obj: PlainObject,
93
+ _args: PlainObject,
94
+ _context: PlainObject,
105
95
  _info: GraphQLResolveInfo,
106
96
  ) => async ({ page }: { page: number }) => mock(page);
107
97
 
@@ -119,8 +109,7 @@ describe("connectionResolver", () => {
119
109
  createMakeCursors,
120
110
  createResourceResolver,
121
111
  cursorCache,
122
- getters: (getters as unknown) as Getters,
123
- resolver: result => result,
112
+ getters,
124
113
  resultsPerPage,
125
114
  });
126
115
 
@@ -139,11 +128,7 @@ describe("connectionResolver", () => {
139
128
 
140
129
  describe("when the first [X] number are requested", () => {
141
130
  test("when there is a fresh cache and there are NO missing pages in the cache", async () => {
142
- const createResourceResolver = (
143
- _obj: Record<string, any>,
144
- args: Record<string, any>,
145
- { restClient }: Record<string, any>,
146
- ) => {
131
+ const createResourceResolver = (_obj: PlainObject, args: PlainObject, { restClient }: PlainObject) => {
147
132
  return async ({ page }: { page: number }) => restClient({ ...removeConnectionInputOptions(args), page });
148
133
  };
149
134
 
@@ -161,8 +146,7 @@ describe("connectionResolver", () => {
161
146
  createMakeCursors,
162
147
  createResourceResolver,
163
148
  cursorCache,
164
- getters: (getters as unknown) as Getters,
165
- resolver: result => result,
149
+ getters,
166
150
  resultsPerPage,
167
151
  });
168
152
 
@@ -180,9 +164,9 @@ describe("connectionResolver", () => {
180
164
  const mock = jest.fn().mockImplementation(page => pageResponse(page));
181
165
 
182
166
  const createResourceResolver = (
183
- _obj: Record<string, any>,
184
- _args: Record<string, any>,
185
- _context: Record<string, any>,
167
+ _obj: PlainObject,
168
+ _args: PlainObject,
169
+ _context: PlainObject,
186
170
  _info: GraphQLResolveInfo,
187
171
  ) => async ({ page }: { page: number }) => mock(page);
188
172
 
@@ -200,8 +184,7 @@ describe("connectionResolver", () => {
200
184
  createMakeCursors,
201
185
  createResourceResolver,
202
186
  cursorCache,
203
- getters: (getters as unknown) as Getters,
204
- resolver: result => result,
187
+ getters,
205
188
  resultsPerPage,
206
189
  });
207
190
 
@@ -221,9 +204,9 @@ describe("connectionResolver", () => {
221
204
  const mock = jest.fn().mockImplementation(page => pageResponse(page));
222
205
 
223
206
  const createResourceResolver = (
224
- _obj: Record<string, any>,
225
- _args: Record<string, any>,
226
- _context: Record<string, any>,
207
+ _obj: PlainObject,
208
+ _args: PlainObject,
209
+ _context: PlainObject,
227
210
  _info: GraphQLResolveInfo,
228
211
  ) => async ({ page }: { page: number }) => mock(page);
229
212
 
@@ -236,8 +219,7 @@ describe("connectionResolver", () => {
236
219
  createMakeCursors,
237
220
  createResourceResolver,
238
221
  cursorCache,
239
- getters: (getters as unknown) as Getters,
240
- resolver: result => result,
222
+ getters,
241
223
  resultsPerPage,
242
224
  });
243
225
 
@@ -255,11 +237,7 @@ describe("connectionResolver", () => {
255
237
 
256
238
  describe("when the last [X] number are requested", () => {
257
239
  test("when there is a fresh cache and there are NO missing pages in the cache", async () => {
258
- const createResourceResolver = (
259
- _obj: Record<string, any>,
260
- args: Record<string, any>,
261
- { restClient }: Record<string, any>,
262
- ) => {
240
+ const createResourceResolver = (_obj: PlainObject, args: PlainObject, { restClient }: PlainObject) => {
263
241
  return async ({ page }: { page: number }) => restClient({ ...removeConnectionInputOptions(args), page });
264
242
  };
265
243
 
@@ -277,8 +255,7 @@ describe("connectionResolver", () => {
277
255
  createMakeCursors,
278
256
  createResourceResolver,
279
257
  cursorCache,
280
- getters: (getters as unknown) as Getters,
281
- resolver: result => result,
258
+ getters,
282
259
  resultsPerPage,
283
260
  });
284
261
 
@@ -296,9 +273,9 @@ describe("connectionResolver", () => {
296
273
  const mock = jest.fn().mockImplementation(page => pageResponse(page));
297
274
 
298
275
  const createResourceResolver = (
299
- _obj: Record<string, any>,
300
- _args: Record<string, any>,
301
- _context: Record<string, any>,
276
+ _obj: PlainObject,
277
+ _args: PlainObject,
278
+ _context: PlainObject,
302
279
  _info: GraphQLResolveInfo,
303
280
  ) => async ({ page }: { page: number }) => mock(page);
304
281
 
@@ -316,8 +293,7 @@ describe("connectionResolver", () => {
316
293
  createMakeCursors,
317
294
  createResourceResolver,
318
295
  cursorCache,
319
- getters: (getters as unknown) as Getters,
320
- resolver: result => result,
296
+ getters,
321
297
  resultsPerPage,
322
298
  });
323
299
 
@@ -337,9 +313,9 @@ describe("connectionResolver", () => {
337
313
  const mock = jest.fn().mockImplementation(page => pageResponse(page));
338
314
 
339
315
  const createResourceResolver = (
340
- _obj: Record<string, any>,
341
- _args: Record<string, any>,
342
- _context: Record<string, any>,
316
+ _obj: PlainObject,
317
+ _args: PlainObject,
318
+ _context: PlainObject,
343
319
  _info: GraphQLResolveInfo,
344
320
  ) => async ({ page }: { page: number }) => mock(page);
345
321
 
@@ -352,8 +328,7 @@ describe("connectionResolver", () => {
352
328
  createMakeCursors,
353
329
  createResourceResolver,
354
330
  cursorCache,
355
- getters: (getters as unknown) as Getters,
356
- resolver: result => result,
331
+ getters,
357
332
  resultsPerPage,
358
333
  });
359
334
 
package/src/main/index.ts CHANGED
@@ -1,21 +1,27 @@
1
1
  import { GraphQLResolveInfo } from "graphql";
2
- import { Connection, ConnectionAdapterUserOptions, ConnectionInputOptions } from "../defs";
2
+ import { Connection, ConnectionInputOptions, ConnectionResolverUserOptions, Node, PlainObject } from "../defs";
3
3
  import isCursorSupplied from "../helpers/isCursorSupplied";
4
4
  import requestAndCachePages from "../helpers/requestAndCachePages";
5
5
  import resolveConnection from "../helpers/resolveConnection";
6
6
  import validateCursor from "../helpers/validateCursor";
7
7
 
8
- export default ({
8
+ const main = <
9
+ Source extends PlainObject,
10
+ Args extends PlainObject,
11
+ Ctx extends PlainObject,
12
+ Resource extends PlainObject,
13
+ ResourceNode extends Node
14
+ >({
9
15
  cursorCache,
10
16
  createMakeCursors,
11
17
  createResourceResolver,
12
18
  getters,
13
- resolver,
19
+ resolver = result => result,
14
20
  resultsPerPage,
15
- }: ConnectionAdapterUserOptions) => async (
16
- source: Record<string, any>,
17
- args: Record<string, any> & ConnectionInputOptions,
18
- context: Record<string, any>,
21
+ }: ConnectionResolverUserOptions<Source, Args, Ctx, Resource, ResourceNode>) => async (
22
+ source: Source,
23
+ args: Args & ConnectionInputOptions,
24
+ context: Ctx,
19
25
  info: GraphQLResolveInfo,
20
26
  ): Promise<Connection> => {
21
27
  try {
@@ -68,7 +74,7 @@ export default ({
68
74
  );
69
75
  }
70
76
 
71
- await requestAndCachePages([1], {
77
+ await requestAndCachePages<Resource, ResourceNode>([1], {
72
78
  cursorCache,
73
79
  getters,
74
80
  groupCursor,
@@ -90,3 +96,5 @@ export default ({
90
96
  throw e;
91
97
  }
92
98
  };
99
+
100
+ export default main;