Skip to content

fix(api-catalog): stabilize manifest ordering and sync metafields drift - #204

Open
jpage-godaddy wants to merge 1 commit into
mainfrom
spec-drift
Open

fix(api-catalog): stabilize manifest ordering and sync metafields drift#204
jpage-godaddy wants to merge 1 commit into
mainfrom
spec-drift

Conversation

@jpage-godaddy

@jpage-godaddy jpage-godaddy commented Aug 11, 2026

Copy link
Copy Markdown
Collaborator

Summary

  • Switches the manifest's domain map from HashMap to BTreeMap so manifest.json keys serialize in stable, sorted order instead of reshuffling on every regeneration. Verified by running generate-api-catalog twice back-to-back and diffing — identical apart from the generated timestamp.
  • Picks up real upstream drift in metafields.json (expanded resourceType/type enums, new metafieldDefinitionId field, updated required fields) — this was flagged by the spec-drift job in run 31533986583 alongside the catalog-products parse failure that feat(api-explorer): add api graphql command group for GraphQL-backed domains #200 addresses.

Test plan

  • cargo check --workspace
  • cargo clippy --workspace -- -D warnings
  • cargo test --workspace (578 passed)
  • cargo fmt --check
  • ./rust/scripts/check-module-size.sh
  • Ran generate-api-catalog twice back-to-back post-rebase and confirmed all catalog files (including catalog-products.json/taxes.json from feat(api-explorer): add api graphql command group for GraphQL-backed domains #200) regenerate byte-identical apart from the manifest.json timestamp

Copilot AI lite review requested due to automatic review settings August 11, 2026 22:42

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 to graphql-parser, plus add unit tests for the sanitizer.
  • Serialize manifest.json domains in stable sorted order by switching the domains map to BTreeMap.
  • 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.

Comment thread rust/schemas/api/catalog-products.json
Comment thread rust/tools/generate-api-catalog/src/graphql.rs Outdated

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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-parser can’t handle will still result in a zero-operation catalog because load_graphql_schema currently swallows parse_graphql_operations errors and returns Vec::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_balanced claims 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 future extend schema usage) 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 {

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@jpage-godaddy jpage-godaddy changed the title fix(api-catalog): parse federated GraphQL schemas and stabilize manifest order fix(api-catalog): stabilize manifest ordering and sync metafields drift Aug 11, 2026
Base automatically changed from graphql to main August 12, 2026 00:23
…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.
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.

2 participants