feat: persisted GraphQL operations#46
Merged
Merged
Conversation
b5a1352 to
1f0d893
Compare
Codecov Report❌ Patch coverage is 📢 Thoughts on this report? Let us know! |
New package Trax.Api.GraphQL.PersistedOperations: - PersistedOperationsBuilder fluent config (RequirePersisted, AllowOperations, WithInMemoryCache, UseRabbitMqInvalidation, DisableIntrospection, LogNonPersistedRequests). - DbPersistedOperationStorage implementing both IPersistedOperationStore (programmatic CRUD) and HotChocolate's IOperationDocumentStorage. Uses the existing IDataContextProviderFactory; no separate DbContext. - ASP.NET middleware that enforces inline-query rejection, allowlist bypass, automatic introspection bypass, and shadow-mode logging. Registered via app.UsePersistedOperationsEnforcement(). - Shape-diff fingerprint computer (sha-256 over a canonicalized AST walk: inlines fragments, sorts sibling fields, tracks aliases and @include/@Skip directives). Binding test fixture covers ~30 labeled pairs across same-shape and different-shape cases. - Optional in-memory cache (NoOp default) and RabbitMQ-based multi-node cache invalidation broadcaster (NoOp default). Both opt-in. - Standalone AddPersistedOperationStore extension for non-GraphQL hosts (admin tools, manifest uploaders). Tests: 163 passing across unit (allowlist, introspection detector, id parser, builder validation, shape-diff fixture, middleware, cache, no-op broadcaster) and integration (storage CRUD, history rows, broadcast publishing, cache hit, EF round-trip persistence, composite PK isolation).
1f0d893 to
5f02337
Compare
|
This PR is included in version 1.26.0 |
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
New package
Trax.Api.GraphQL.PersistedOperations:PersistedOperationsBuilder(RequirePersisted, AllowOperations, AllowOperationsMatching, WithInMemoryCache, UseRabbitMqInvalidation, DisableIntrospection, LogNonPersistedRequests, UseDatabase). Builder validates inconsistent configs at startup with named error messages.DbPersistedOperationStorageimplementing bothIPersistedOperationStore(programmatic CRUD) and HotChocolate'sIOperationDocumentStorage. Reads/writes through the existing TraxIDataContextProviderFactory; no dedicated DbContext.UpsertAsynccomputes a canonicalized SHA-256 fingerprint of the response shape (AST walker that inlines fragments, sorts sibling fields by alias/response-key, tracks @include/@Skip directives) and rejects edits that change the shape withShapeDiffViolationExceptionunlessBypassShapeDiff = true.IPersistedOperationCache(NoOp default, in-memory opt-in viaWithInMemoryCache). Optional RabbitMQ-backed multi-node invalidation (UseRabbitMqInvalidation).AddPersistedOperationStorestandalone DI extension for non-GraphQL admin tools.Wires through
TraxGraphQLBuilder.UsePersistedOperations(...)andapp.UsePersistedOperationsEnforcement().Models live in Trax.Effect (separate PR); this PR depends on it landing first.
Test plan
dotnet build Trax.Api/produces zero warnings.dotnet test tests/Trax.Api.Tests/ --filter "FullyQualifiedName~PersistedOperations"passes 197 tests.Trax.Api.GraphQL.PersistedOperations>= 95% (measured locally at 96.0%).trax_rabbitmqcontainer.trax_databasecontainer.