Snapshot example services' GraphQL schemas as insta tests#6542
Conversation
deuszx
left a comment
There was a problem hiding this comment.
I think the description is outdated(?) since you added this pattern for all examples?
Also, why not add the fn schema() to trait ServiceAbi?
Yes thx, I keep reminding Claude to do that
Because in theory, an app doesn't have to use GraphQL. It's just a convention that most (Wasm) apps use (like BCS) but it's not part of the core protocol. |
|
(I guess we could have a |
But we have (for example) |
Yes this could work. And also |
Motivation
We already record each application's serde/BCS formats as an
instasnapshot (via theBcsApplicationtrait) so that unintended changes to the wire format of operations, messages and events show up as a reviewable diff. The GraphQL schema exposed by an application's service has no equivalent guard: today nothing flags an accidental change to the query/mutation surface that clients depend on.Proposal
Establish a lightweight, purely conventional pattern (no new trait, no macro) for snapshotting a service's GraphQL schema, and apply it to
hex-gameas the reference implementation.Unlike
BcsApplication::formats(), which is type-only, building anasync-graphqlSchemaneeds owned instances of the roots and aServiceRuntime— so the natural home is a#[cfg(test)]unit test inservice.rs, whereServiceRuntimeresolves toMockServiceRuntime. Concretely, forhex-game:HexService::schema()and havehandle_querydelegate to it, so the snapshotted SDL cannot drift from what the service actually serves.schema_sdltest:insta::assert_snapshot!(service.schema().sdl()), reusing the existing mock-runtime setup.Test Plan
cargo test -p hex-game --bin hex_game_service— bothqueryand the newschema_sdlpass.schema_sdlagainst the committed snapshot withoutINSTA_UPDATEto confirm the SDL is deterministic (theMapViewhash-suffixed type names are stable across runs).cargo fmt -- --check(pinned nightly) andcargo clippy -p hex-game --testsboth clean.Release Plan
Links