Skip to content

Commit

Permalink
Improve error message when computeKeyFieldsObject throws.
Browse files Browse the repository at this point in the history
  • Loading branch information
benjamn committed Aug 25, 2021
1 parent 751802a commit e1b737f
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 3 deletions.
4 changes: 3 additions & 1 deletion src/cache/inmemory/__tests__/entityStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1779,7 +1779,9 @@ describe('EntityStore', () => {
expect(cache.identify(ABCs)).toBeUndefined();
expect(consoleWarnSpy).toHaveBeenCalledTimes(1);
expect(consoleWarnSpy).toHaveBeenCalledWith(
new Error("Missing field 'b' while computing key fields")
new Error(`Missing field 'b' while extracting keyFields from ${
JSON.stringify(ABCs)
}`),
);
} finally {
consoleWarnSpy.mockRestore();
Expand Down
6 changes: 5 additions & 1 deletion src/cache/inmemory/__tests__/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,11 @@ describe("type policies", function () {
book: theInformationBookData,
},
});
}).toThrowError("Missing field 'year' while computing key fields");
}).toThrowError(
`Missing field 'year' while extracting keyFields from ${JSON.stringify(
theInformationBookData
)}`,
);
});

it("does not clobber previous keyFields with undefined", function () {
Expand Down
4 changes: 3 additions & 1 deletion src/cache/inmemory/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1103,7 +1103,9 @@ function computeKeyFieldsObject(
const responseKey = aliases && aliases[s] || s;
invariant(
hasOwn.call(response, responseKey),
`Missing field '${responseKey}' while computing key fields`,
`Missing field '${responseKey}' while extracting keyFields from ${
JSON.stringify(response)
}`,
);
keyObj[lastActualKey = s] = response[lastResponseKey = responseKey];
}
Expand Down

0 comments on commit e1b737f

Please sign in to comment.