Open vinaybedre opened 5 months ago
Hi! Thank you for raising this issue!
The problem seems to be the federation driver, which uses useApolloFederation
plugin under the hood to setup a federation executor.
The problem is that this plugin is added at the end of the plugin list, which overrides the custom executor from the useResponseCache
.
Do you have any warnings coming from the response cache plugin ? It should detect this case and warn about this problem.
To fix this, the federation yoga server should be updated to put the federation plugin at the start of the plugin list instead of the end.
@EmrysMyrddin you are correct, I am getting a warning [useResponseCache] The cached execute function was not called, another plugin might have overwritten it. Please check your plugin order.
But in federation, the plugin useApolloFederation
is applied at the end as per this line https://github.com/dotansimha/graphql-yoga/blob/3d0cfd29fff92a98308b20b08c45aff68e0e9fa1/packages/nestjs-federation/src/index.ts#L111
or you mean to say that useApolloFederation
must be at the start?
@EmrysMyrddin I just created a patch by changing useApolloFederation to be the first plugin. You can see the changes at https://stackblitz.com/~/github.com/vinaybedre/envelop-response-cache-bug
After patching i see no warning, but caching is still not working.
Issue workflow progress
Progress of the issue based on the Contributor Workflow
@envelop/*
packages that you are using.[ ] 4. A pull request is pending review
Describe the bug
The caching via plugin
useResponseCache
is not working as expected when used in the gateway of a federated service. The cache does not store ObjectTypes of GraphQL at all, but only the etag call.To Reproduce Steps to reproduce the behavior:
useResponseCache
plugin.Expected behavior
The cache should store ObjectTypes of GraphQL responses, ensuring that repeated queries retrieve data from the cache as expected.
Environment:
@envelop/*
versions: "@envelop/response-cache": "^6.1.2"Additional context
A reproducible repo is provided here: Stackblitz Reproduction