Commit 8f0fc3b
committed
Export getOffset, and give it a more descriptive name
In building a schema using `connectionFromArraySlice`, I've found it
useful to have access to functionality like `getOffset`. This commit
exposes it as an export, after changing the name to be more descriptive,
do further distinguish it from the existing `cursorToOffset`.
Here's an example of the function in use:
resolve: async (_, args) => {
const offset = getOffsetWithDefault(args.after, -1) + 1;
const [articles, totalCount] = await articleLoader.readIndex(
args.first, offset
);
return connectionFromPromisedArraySlice(
articleLoader.loadMany(articles),
args,
{
sliceStart: offset,
arrayLength: totalCount,
},
);
},
Without the function, I end up reimplementing equivalent logic, such as:
const after = args.after && cursorToOffset(args.after);
const offset = isNaN(after) ? 0 : after + 1;1 parent 70f20a3 commit 8f0fc3b
2 files changed
+7
-3
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
71 | 71 | | |
72 | 72 | | |
73 | 73 | | |
74 | | - | |
75 | | - | |
| 74 | + | |
| 75 | + | |
76 | 76 | | |
77 | 77 | | |
78 | 78 | | |
| |||
172 | 172 | | |
173 | 173 | | |
174 | 174 | | |
175 | | - | |
| 175 | + | |
| 176 | + | |
| 177 | + | |
| 178 | + | |
176 | 179 | | |
177 | 180 | | |
178 | 181 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
21 | 21 | | |
22 | 22 | | |
23 | 23 | | |
| 24 | + | |
24 | 25 | | |
25 | 26 | | |
26 | 27 | | |
| |||
0 commit comments