V3 InMemoryCache: Object Fieldname Characters too Restrictive
See original GitHub issueI have a nested object that uses Guids as the fieldname:
var user = {
id: '1',
nestedObject: {
'd7eb901a-cc21-4f8f-93f4-0408406e6a00': 'some value'
}
}
I use cache.writeData to update the nestedObject:
cache.writeData({
id: defaultDataIdFromObject(user)
data: {
nestedObject: {
'd7eb901a-cc21-4f8f-93f4-0408406e6a00': 'a different value'
}
},
});
Intended outcome: I am expecting the imMemoryCache to update the User to the following value:
{
id: '1',
nestedObject: {
'd7eb901a-cc21-4f8f-93f4-0408406e6a00': 'a different value'
}
}
Actual outcome: In actuality, the keys for the nested object get messed up (seem to get doubled):
{
id: '1',
nestedObject: {
'd7eb901a-cc21-4f8f-93f4-0408406e6a00-d7eb901a-cc21-4f8f-93f4-0408406e6a00': 'a different value'
}
}
How to reproduce the issue: Follow steps above to reproduce
Notes
- This is possible due to the limited characters in the FieldNamePattern variable in cache/inMemory/helpers.ts
- There are a lot more valid JSON key characters that are missing. However, the hyphen was the only one I was running into in this example
- Feature Request Sidenote: The ability to pass in a custom merge algorithm could be useful
- Possible Bug sidenote: Due to the merge algorithm, it seems like it is not possible to reset a field back to undefined. Is this correct, or intended behaviour? And, if intended, is there a way to set a field back to undefined in cache?
Versions System: OS: macOS 10.15.2 Binaries: Node: 12.12.0 - /usr/local/bin/node Yarn: 1.19.1 - /usr/local/bin/yarn npm: 6.9.0 - /usr/local/bin/npm Browsers: Chrome: 79.0.3945.88 Safari: 13.0.4 npmPackages: @apollo/client: ^3.0.0-beta.10 => 3.0.0-beta.16 @apollo/react-hooks: ^3.2.0-beta.0 => 3.2.0-beta.0 apollo-link-debounce: ^2.1.0 => 2.1.0
Issue Analytics
- State:
- Created 4 years ago
- Comments:13 (8 by maintainers)
Top Results From Across the Web
Configuring the Apollo Client cache - Apollo GraphQL Docs
Create an InMemoryCache object and provide it to the ApolloClient constructor, ... import { InMemoryCache, ApolloClient } from '@apollo/client';. 2. 3.
Read more >Index name, type name and field name rules - Elastic Discuss
I am using ES 6. What are exact rules regarding formation of index name, type name and field name strings.. I know ES...
Read more >Customizing the behavior of cached fields - Client (React)
You can customize how a particular field in your Apollo Client cache is read and written. To do so, you define a field...
Read more >Editing field names and descriptions - Amazon QuickSight
To change a field name or description. In the Fields pane of the data prep page, choose the three-dot icon on the field...
Read more >Configuring the Cache – Angular - GraphQL Code Generator
As of Apollo Client 3.0, the InMemoryCache class is provided by the @apollo/client ... Create an InMemoryCache object and provide it to the ......
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
@hwillson - yes, thanks, these are all resolved for me now as of v3.0.0-beta.24
@ahrnee I think all of these problems can be solved by making the
evict
method more powerful: https://github.com/apollographql/apollo-client/pull/5773