Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

writeQuery somehow breaks startPolling #10614

Open
NeverwinterMoon opened this issue Feb 27, 2023 · 1 comment
Open

writeQuery somehow breaks startPolling #10614

NeverwinterMoon opened this issue Feb 27, 2023 · 1 comment

Comments

@NeverwinterMoon
Copy link

NeverwinterMoon commented Feb 27, 2023

Issue Description

startPolling updates cache and UI only once after using writeQuery. After that, even if totally fresh data is incoming, cache is not touched at all, UI is never updated.

Apollo Client version 3.7.9.

Link to Reproduction

Described in reproduction steps

Reproduction Steps

export const QUERY = gql`
  someThing(id: $id) {
    __typename
    id
    state {
      __typename
      someNumber
    }
  }
`
const client = useApolloClient()

const {
    loading,
    data: { someThing } = {},
    error,
    startPolling,
    stopPolling
  } = useQuery(QUERY, {
    variables: {
      id: id
    }
  })
// Button 1
<Button onClick={() => {
client.writeQuery({
  query:     QUERY,
  data:      {
    someThing: {
      __typename: 'SomeThing',
      id: id,
      state: {
        __typename: 'SomeState',
        someNumber: 1
      }
    }
  },
  variables: {
    id: id
  }
})
}} />
// Button 2
<Button onClick={() => {
client.writeQuery({
  query:     QUERY,
  data:      {
    someThing: {
      __typename: 'SomeThing',
      id: id,
      state: {
        __typename: 'SomeState',
        someNumber: 2
      }
    }
  },
  variables: {
    id: id
  }
})
}} />
// Button 3
<Button onClick={() => {
startPolling(2000)
}} />

When the view loads, it calls the query for the first time. All data loads fine.

If I press Button 1 to write query, cache is updated fine, UI is refreshed fine.

If I press Button 2 to write query, cache is updated fine, UI is refreshed fine.

I can click Button 1 and Button 2 as many time as I want and the cache and UI are both updated all the time.

If I press Button 3 to start polling, it updates cache and UI, then I press either Button 1 or Button 2, this updates cache and UI, the polling continues but it updates nothing after that - neither cache nor UI. Note that the call to server always returns random state.someNumber, so the data is always new.

I can reproduce the above all the time. So, steps are:

  • Load query on view load
  • Write to cache with writeQuery
  • Start polling
  • Polling updates cache and UI
  • Write to cache with writeQuery again
  • Polling does not update anything (I can see from network that requests are done and data has a new value every time)

I also have basic InMemoryCache for logging. Otherwise, the logic is just using mergeObjects, but it doesn't matter - as it's called only once (first poll result after writeQuery, after that it doesn't even call it).

What works:

  • Load query on view load
  • Start polling
  • Polling updates cache and UI
  • Polling keeps updating cache and UI, as data is always different

Basically, without using writeQuery, polling works as expected.

@jerelmiller jerelmiller added 🔍 investigate Investigate further 🏓 awaiting-team-response requires input from the apollo team labels Mar 2, 2023
@bignimbus bignimbus added 🛫 in-progress and removed 🏓 awaiting-team-response requires input from the apollo team 🔍 investigate Investigate further labels Mar 13, 2023
@bignimbus
Copy link
Contributor

Hi @NeverwinterMoon 👋🏻 thanks for opening this issue! @phryneas is working on a branch that may address this issue. Thanks for your patience while we prove this out 🙏🏻

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants