zino-hofmann / graphql-flutter

A GraphQL client for Flutter, bringing all the features from a modern GraphQL client to one easy to use package.
https://zino-hofmann.github.io/graphql-flutter
MIT License
3.25k stars 621 forks source link

fix: Cache-reboardcast error #1041

Closed budde377 closed 2 years ago

budde377 commented 2 years ago

With the introduction of parserFn we can annotate parsed type on the QueryResult. When rebroadcasting, the generic is lost which causes the error:

[VERBOSE-2:ui_dart_state.cc(209)] Unhandled Exception: type 'QueryResult<dynamic>' is not a subtype of type 'QueryResult<QueryFetchLibrary>' of 'result'
#0      ObservableQuery.addResult (package:graphql[/src/core/observable_query.dart]())
package:graphql/…/core/observable_query.dart:1
#1      QueryManager.maybeRebroadcastQueries
package:graphql/…/core/query_manager.dart:468
#2      ObservableQuery._maybeRebroadcast
package:graphql/…/core/observable_query.dart:94
#3      ObservableQuery._applyCallbacks
package:graphql/…/core/observable_query.dart:292
#4      ObservableQuery.addResult
package:graphql/…/core/observable_query.dart:264
#5      QueryManager.addQueryResult
package:graphql/…/core/query_manager.dart:402
#6      QueryManager._resolveQueryOnNetwork
package:graphql/…/core/query_manager.dart:276
<asynchronous suspension>

This means that cache updates won't propagate.

This PR refactors the code to preserve type information.

TODO

codecov[bot] commented 2 years ago

Codecov Report

Merging #1041 (5510511) into beta (bea716d) will increase coverage by 0.03%. The diff coverage is 65.00%.

Impacted file tree graph

@@            Coverage Diff             @@
##             beta    #1041      +/-   ##
==========================================
+ Coverage   53.93%   53.96%   +0.03%     
==========================================
  Files          40       41       +1     
  Lines        1511     1512       +1     
==========================================
+ Hits          815      816       +1     
  Misses        696      696              
Impacted Files Coverage Δ
packages/graphql/lib/src/utilities/response.dart 50.00% <50.00%> (ø)
...ackages/graphql/lib/src/core/observable_query.dart 41.73% <100.00%> (+1.40%) :arrow_up:
packages/graphql/lib/src/core/query_manager.dart 69.73% <100.00%> (+1.28%) :arrow_up:

Continue to review full report at Codecov.

Legend - Click here to learn more Δ = absolute <relative> (impact), ø = not affected, ? = missing data Powered by Codecov. Last update 2cd0727...5510511. Read the comment docs.

vincenzopalazzo commented 2 years ago

Let's add a test illustrating this.

Maybe we open an issue to remember it?