Open MarcusRiemer opened 3 years ago
I now also tried adding addTypename: true
to my specs (as hinted by the testing documentation):
{
provide: APOLLO_TESTING_CACHE,
useValue: {
addTypename: true,
},
},
This leads to runtime-errors in the form of this._apollo.client.cache.readQuery is not a function
which makes me believe that the documentation is incorrect and actually expects a "normal" cache instance and not a configuration object?
My real issue seems to be elsewhere, but when looking at the code the documentation mentioned above seems to be wrong indeed: https://github.com/kamilkisiela/apollo-angular/blob/880a7a092d478cc8352059829dde5c5126ab4dbf/packages/apollo-angular/testing/src/module.ts#L55-L66
Describe the bug
I am effectively trying to call
cache.writeQuery
andcache.readQuery
as part of an Angular Spec file. The item is always written to the cache (I have log messages that at least indicate so), but for whatever reason reading it back doesn't work at all.To Reproduce
The following code is ripped out of my application as condensed version and is also available as a Jasmine-Test on StackBlitz that immediatly shows the error and the log output.
The first log entry strongly indicates that the item is indeed added to the cache and well formed:
And if I dig into the private state of the cache, I can find the entry there as well:
Nevertheless the spec (and therefore the cache read) fails with
res
being undefined instead of properly mirroringDEFAULT_EMPTY_BLOCKLANGUAGE
.Expected behavior
I would expect that the item is retrieved from the cache and therefore the test passes.
Environment:
@apollo/client
: 3.3.11apollo-angular
: 2.4.0graphql
: 15.5.0@angular/core
: 11.2.5@angular/cli
: 11.2.4typescript
: 4.1.3Additional context
I also asked this over on StackOverflow but I didn't get a response yet. The more I am digging around this the more I am suspecting I might be hitting a bug.