fix(api-catalog): stabilize manifest ordering and sync metafields drift - #204
fix(api-catalog): stabilize manifest ordering and sync metafields drift#204jpage-godaddy wants to merge 1 commit into
Conversation
There was a problem hiding this comment.
Pull request overview
This PR updates the generate-api-catalog tooling to (1) handle Apollo Federation v2 extend schema @link(...) GraphQL syntax by stripping schema-extension statements prior to parsing, and (2) stabilize the generated API catalog manifest ordering so regenerations don’t reshuffle keys. It also regenerates the checked-in API schema artifacts reflecting upstream drift and the corrected GraphQL parsing behavior.
Changes:
- Sanitize GraphQL schemas by removing
extend schema ...statements before feeding them tographql-parser, plus add unit tests for the sanitizer. - Serialize
manifest.jsondomains in stable sorted order by switching the domains map toBTreeMap. - Regenerate
rust/schemas/api/*.json(including updated operation counts and upstream schema changes).
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| rust/tools/generate-api-catalog/src/main.rs | Uses BTreeMap for stable manifest domain key ordering. |
| rust/tools/generate-api-catalog/src/graphql.rs | Strips extend schema ... blocks before parsing; adds sanitizer helpers + tests. |
| rust/src/api_explorer/operation.rs | Updates expected GraphQL operation count to match regenerated catalog. |
| rust/schemas/api/metafields.json | Regenerated schema capturing upstream drift and new/changed fields. |
| rust/schemas/api/manifest.json | Regenerated manifest now in stable key order and updated counts/timestamps. |
| rust/schemas/api/catalog-products.json | Regenerated GraphQL operation list/count reflecting corrected parsing and upstream changes. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 6 out of 6 changed files in this pull request and generated no new comments.
Suppressed comments (2)
rust/tools/generate-api-catalog/src/graphql.rs:80
- Even with the sanitizer, a future SDL change that
graphql-parsercan’t handle will still result in a zero-operation catalog becauseload_graphql_schemacurrently swallowsparse_graphql_operationserrors and returnsVec::new(). That can reintroduce the “wipe out operations on regeneration” failure mode the PR is trying to prevent.
Consider propagating parse errors (or failing the generator for GraphQL domains) so CI fails loudly instead of emitting a 0-op schema.
let sanitized = strip_schema_extensions(source);
let doc = graphql_parser::parse_schema::<String>(&sanitized)
.map_err(|e| anyhow::anyhow!("GraphQL parse error: {e}"))?;
rust/tools/generate-api-catalog/src/graphql.rs:256
skip_balancedclaims to respect quoted strings, but it only tracks normal"..."strings. GraphQL SDL also allows block strings ("""..."""), which can legally contain),}, or]without escaping. If a federation directive argument (or futureextend schemausage) includes a block string, this scanner can mis-count nesting and either fail to strip the schema extension cleanly or strip too much.
It would be more robust to handle """ block strings (and ideally avoid matching extend schema inside any string/comment regions).
/// Skips a balanced `(...)`, `{...}`, or `[...]` group starting at `pos`,
/// respecting quoted strings so brackets inside them aren't counted.
fn skip_balanced(source: &str, pos: usize) -> usize {
let open = source[pos..].chars().next().expect("pos < source.len()");
let close = match open {
5f79a58 to
d3a1677
Compare
d3a1677 to
9d7a74f
Compare
…est order The catalog-products GraphQL spec adopted Apollo Federation v2's `extend schema @link(...)` syntax, which graphql-parser can't parse. The generator silently fell back to zero operations on parse failure, so regenerating would have wiped out 149 GraphQL operations and reported it as drift. Strip schema-extension statements before parsing since we only need Query/Mutation fields, not federation metadata. Also switch the manifest's domain map from HashMap to BTreeMap so manifest.json keys serialize in a stable, sorted order instead of reshuffling on every regeneration. Regenerate the catalog with these fixes, recovering the catalog-products GraphQL operations (149 -> 179) and picking up real upstream drift in metafields.json.
9d7a74f to
3ab13f2
Compare
Summary
HashMaptoBTreeMapsomanifest.jsonkeys serialize in stable, sorted order instead of reshuffling on every regeneration. Verified by runninggenerate-api-catalogtwice back-to-back and diffing — identical apart from thegeneratedtimestamp.metafields.json(expandedresourceType/typeenums, newmetafieldDefinitionIdfield, updated required fields) — this was flagged by the spec-drift job in run 31533986583 alongside the catalog-products parse failure that feat(api-explorer): addapi graphqlcommand group for GraphQL-backed domains #200 addresses.Test plan
cargo check --workspacecargo clippy --workspace -- -D warningscargo test --workspace(578 passed)cargo fmt --check./rust/scripts/check-module-size.shgenerate-api-catalogtwice back-to-back post-rebase and confirmed all catalog files (includingcatalog-products.json/taxes.jsonfrom feat(api-explorer): addapi graphqlcommand group for GraphQL-backed domains #200) regenerate byte-identical apart from themanifest.jsontimestamp