Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions __tests__/runtimeHelpers.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import { unPartitionResults } from '../src/runtimeHelpers';

describe('unPartitionResults', () => {
it('should perform inverse mapping for result without Error', () => {
expect(unPartitionResults([[0, 2], [1]], [[{ foo: 'foo' }, { bar: 'bar' }], [{ baz: 'baz' }]])).toEqual([
{ foo: 'foo' },
{ baz: 'baz' },
{ bar: 'bar' },
]);
});

it('should perform inverse mapping for result with some Error in resultGroups', () => {
const customError = new Error('bar error');
expect(unPartitionResults([[0, 2], [1]], [[{ foo: 'foo' }, customError], [{ baz: 'baz' }]])).toEqual([
{ foo: 'foo' },
{ baz: 'baz' },
customError,
]);
});

it('should perform inverse mapping for result with all Error in one resultGroup', () => {
const customError = new Error('foo error');
expect(unPartitionResults([[0, 2], [1]], [[customError, customError], [{ baz: 'baz' }]])).toEqual([
customError,
{ baz: 'baz' },
customError,
]);
});
});
5 changes: 5 additions & 0 deletions src/implementation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -249,6 +249,11 @@ function getBatchLoader(resourceConfig: BatchResourceConfig, resourcePath: Reado
)} Resource returned \${response.length} items, but we requested \${requests.length} items.\`,
'Add reorderResultsByKey to the config for this resource to be able to handle a partial response.',
].join(' '));

// Tell flow that BatchItemNotFoundError extends Error.
// It's an issue with flowgen package, but not an issue with Flow.
// @see https://github.com/Yelp/dataloader-codegen/pull/35#discussion_r394777533
invariant(response instanceof Error, 'expected BatchItemNotFoundError to be an Error');
}
}
`;
Expand Down