React-apollo: refetchQueries don't update components | bug

Created on 12 Oct 2016  Â·  16Comments  Â·  Source: apollographql/react-apollo

Steps to Reproduce

I have component with

@graphql(gql`
  query getViewer {
    viewer {
      id,
    }
  }
`, {
  props: ({ data: { loading, viewer, error } }) => ({ loading, viewer, error }),
})
export default class ViewerProvider extends Component {
  render() {
    const { children, loading, viewer, error } = this.props;
    console.log(loading, viewer, error);
    return children;
  }
}
  1. When user is not logged in - viewer is not defined. (I can see in the console that viewer is not defined)
  2. After login I am calling refetchQueries: ['getViewer']
  3. Query to server looks like this
query ___composed {
  ___getViewer___requestIndex_0___fieldIndex_0: viewer {
    id
    __typename
  }
}

and response looks like this:

{"data":{"___getViewer___requestIndex_0___fieldIndex_0":{"id":"1","__typename":"User"}}}

But my component is not updated. There is no info in the console.

Expected Behavior

Component will be updated properly with new data from server

Version

Most helpful comment

I'm having the same issues I think - refetchQueries only works sometimes not sure why. Been having a terrible time trying to make this work for a few days now.

so: "Looks like the problem is indeed in apollo client. Going to close this issue and try to fix there."

is there a link to the issue there?

All 16 comments

I have tried to turn off batching. But this issue is still here.

Query looks like this

{
operationName: "getViewer"
query: "query getViewer {↵  viewer {↵    id↵    __typename↵  }↵}↵"
variables: {}
}

and response is correct too but component has old data

Here is more info about this issue.
There is a problem only with components which are already mounted. If I am using new component this component will get correct data.

After debugging react-apollo I found that component is subscribed but there is no next call.
That means the problem is somewhere in the apollo-client.

Looks like the problem is indeed in apollo client. Going to close this issue and try to fix there.

Maybe it is a problem with react-apollo because component will stay in state loading === true forever.

The problematic line in react-apollo is https://github.com/apollostack/react-apollo/blob/master/src/graphql.tsx#L382

As you can see loading will be changed to value "true". But this function is called from componentWillReceiveProps and no from componentDidMount. Anyway after that loading value will be equals true forever.

Links to branches are not useful because branches move. pointing to a commit or tag is always better.
I have the same issue and I do not understand why unresolved issues is closed:

I see no commit related to this and the last thing was rather an "try to fix it" and since the link does not point to the correct location anymore I can not tell whether it was fixed. Is this is a different bug or regression, or there was no fix.

Any updates on this? Thanks! :)

@seeden @stubailo i have same problema, any solution?

It's ok, if use:
refetchQueries: [{ query: MyQuery }]

It's not update property loading and not update view:
refetchQueries: ['MyQuery']

I appear to be having this problem as well. Any known workarounds?

@marlonmleite where do you have the second variant from? I only know the first one from docs, so it would not surprise why the second variant you'v posted does not work.

I also did a mistake in my previous post here.

I read it like that:
"Looks like the problem is indeed in apollo client. Going to close this issue and try to fix here.

But its actually:
"Looks like the problem is indeed in apollo client. Going to close this issue and try to fix there."

That is why I was wondering - need some new glasses :D.

I'm having the same issues I think - refetchQueries only works sometimes not sure why. Been having a terrible time trying to make this work for a few days now.

so: "Looks like the problem is indeed in apollo client. Going to close this issue and try to fix there."

is there a link to the issue there?

Having the same problem
It's so weird cause sometimes it works perfectly but most of the times it doesn't
Is there any alternative to refetchQueries?

do you have everywhere id in your queries ( I mean in all sub fields)?
apollo-client have a lot of problems if field id is missing

@marlonmleite

It's not update property loading and not update view:
refetchQueries: ['MyQuery']

i have been using this varient of refetchQueries for sometime but now it does not work!

@akomm ,http://dev.apollodata.com/react/api-mutations.html#graphql-mutation-options-refetchQueries here is the documentation for that second variant of refetchQueies

Was this page helpful?
0 / 5 - 0 ratings