Skip to content

feat: persisted-operations sample + E2E test project#53

Merged
Theauxm merged 2 commits intomainfrom
feat/persisted-operations
May 8, 2026
Merged

feat: persisted-operations sample + E2E test project#53
Theauxm merged 2 commits intomainfrom
feat/persisted-operations

Conversation

@Theauxm
Copy link
Copy Markdown
Member

@Theauxm Theauxm commented May 8, 2026

Summary

A real Trax demo of persisted operations: trains, mediator, GraphQL exposure via [TraxQuery], and persisted-op enforcement.

Library (Trax.Samples.PersistedOperations) — train assembly:

  • GreetTrain (namespace greeting): Junction<GreetInput, GreetOutput> builds a greeting and timestamp.
  • LookupUserTrain (namespace users): Junction<LookupUserInput, UserProfile> resolves a synthetic user profile.
  • Both [TraxQuery]-attributed and discovered through AddMediator(typeof(GraphQLNamespaces).Assembly).

API (.Api)WebApplication host:

  • AddTrax(t => t.AddEffects(e => e.UsePostgres(...)).AddMediator(...)).
  • AddTraxGraphQL(g => g.UsePersistedOperations(opts => opts.UseDatabase(...).RequirePersisted(true).LogNonPersistedRequests(true).AllowOperationsMatching(id => id.StartsWith("dev_")))).
  • app.UsePersistedOperationsEnforcement() then UseTraxGraphQL().

Client (.Client) — console process:

  • Wires AddTrax + AddPersistedOperationStore.
  • Uploads a manifest (greet_v1, lookupUser_v1) of GraphQL documents that call into the trains.
  • Sends requests by id, demonstrates the hot-fix flow.

E2E test project (.E2E)WebApplicationFactory<Program> against real Postgres, 18 tests covering: enforcement (inline rejected, persisted accepted), distinct-ids dispatching to distinct trains, multi-variable inputs returning correct results per call, deactivate/restore lifecycle, history accumulation, dev-prefix bypass, content-type variants, batched requests (rejected wholesale on inline entry; both-persisted batches pass), shape-diff rejection, deactivated-id error shape, auth-ordering smoke check, tenant scoping isolation.

Live smoke run completes end-to-end:

--- greet_v1 (Alice) ---
{"data":{"discover":{"greeting":{"greet":{"greeting":"Hello, Alice.","greetedAt":"2026-05-08T17:41:51.384Z"}}}}}

--- lookupUser_v1 (user-42) ---
{"data":{"discover":{"users":{"lookupUser":{"userId":"user-42","displayName":"User user-42","email":"[email protected]","loginCount":808}}}}}

Depends on Trax.Api PR (uses the new package).

Test plan

  • dotnet build Trax.Samples/ produces zero warnings.
  • dotnet test tests/Trax.Samples.PersistedOperations.E2E/ passes 18/18 against docker compose up -d.
  • dotnet run --project samples/PersistedOperations/Trax.Samples.PersistedOperations.Api/ followed by the Client process completes the upload + query + hot-fix loop end-to-end.

@Theauxm Theauxm force-pushed the feat/persisted-operations branch from 916521d to f05af10 Compare May 8, 2026 17:42
Two-process sample under samples/PersistedOperations:
- Trax.Samples.PersistedOperations.Api: GraphQL host with persisted-op
  enforcement enabled. Demonstrates AllowOperationsMatching for dev_*
  carve-outs and shadow-mode logging.
- Trax.Samples.PersistedOperations.Client: console client that uploads
  a manifest, sends a request by id, hot-fixes the document, and
  re-queries to demonstrate the no-redeploy flow.

E2E test project under tests/Trax.Samples.PersistedOperations.E2E:
- WebApplicationFactory<Program>-hosted in-process API, real Postgres
  via the docker-compose container.
- Enforcement, dev-prefix bypass, deactivate/restore lifecycle, hot-fix
  flow tests. The persisted-id resolution path (3 tests) is currently
  Ignored pending follow-up on HC v15's IOperationDocumentStorage
  pipeline wiring; the storage layer itself is fully exercised by the
  Trax.Api integration suite.
@Theauxm Theauxm force-pushed the feat/persisted-operations branch from f05af10 to c9e04b8 Compare May 8, 2026 18:03
@Theauxm Theauxm mentioned this pull request May 8, 2026
1 task
Switch the dev broker to trax/trax123 so local docker-compose mirrors
the CI service container, and apply csharpier formatting to two E2E
test files that were failing the format check.
@Theauxm Theauxm merged commit 413a9ed into main May 8, 2026
1 check passed
@codecov
Copy link
Copy Markdown

codecov Bot commented May 8, 2026

Codecov Report

❌ Patch coverage is 98.11321% with 1 line in your changes missing coverage. Please review.

Files with missing lines Patch % Lines
...ns/Trax.Samples.PersistedOperations.Api/Program.cs 96.00% 0 Missing and 1 partial ⚠️

📢 Thoughts on this report? Let us know!

@Theauxm Theauxm deleted the feat/persisted-operations branch May 8, 2026 19:48
@traxsharp
Copy link
Copy Markdown

traxsharp Bot commented May 8, 2026

This PR is included in version 1.22.0

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