Skip to content

Commit

Permalink
Revert "Stop treating dangling references differently from empty obje…
Browse files Browse the repository at this point in the history
…cts" (#6371)

This reverts commit c810713, introduced
recently in PR #6365. My optimism that #6365 was an improvement seems to
have been misplaced, since it caused the regression reported in #6368.
We're too close to the AC3 RC/release to be floating risky changes like
these without compelling justifications.
  • Loading branch information
benjamn authored Jun 1, 2020
1 parent 518660b commit 5e74226
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 7 deletions.
8 changes: 4 additions & 4 deletions src/cache/inmemory/__tests__/entityStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1555,11 +1555,11 @@ describe('EntityStore', () => {

expect(() => cache.readQuery({
query: queryWithAliases,
})).toThrow(/Can't find field 'a' on ABCs:.* object/);
})).toThrow(/Dangling reference to missing ABCs:.* object/);

expect(() => cache.readQuery({
query: queryWithoutAliases,
})).toThrow(/Can't find field 'a' on ABCs:.* object/);
})).toThrow(/Dangling reference to missing ABCs:.* object/);
});

it("gracefully handles eviction amid optimistic updates", () => {
Expand Down Expand Up @@ -1639,8 +1639,8 @@ describe('EntityStore', () => {

const missing = [
new MissingFieldError(
"Can't find field 'name' on Author:2 object",
["book", "author", "name"],
"Dangling reference to missing Author:2 object",
["book", "author"],
expect.anything(),
expect.anything(),
),
Expand Down
6 changes: 3 additions & 3 deletions src/cache/inmemory/__tests__/policies.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2397,7 +2397,7 @@ describe("type policies", function () {
});

expect(read).toThrow(
/Can't find field 'title' on Book:{"isbn":"156858217X"} object/
/Dangling reference to missing Book:{"isbn":"156858217X"} object/
);

const stealThisData = {
Expand Down Expand Up @@ -2529,11 +2529,11 @@ describe("type policies", function () {
});

expect(() => read("0393354326")).toThrow(
/Can't find field 'title' on Book:{"isbn":"0393354326"} object/
/Dangling reference to missing Book:{"isbn":"0393354326"} object/
);

expect(() => read("156858217X")).toThrow(
/Can't find field 'title' on Book:{"isbn":"156858217X"} object/
/Dangling reference to missing Book:{"isbn":"156858217X"} object/
);
});

Expand Down
14 changes: 14 additions & 0 deletions src/cache/inmemory/readFromStore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,6 +213,20 @@ export class StoreReader {
objectOrReference,
context,
}: ExecSelectionSetOptions): ExecResult {
if (isReference(objectOrReference) &&
!context.policies.rootTypenamesById[objectOrReference.__ref] &&
!context.store.has(objectOrReference.__ref)) {
return {
result: {},
missing: [missingFromInvariant(
new InvariantError(
`Dangling reference to missing ${objectOrReference.__ref} object`
),
context,
)],
};
}

const { fragmentMap, variables, policies, store } = context;
const objectsToMerge: { [key: string]: any }[] = [];
const finalResult: ExecResult = { result: null };
Expand Down

0 comments on commit 5e74226

Please sign in to comment.