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

Loading query overwrites updateQueries response #1223

Closed
rafgraph opened this issue Jan 23, 2017 · 3 comments
Closed

Loading query overwrites updateQueries response #1223

rafgraph opened this issue Jan 23, 2017 · 3 comments

Comments

@rafgraph
Copy link

rafgraph commented Jan 23, 2017

I have a login mutation with an updateQueries option that updates my current user query.

  query currentUser {
    viewer {
      user {
        id
        username
      }
    }
  }

This works fine in isolation, the currentUser query is updated with the user id and username and my User React component gets the new current user data exactly as is should. However, when I have a current user, my User component renders a UserInfo component which has a currentUserInfo query.

query currentUserInfo($orderBy: [UserInfoOrderByArgs]) {
    viewer {
      user {
        id
        info(orderBy: $orderBy) {
          edges {
            node {
              id
              title
              ...
            }
          }
        }
      }
    }
  }

When this query runs it first has data.loading: true, as it should, but it also updates the result of the currentUser query so the user is null (note that loading for the currentUser query is false, so it's saying it's finished loading and has a null user), which gets passed into my User component and causes problems.

Note that this is all happening synchronously: login mutation result updates currentUser query with logged in user > User component gets new current user data and renders the UserInfo component > UserInfo component runs currentUserInfo query > currentUser query is updated with user as null > User component gets new current user data with null user > User component un-mounts UserInfo component.

If I change it so the UseInfo component is rendered asynchronously (with a setTimeout of 0), everything works as it should and currentUser is not updated with user as null.

Also, if the currentUser query is first run because the User component is rendered (and there is a current user, say on a page reload), then the synchronous process works fine. It's only when it starts with updateQueries from the login mutation that the issue arises.

Note that both User and UserInfo have respective UserWithData and UserInfoWithData containers that I didn't explicitly name above.

Using apollo-client 0.8.0 and react-apollo 0.8.3.

@BlooJeans
Copy link
Contributor

Not sure if this is the exact same issue, but your experience sounds similar to my current problem, but I'm using refetchQueries instead of updateQueries

navigate to EventOverview (fetch event)
navigate to EventDetails (fetch event with different properties)
saveEvent mutation (with refetchQueries: [EventOverviewQuery])
APOLLO_MUTATION_INIT
APOLLO_MUTATION_RESULT -> (properly returns edited event)
APOLLO_QUERY_INIT for EventOverviewQuery
APOLLO_QUERY_RESULT for EventOverviewQuery -> (properly returns event for Overview)
APOLLO_QUERY_STOP for EventOverviewQuery (what's causing this?)
event is now null for EventOverview

@helfer
Copy link
Contributor

helfer commented Jan 24, 2017

@RAFREX Thanks for the detailed writeup. That sounds like a tricky issue, but very reproducible. Do you think you could write a failing test case? I think a good place to put it would be this file.

@BlooJeans I think refetch always fires these three events: INIT, RESULT and STOP, so that is not surprising per se.

@helfer
Copy link
Contributor

helfer commented May 3, 2017

Closing for lack of activity. If this is still a problem, please open a new issue.

@helfer helfer closed this as completed May 3, 2017
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Feb 17, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants