Skip to content

Commit

Permalink
fix: useCache() with indexes but no entities ever stored (#279)
Browse files Browse the repository at this point in the history
  • Loading branch information
ntucker committed Mar 1, 2020
1 parent af77661 commit 67a1257
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
Expand Up @@ -148,4 +148,19 @@ describe('buildInferredResults()', () => {
data: undefined,
});
});

it('should work with indexes but no indexes stored', () => {
const schema = {
pagination: { next: '', previous: '' },
data: IndexedUserResource.asSchema(),
};
expect(buildInferredResults(schema, { username: 'bob' }, {})).toEqual({
pagination: { next: '', previous: '' },
data: undefined,
});
expect(buildInferredResults(schema, { hover: 'bob' }, {})).toEqual({
pagination: { next: '', previous: '' },
data: undefined,
});
});
});
Expand Up @@ -24,7 +24,7 @@ export default function buildInferredResults<
if (id !== undefined && id !== '') return id as any;
// now attempt lookup in indexes
const indexName = indexFromParams(params, schema.indexes);
if (indexName) {
if (indexName && indexes[schema.key]) {
// 'as Record<string, any>': indexName can only be found if params is a string key'd object
return indexes[schema.key][indexName][
(params as Record<string, any>)[indexName]
Expand Down

0 comments on commit 67a1257

Please sign in to comment.