React-apollo: graphql is caching the variables when using object instead of function in options

Created on 5 Nov 2016  路  10Comments  路  Source: apollographql/react-apollo

Usually I have this type of code:

graphql(query, {
  options: ({ id }) => ({ variables: { id }, fragments }),
})

But since I don't need to pass any args explicitly, it could be write as:

graphql(query, {
  options: () => ({ fragments }),
})

Or:

graphql(query, {
  options: { fragments },
})

BUG: this third case, without a function, is using a cached variables. So, the first time a item is rendered, it runs correctly. But if I the navigate to another item, with different id, it uses the same old id of the first item.

ps1: I prefer to always explicitly pass the variables, but found this bug while prototyping.
ps2: v0.5.16

bug

Most helpful comment

Fixed in 1.0.0-rc.3 馃帀

All 10 comments

This sounds like a straight up bug!

Is there any progress on this?

Would love to see a reproduction of the problem (ideally as a failing test case).

@deoqc @drager I think this may have been solved with a recent fix in Apollo Client (not 100% sure though). Can one of you try it again?

@helfer: Sorry for the late answer... This is not fixed, tested with apollo-client 1.0.0-rc.2 and react-apollo 1.0.0-rc.2.

@drager could you create a reproduction with react-apollo-error-template? It will go a long way in helping us debug and solve your issue 馃槉

@calebmer: I will try to get a reproduction as soon as possible.

The same problem happened to me: specifying an empty options object already triggers this bug. I reproduced this at steventebrinke/react-apollo-error-template@e80ca5ed7a89cbed0b7d39f44d24ffb433f3e111.

Thanks for the reproduction @steventebrinke! This was a hard bug to track down, but I got it. Let me know if this fixes the error for you: https://github.com/apollographql/react-apollo/pull/537

Fixed in 1.0.0-rc.3 馃帀

Was this page helpful?
0 / 5 - 0 ratings