#292062 follow-up
This follows-up on this master:broken issue: #292062 (closed)
What happened
Two MRs got merged consecutively:
-
!48705 (merged) introduced a
@connection
directive in a GraphQL query because some paginated data had to be optimistically updated. The directive allowed the data to be stored in Apollo's cache with a static key, making it easier to read/write the cached query. More on this here: https://www.apollographql.com/docs/react/v2/caching/cache-interaction/#the-connection-directive -
!48940 (merged) introduced a test where the above query was being mocked via
mock-apollo-client
, which is what actually brokemaster
.
Why?
What exactly happened is similar to what's described in this apollo-client
issue: https://github.com/apollographql/apollo-client/issues/2518
When it encounters a @connection
directive, apollo-client
strips it out of the cache key when caching the data.
The thing is that mock-apollo-client
uses apollo-client
's actual cache layer, but it provides its own mocked link, with its own way of building cache keys that does not strip the @connection
directive.
This results in a discrepancy between mocked request handlers and what's actually in the cache, as any query containing a @connection
query can not be traced back to the cache.
So, when mocking apollo-client
in tests, queries containing a @connection
directive would always be considered not mocked and would never resolve properly.
How do we fix this?
-
Revert the changes that caused the failure. - The failure was initially reported in #292062 (closed).
- !48940 (merged) was identified as the culprit and got reverted in !49401 (merged)
-
Contribute a fix to the upstream project. - A fix has been submitted to the upstream project: https://github.com/Mike-Gibson/mock-apollo-client/pull/20
- It got merged and released in
mock-apollo-client@0.5.0
: https://github.com/Mike-Gibson/mock-apollo-client/releases/tag/v0.5.0
-
Once the fix is merged and released, upgrade the package in GitLab. - Upgrade MR: !49467 (merged)
-
Reintroduce the changes that caused the failures. - MR: !49435 (merged)
-
Document the @connection
key in GitLab's development docs.- Documentation MR: !49471 (merged)