How to add additional fields to cache

Hi there! I’m building web3 project and retrieve all data from TheGraph protocol. The problem that I’m facing right now is with updating cache. I need to update field using cache.modify. I have to add additional fields though the fields parameter. Unfortunately when I add them received data from useQuery remains the same. How can I add additional data to these fields or it’s possible only to delete and update it. Thanks!

Hi @neulad, welcome to the community forum! When you say “additional fields” a few possibilities come to mind. Can you share some sample code or a codesandbox to help illustrate the issue you’re seeing? We have a boilerplate template if that helps:

Hi @JeffAuriemma! Thank you for your response. So by additional fields I meant using local-only fields. I have a Token entity that has a field called name. This field gets updated when I query IPFS and get name property of my token. However, every time I try to update this field using cache.modify or client.readFragment nothing happens and data remains the same, readFragment returns null. I get id using cache.identify and it returns correct value. On my query I use @client modifier to specify that the field is local. When I try to log inside the name method in fields field of parameters specified for cache.modify it doesn’t get logged. Here’s a reproduction: GitHub - neulad/local-field-issue-reproduction. Thanks in advance for help :slight_smile:

Hi @neulad, thanks for the sample code! I wasn’t able to run it (no package.json) but from inspecting the source code I suspect that the issue is related to this. Check out Ben’s response in that Issue. In short, I recommend using a different pattern for storing and modifying local state. It’s likely that a Reactive Variable suits your use case nicely.

Let me know if you need more support here!