Skip to content

fix(persisted-operations): invalidate HotChocolate caches on document change#52

Merged
Theauxm merged 1 commit into
mainfrom
fix/persisted-ops-hc-cache-invalidation
May 12, 2026
Merged

fix(persisted-operations): invalidate HotChocolate caches on document change#52
Theauxm merged 1 commit into
mainfrom
fix/persisted-ops-hc-cache-invalidation

Conversation

@Theauxm
Copy link
Copy Markdown
Member

@Theauxm Theauxm commented May 12, 2026

Summary

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 (root-scoped IDocumentCache, keyed by persisted-op id) and the previously compiled IOperation (schema-scoped IPreparedOperationCache, 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.

DbPersistedOperationStorage now calls a new HotChocolateOperationCacheInvalidator on Upsert / Deactivate / Restore. PersistedOperationReceiverService does 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

  • HotChocolateCacheInvalidationTests pins 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 reach Count == 0 after upsert; deactivate hides the document from subsequent executes; restore re-enables it; the invalidator can be exercised directly and clears both caches.
  • Existing receiver/storage tests updated for the new constructor parameter.
  • Full Trax.Api.Tests suite: 1099 passed, 0 failed.
  • E2E verified against the matching sample fix in Trax.Samples — see https://github.com/TraxSharp/Trax.Samples PR (paired branch).

Related

  • Companion PR in Trax.Samples (hot-fix sample now uses a genuinely different doc and asserts the change took effect).
  • Companion PR in Trax.Docs (notes the new HC cache-clear behaviour).

… 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.
@Theauxm Theauxm merged commit 943a3ae into main May 12, 2026
1 check passed
@Theauxm Theauxm deleted the fix/persisted-ops-hc-cache-invalidation branch May 12, 2026 17:08
@traxsharp
Copy link
Copy Markdown

traxsharp Bot commented May 12, 2026

This PR is included in version 1.28.2

@codecov
Copy link
Copy Markdown

codecov Bot commented May 12, 2026

Codecov Report

❌ Patch coverage is 75.00000% with 13 lines in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...s/Storage/HotChocolateOperationCacheInvalidator.cs 62.85% 12 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant