Apollo-client: `options. notifyOnNetworkStatusChange` judgement makes impossible to pass same options twice.

Created on 21 Jan 2018  ·  4Comments  ·  Source: apollographql/apollo-client

Intended outcome:

Don't throw error on passing same options twice.

Actual outcome:

options. notifyOnNetworkStatusChange is set to be false at first time, and will throw error at then second time.

How to reproduce the issue:

https://github.com/apollographql/apollo-client/blob/02770cafc8f541064a69c2f30049044e27036c4b/packages/apollo-client/src/core/QueryManager.ts#L658-L663

Check these codes, should we only check options.notifyOnNetworkStatusChange is true?

Version

For now, I can only new an options object every time temporarily.

Most helpful comment

@Poincare I'm not passing notifyOnNetworkStatusChange: false, it is set internally.

https://github.com/apollographql/apollo-client/blob/02770cafc8f541064a69c2f30049044e27036c4b/packages/apollo-client/src/core/QueryManager.ts#L663

I think we should only check whether options.notifyOnNetworkStatusChange is truthy.

All 4 comments

The point of that line is to make sure that the application developer doesn't pass a notifyOnNetworkStatusChange option to query. This is because query doesn't support this option because it doesn't watch the query for changes its result, as opposed to watchQuery which does watch the result.

In what situation do you have to pass a false for notifyOnNetworkStatusChange when calling query and then need to use that instance to change the option?

@Poincare I'm not passing notifyOnNetworkStatusChange: false, it is set internally.

https://github.com/apollographql/apollo-client/blob/02770cafc8f541064a69c2f30049044e27036c4b/packages/apollo-client/src/core/QueryManager.ts#L663

I think we should only check whether options.notifyOnNetworkStatusChange is truthy.

I think the !== undefined check is fine, I would prefer either doing an Object.assign as to not mutate the query options or remove the above mentioned line. I think removing the line is fine as the watchQuery does the same mutation.

https://github.com/apollographql/apollo-client/blob/0882a809dc7381c7e95a17696130796d661d6678/packages/apollo-client/src/core/QueryManager.ts#L646

That should probably be fixed as well.

This should no longer be an issue with current versions of apollo-client. Thanks!

Was this page helpful?
0 / 5 - 0 ratings