-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(apollo-cache-inmemory): track typename in IdValue and replace und…
…erlying objects when it changes (#3159) * fix(apollo-cache-inmemory): track typename in field id values and allow missing id when it changes There is an edge case bug with types that are of a Union type of: `{ id, __typename: 'First' }` and `{ __typename: 'Second' }` (without the `id` field). In such a case, if we first retrieve a result with `First` and then re-query when the response contains the other type (`Second`), Apollo would throw an error that the field is now missing an `id`, which was previously present. This would be correct if the object was of the same type, however we cannot know whether another type (`Second`) even contains an `id` field in the schema in the first place (here, it didn't). This commit adds support for tracking typenames to the `IdValue` and should such a case occur, it fully replaces fields with autogenerated names in case their underlying types have changed, after being re-queried. * chore(tests): add typenames to IdValues created in tests * chore(tests): use snapshots to simplify testing changes to the Cache implementation * doc(apollo-cache-inmemory): add CHANGELOG entry * refactor(apollo-cache-inmemory): try to address benchmark drop * doc(apollo-cache-inmemory): add contributor * chore(apollo-utilities): add a warning about toIdValue signature change * chore(apollo-utilities): update flow typings * chore(apollo-utilities): update flow typings * Update package.json * refactor(apollo-utilities): change toIdValue helper signature to remove breaking change
- Loading branch information
Showing
18 changed files
with
1,063 additions
and
597 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
135 changes: 135 additions & 0 deletions
135
packages/apollo-cache-inmemory/src/__tests__/__snapshots__/cache.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,135 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[ | ||
`Cache writeFragment will write some deeply nested data into the store at any id 1` | ||
] = ` | ||
Object { | ||
"bar": Object { | ||
"i": 7, | ||
}, | ||
"foo": Object { | ||
"e": 4, | ||
"h": Object { | ||
"generated": false, | ||
"id": "bar", | ||
"type": "id", | ||
"typename": undefined, | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[ | ||
`Cache writeFragment will write some deeply nested data into the store at any id 2` | ||
] = ` | ||
Object { | ||
"bar": Object { | ||
"i": 7, | ||
"j": 8, | ||
"k": 9, | ||
}, | ||
"foo": Object { | ||
"e": 4, | ||
"f": 5, | ||
"g": 6, | ||
"h": Object { | ||
"generated": false, | ||
"id": "bar", | ||
"type": "id", | ||
"typename": undefined, | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[ | ||
`Cache writeFragment will write some deeply nested data into the store at any id 3` | ||
] = ` | ||
Object { | ||
"bar": Object { | ||
"i": 10, | ||
"j": 8, | ||
"k": 9, | ||
}, | ||
"foo": Object { | ||
"e": 4, | ||
"f": 5, | ||
"g": 6, | ||
"h": Object { | ||
"generated": false, | ||
"id": "bar", | ||
"type": "id", | ||
"typename": undefined, | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[ | ||
`Cache writeFragment will write some deeply nested data into the store at any id 4` | ||
] = ` | ||
Object { | ||
"bar": Object { | ||
"i": 10, | ||
"j": 11, | ||
"k": 12, | ||
}, | ||
"foo": Object { | ||
"e": 4, | ||
"f": 5, | ||
"g": 6, | ||
"h": Object { | ||
"generated": false, | ||
"id": "bar", | ||
"type": "id", | ||
"typename": undefined, | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[ | ||
`Cache writeFragment will write some deeply nested data into the store at any id 5` | ||
] = ` | ||
Object { | ||
"bar": Object { | ||
"i": 7, | ||
"j": 8, | ||
"k": 9, | ||
}, | ||
"foo": Object { | ||
"e": 4, | ||
"f": 5, | ||
"g": 6, | ||
"h": Object { | ||
"generated": false, | ||
"id": "bar", | ||
"type": "id", | ||
"typename": "Bar", | ||
}, | ||
}, | ||
} | ||
`; | ||
|
||
exports[ | ||
`Cache writeFragment will write some deeply nested data into the store at any id 6` | ||
] = ` | ||
Object { | ||
"bar": Object { | ||
"i": 10, | ||
"j": 11, | ||
"k": 12, | ||
}, | ||
"foo": Object { | ||
"e": 4, | ||
"f": 5, | ||
"g": 6, | ||
"h": Object { | ||
"generated": false, | ||
"id": "bar", | ||
"type": "id", | ||
"typename": "Bar", | ||
}, | ||
}, | ||
} | ||
`; |
134 changes: 134 additions & 0 deletions
134
packages/apollo-cache-inmemory/src/__tests__/__snapshots__/mapCache.ts.snap
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.