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.

How to configure cache for Viewer Type in 3.0?

See original GitHub issue

As of 3.0, the Viewer type in our schema throws the Cache data may be lost... warning in the console because it does not have an id field, And I’m just not sure the best way to address it. I’m trying to determine the ideal solution here (other than removing the viewer type entirely).

If I write a custom merge function on Viewer it would need need to be written for each field individually, which seems like a bad idea.

I tried writing a custom merge on Query but that didn’t seem to work:

    new InMemoryCache({
      typePolicies: {
        Query: {
          fields: {
            viewer: {
              merge(existing, incoming) {
                return { ...existing, ...incoming };
              },
            },
          },
        },
      },
    });

If I utilize possibleTypes and map Viewer to the types of its fields (eg User Product AccountType), it doesn’t seem to fix the issue. Do I need to remove references to the viewer in my queries to allow this to work?

The only other option I can think of is adding id to Viewer, but trying to avoid that if I can.

Any input is appreciated!

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
benjamncommented, Jul 22, 2020

Ok, since it sounds like Viewer is a singleton, you can give it a constant ID (without having to invent a real identity):

new InMemoryCache({
  typePolicies: {
    Viewer: {
      // This means the singleton Viewer's identity does not depend on any of its
      // fields (except for __typename), making the ID effectively constant.
      keyFields: [],
    },
  },
})

Alternatively, the following tweak to the merge function might make a difference, since it will do a better job of merging sub-fields that have their own merge functions:

merge(existing, incoming, { mergeObjects }) {
  return mergeObjects(existing, incoming);
}

I’ll leave this issue open in case those solutions don’t work, or you have any other questions.

0reactions
hwillsoncommented, May 4, 2021

It doesn’t sound like there is an outstanding issue here, so closing. Thanks!

Read more comments on GitHub >

github_iconTop Results From Across the Web

Configuring the Apollo Client cache - Apollo GraphQL Docs
You can configure the cache's behavior to better suit your application. For example, you can: Customize the format of a particular type's cache...
Read more >
Configuring the Cache of a View - Community | Denodo
To enable the cache of a view, open the view, click Options and select one of the following cache modes: Partial. When a...
Read more >
K60520554: Caches | BIG-IP TMOS operations guide - AskF5
You can also change the size of a DNS cache to fix cache performance issues. Go to DNS > Caches > Cache List....
Read more >
3 Changing Configuration Settings - Oracle Help Center
The Imaging viewer can cache documents on the server outside of the repository to allow more efficient rendering of the documents before they...
Read more >
Available map and image cache properties - ArcGIS Enterprise
Be sure to give the ArcGIS Server account write access to the server cache directory so that the server can successfully place 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