fix(persisted-operations): invalidate HotChocolate caches on document change#52
Merged
Merged
Conversation
… change Re-uploading a persisted operation updated the DB row and Trax's optional IPersistedOperationCache but left HotChocolate's request-pipeline caches holding the previously parsed DocumentNode and compiled IOperation. The request executor short-circuited on the cached compiled form, so the new document only took effect after a process restart. DbPersistedOperationStorage now clears both HC cache layers (IDocumentCache, root-scoped; IPreparedOperationCache, schema-scoped) on Upsert / Deactivate / Restore via a new HotChocolateOperationCacheInvalidator. PersistedOperationReceiverService calls the same invalidator on remote RabbitMQ messages so multi-node deployments stay coherent. Neither HC cache exposes per-id removal, so each call clears the cache wholesale — acceptable since persisted-op edits are operator-driven and rare. Tests: HotChocolateCacheInvalidationTests pins the contract end-to-end (via store and via the GraphQL upload mutation) and asserts both HC caches reach Count == 0 after an upsert. Existing receiver/storage tests updated for the new constructor parameter.
|
This PR is included in version 1.28.2 |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Re-uploading a persisted operation updated the DB row and Trax's optional
IPersistedOperationCachebut left HotChocolate's request-pipeline caches holding the previously parsedDocumentNode(root-scopedIDocumentCache, keyed by persisted-op id) and the previously compiledIOperation(schema-scopedIPreparedOperationCache, keyed by{schema}-{executorVersion}-{documentId}+{operationName}). The executor short-circuited on the cached compiled form, so the new document only took effect after a process restart.DbPersistedOperationStoragenow calls a newHotChocolateOperationCacheInvalidatoron Upsert / Deactivate / Restore.PersistedOperationReceiverServicedoes the same on remote RabbitMQ messages so multi-node deployments stay coherent. Neither HC cache exposes per-id removal in 15.x, so each call clears the cache wholesale — fine because edits are operator-driven and rare.Test plan
HotChocolateCacheInvalidationTestspins the contract end-to-end: upsert via store and via the GraphQL upload mutation each serve the new document on the next execute; both HC caches reachCount == 0after upsert; deactivate hides the document from subsequent executes; restore re-enables it; the invalidator can be exercised directly and clears both caches.Related