urql-graphql / urql

The highly customizable and versatile GraphQL client with which you add on features like normalized caching as you grow.
https://urql.dev/goto/docs
MIT License
8.54k stars 444 forks source link

fix(graphcache): incorrectly matching all concrete types #3603

Closed JoviDeCroock closed 3 weeks ago

JoviDeCroock commented 4 weeks ago

Resolves #3600

Summary

Currently we are holding a mapping of abstract --> concrete types, however when we are in a write operation we always say the fragment matches. This meant that in the union case we would often write concrete type maps to another concrete type. This is invalid, I changed the condition to check whether the fragment actually matches before writing an abstract to concrete type mapping. This however begs the question whether this functionality is worth keeping around because a heuristic match could still make us fall into the concrete to concrete mapping which could in turn cause unexpected behaviour in later queries.

This also adds a check to see whether we have accidentally persisted a concrete type in the past due to i.e. multiple matching selection-sets. This ensures that we can't confuse types.

In the test case this would result in us writing

Type1 maps to Type2 and hence any subsequent read would result in a fragment match for both and hence resulting in null as we would think some scalar values are undefined.

changeset-bot[bot] commented 4 weeks ago

🦋 Changeset detected

Latest commit: e1ad44d746deeeecd6bfc57054eddcf50d1e95f3

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package | Name | Type | | ------------------------- | ----- | | @urql/exchange-graphcache | Patch |

Not sure what this means? Click here to learn what changesets are.

Click here if you're a maintainer who wants to add another changeset to this PR