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.

Query doesn't update when data changes

See original GitHub issue

Context:

Hi, one of my endpoints is very slow; so I made the relevant resolver return early; on the client I poll for a subset of the data which I know will soon change.

const INSTANCE_LIST = gql`
  query {
    viewer {
      id
      instances {
        id
        createdAt
        instanceType
        prettyName
        hashCode
        url
        color
        primaryStorageSize
        startupStage
        startupDnsComplete
      }
    }
  }
`

const STARTUP_STAGE_ONLY = gql`
  query {
    viewer {
      instances {
        id
        startupStage
        startupDnsComplete
      }
    }
  }
`

const InstanceList = () => (
  <Query query={INSTANCE_LIST}>
    {({data, refetch}) => {
      const instances = data?.viewer?.instances || []
      const inFlux = instances.some(i => {
        return i.startupStage !== 'done' || !i.startupDnsComplete
      })

      return (
        <>
          {inFlux && (
            <Query query={STARTUP_STAGE_ONLY} pollInterval={1500}>
              {() => null}
            </Query>
          )}
          {instances
            .slice()
            .sort((a, b) => new Date(b.createdAt) - new Date(a.createdAt))
            .map((instance, index) => (
              <OneInstance
                key={instance.id}
                instance={instance}
                index={index}
              />
            ))}
        </>
      )
    }}
  </Query>
)

Intended outcome:

When the data changes, the parent <Query /> component will re-render and have up-to-date information.

Actual outcome:

Although the client cache updates, the parent <Query /> component keeps rendering stale data, even after remounting.

How to reproduce the issue:

It’ll take me a little time to put an example together, which I can do. But it’d be great to know if this is already a known issue before investing the time.

Versions

  System:
    OS: Linux 4.15 Ubuntu 16.04.4 LTS (Xenial Xerus)
  Binaries:
    Node: 10.1.0 - ~/.nvm/versions/node/v10.1.0/bin/node
    npm: 6.1.0 - ~/.nvm/versions/node/v10.1.0/bin/npm
  Browsers:
    Chrome: 67.0.3396.99
    Firefox: 61.0.1
  npmPackages:
    apollo-server: 2.0.0-rc.10 => 2.0.0-rc.10 
    apollo-server-express: 2.0.0-rc.10 => 2.0.0-rc.10

Issue Analytics

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

github_iconTop GitHub Comments

6reactions
ashtonsixcommented, Jul 27, 2018

Woah, named queries and devtools? You’re blowing my mind with this whole new world of stuff I didn’t know about. 😍

The devtools were reporting “There is a network error: {“type”:“WriteError”}”, but without any details. The error seemed to come from here, so I opened up the file inside node_modules, added a console.log and tried again. Here’s the error I got:

screenshot of error

With this guidance I realised id was missing from the selection set for viewer, added it & the issue was resolved!

The problem then, is this error wasn’t very visible; and once found, there weren’t enough details to help diagnose the issue without editing node_modules. The error was essentially silent.

2reactions
corysimmonscommented, May 15, 2019
const STARTUP_STAGE_ONLY = gql`
  query {
    viewer {
      instances {
        id
        startupStage
        startupDnsComplete
      }
    }
  }
`

Try adding an id to viewer so Apollo can differentiate viewers that are in the store? This worked for me anyway.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Access Update query doesn't update the data - Stack Overflow
In a quick test, the access query designer for a non-passthrough update query generated. UPDATE dbo_Available SET dbo_Available.
Read more >
Excel: Queries and Connections: Data does not update after
Hey, I have a problem with a data querie/ connection in Excel not refreshing (not updating the values), even though it says it...
Read more >
sql server - UPDATE performance where no data changes
The method shown in that answer doesn't filter out rows that exist yet do not need to be updated. That portion could be...
Read more >
Solved: Power Query Data is updating in PQ Editor, but not...
Solved: I have a Power Query through Excel. I haven't change anything to this file, except the same data source was updated with...
Read more >
Excel Pivot Table Refresh Steps and Fixes - Contextures
When you change the information in a pivot table's source data, the pivot table doesn't automatically show the latest information.
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