question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

V3 InMemoryCache: Object Fieldname Characters too Restrictive

See original GitHub issue

I 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:closed
  • Created 4 years ago
  • Comments:13 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
jamshallycommented, Jan 21, 2020

@hwillson - yes, thanks, these are all resolved for me now as of v3.0.0-beta.24

1reaction
benjamncommented, Jan 10, 2020

@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

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found