-
Notifications
You must be signed in to change notification settings - Fork 787
After a query has resulted in an error, variable updates that should result in an Apollo QueryResult with no errors do not update the QueryResult's error field in componentWillReceiveProps #1749
Comments
Having the exact same problem, except i'm using the According to this PR in apollo-client, the issue should be resolved but i'm still getting the same error. These are the latest packages i'm using:
|
@benjaminsaurusrex Have you tried using https://www.apollographql.com/docs/react/features/error-handling.html#policies with an error policy to |
I recently ran into this (using |
Please consider submitting a PR with a unit test reproduction - that's the best way to get attention to this. |
This comment has been minimized.
This comment has been minimized.
Just created a PR with a test case. What I observed in my local tests was:
|
Tried out the errorPolicies:
So setting the policy to |
* Add test for Query bug which is caused by changing props (#1749) * Skip the failing test (#1749) * Enable failing test * Leverage lastResult to limit unnecessary subscription re-creation When the Observable subscription created in `startQuerySubcription` receives an error, we only want to remove the old subscription, and start a new subscription, when we don't have a previous result stored. So if no previous result was received due to problems fetching data, or the previous result has been forcefully cleared out for some reason, we shoule re-create a new subscription. Otherwise we might be unnecessarily starting a new subscription the `Query` component isn't expecting, and isn't tying into its update cycle properly. * Changelog update
This was fixed in #2718. Thanks! |
Actual Result
graphql
HOC, with a Query that produces an errorcomponentWillReceiveProps
, thenextProps.data.error
is still defined with the previous errorIntended Result
graphql
HOC, with a Query that produces an errornextProps.data.error
is no longer definedHow am I testing this?
Good question. I have a basic query that requests a field that always succeeds, and another field that fails when included:
Now for my components. I have 2 components, one that acts as a parent and determines whether its child
shouldFail
or not so that the child gets prop updates, which trigger a variable update when the operation options are different.With this set up, you can see how
Parent
can easily update its state, which causes Child'sshouldFail
prop to update, which causes the variable inside the operation options to update... and down the rabbit hole.The rabbit hole
When a GraphQL error comes through, the Observable decides to clean itself up.
https://github.com/zenparsing/zen-observable/blob/e924b1ddcde8aaac157cedb1908b2ad83b20e7bc/zen-observable.js#L184
Which removes it from
ObservableQuery
's list of observers (emptying it).https://github.com/apollographql/apollo-client/blob/2.0/packages/apollo-client/src/core/ObservableQuery.ts#L538
Then when the new query variables come in, it follows the path of:
GraphQL.componentWillReceiveProps
GraphQL.updateQuery
(https://github.com/apollographql/react-apollo/blob/apollo-client-2.0/src/graphql.tsx#L220)ObservableQuery.setOptions
(https://github.com/apollographql/react-apollo/blob/apollo-client-2.0/src/graphql.tsx#L391)ObservableQuery.setVariables
(https://github.com/apollographql/apollo-client/blob/2.0/packages/apollo-client/src/core/ObservableQuery.ts#L396)Which would normally end up doing the network request, but since earlier the observers list became empty, this ends up being a no-op.
https://github.com/apollographql/apollo-client/blob/2.0/packages/apollo-client/src/core/ObservableQuery.ts#L450
Then there's no recovery from react-apollo's perspective; when the
graphql
hoc callssubscribeToQuery
at the end ofcomponentWillReceiveProps
(after theGraphQL.updateQuery
above), that's a no-op because from its perspective it thinks it's still subscribed.https://github.com/apollographql/react-apollo/blob/apollo-client-2.0/src/graphql.tsx#L432
The above was found and documented after some minor digging to see why this was happening.
Repro Environment
I actually don't have an easily accessible repro environment with public data that can be used for this. Though it should be fairly straightforward to set up by following my components above.
Version
The text was updated successfully, but these errors were encountered: