Skip to content

feat(extract): link Shopify theme JSON templates to sections and blocks - #5554

Closed
dalexhd wants to merge 7 commits into
Graphify-Labs:v8from
dalexhd:feat/shopify-theme-json
Closed

dalexhd wants to merge 7 commits into
Graphify-Labs:v8from
dalexhd:feat/shopify-theme-json

Conversation

@dalexhd

@dalexhd dalexhd commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

Part 2 of 2 for #5552, stacked on #5553 (Liquid extractor): until that one merges, this diff also shows its commits.

Problem

In a current theme the page structure lives in templates/*.json and sections/*-group.json. graphify skips them as data JSON (_is_config_json), so "which pages use this section" has no answer, and a template with $schema would be walked as a config file.

Implementation

  • graphify/extractors/shopify_theme_json.py, routed by path in _get_extractor before the generic .json dispatch, next to the other path-routed branches. json_config.py is untouched.
  • Routed files: .json under templates/ (depth up to 2), sections/*.json, and config/settings_schema.json, only inside a theme root (ancestor with layout/theme.liquid, same gate as PR 1). Anything else keeps today's routing.
  • Parsing: one leading /* ... */ header is stripped, then json.loads. A parse failure yields only the file node. Keys are iterated sorted, so key order does not change the output.
  • Each placed section -> imports edge to sections/<type>.liquid; a missing file is an unresolved reference as in PR 1. App blocks (shopify:// and @app types) get nothing.
  • Nested blocks -> blocks/<type>.liquid only when that file exists; otherwise nothing, because it may be a section-local block.
  • _blocks is the section type Shopify provides for top-level blocks. It never has a file, so it is not reported as broken, but the blocks under it still link.
  • t: keys in {% schema %} bodies and in settings_schema.json -> references edge to the key in the single locales/*.default.schema.json; unresolved when absent; nothing when there is no default schema locale or there are several.

Verification

uv run pytest tests/test_shopify_theme_json_extractor.py tests/test_liquid_extractor.py tests/test_json_schema_config.py -q
uv run ruff check graphify tests/test_shopify_theme_json_extractor.py
uv run pyright graphify/extractors/shopify_theme_json.py
uv run pytest tests -q
  • Synthetic fixtures only. Covered: header comment, $schema, group plus .context.<x>.json variant, empty template, key reordering, nested blocks, app blocks, missing section, t: keys, a repo without layout/theme.liquid.
  • The _blocks fix has a regression test that fails when the source change is reverted (checked on a throwaway branch).
  • Full suite, rebased on current v8: the same 30 failures as an unmodified v8 checkout in the same environment, none new.
  • Real data: three production themes, built twice each, identical graphs. graphify affected snippets/icon.liquid now also lists the templates that place the sections which render it.

Limitations

  • config/settings_data.json and section-local blocks are not read.
  • A block type with no file is silently skipped, so a typo in a block type is not reported.

AI disclosure

Written with Claude Code. I reviewed the code and ran the commands above myself.

dalexhd and others added 3 commits November 27, 2026 15:00
Extract .liquid files of a Shopify theme (gated on a layout/theme.liquid ancestor). render/include/section/sections/content_for and schema blocks become 'imports' edges to the file they name, so 'graphify affected' on a snippet lists the sections rendering it. asset_url and the t filter become 'references' edges (asset file, or key of the single default locale). Relation 'includes' is avoided because affected does not follow it. Dynamic names, comment/doc/raw regions and path-traversal names emit nothing.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A statically named render/include/section/sections/content_for target, asset or translation key that does not exist becomes an AMBIGUOUS edge (score 0.2) to a node flagged unresolved with id ref_liquid_<kind>_<name>, instead of being dropped. Documents how to list them from graph.json and adds Liquid to the built-in parsers list. The incremental cache keeps the stale edge of an unchanged citing file after the target appears; pinned by a strict xfail, a full rebuild clears it.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
A literal such as 'font.eot?#iefix' piped into asset_url named a file that cannot exist. Resolve the part before ? or # instead of reporting a broken reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@dalexhd
dalexhd requested a review from safishamsi as a code owner November 27, 2026 14:24
@github-actions

Copy link
Copy Markdown

Thanks for the pull request, @dalexhd. A maintainer will review it soon.

Want to talk it through while it is in review? Come join us on our Discord server. For longer-form discussion there is also GitHub Discussions.

A couple of things that speed up review: make sure the test suite passes on Python 3.11 and 3.13, and that the change keeps extraction deterministic.

@graphify-labs graphify-labs Bot left a comment •

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Graphify review View in Graphify

Review before merging · Merge confidence 3/5

1 bug · 12 possible issues to check · High impact

Bug  New theme files leave cached references unresolved · liquid.py:175

12 possible issues we couldn't confirm
  • Liquid template files are now counted as source code, so they go to the code extractor instead of the document path · graphify/detect.py:48
  • Liquid templates are placed in their own interop family, so their inline scripts can no longer resolve calls to JavaScript defined in other · graphify/extract.py:4896
  • Liquid files skip the cross-language import guard, so unverified imports and references from them can still bind to same-named files in othe · graphify/build.py:2308
  • +9 more in Graphify

They don't change the score.

What this review covered
  • This review stopped before it finished; findings are from the part that ran.
  • The AI model asked for code in a way the review could not use.
  • We didn't review 9 files that aren't source code, such as docs, config, images, or generated or third-party code.
  • Some lookups asked for files or lines that do not exist; the review was told and carried on.
  • 10 of 10 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 7570 functions depend on this change
  • 6 functions became more coupled. Largest: extract() (1400 callers), build_from_json() (349 callers), _get_extractor() (46 callers).
  • 644 of 644 test files are affected by this change.
  • Gate, test list and every flagged function: in the Graphify check.

Review stopped early on 089d3eb · 14 earlier findings not re-checked

Comment on lines +100 to +103
def _place_sections(data: dict, out: _Collector) -> None:
sections = data.get("sections")
if not isinstance(sections, dict):
return

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug  Theme edits leave cached section and translation links outdated

If a referenced section or locale entry is added after extraction, an unchanged template can keep showing its old unresolved or missing links.

Re-extract unchanged theme JSON when referenced sections or locale entries change.

Evidence · checked against the code
  • Independent source review: Checked the extractor routing and cache lookup path: Shopify theme JSON reaches the generic cached extraction flow, with no dependency-based invalidation on that route. The tests inspected call the extractor directly and do not exercise cache invalidation for changed referenced files.
  • The stale-result case depends on the existing AST cache being enabled; a forced extraction or cache miss reruns the Shopify extractor.
  • Some lookups asked for files or lines that do not exist; the review was told and carried on.
Prompt to fix with AI
In graphify/extractors/shopify_theme_json.py, extract_shopify_theme_json (lines 100-103):
Problem: Theme edits leave cached section and translation links outdated
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

dalexhd and others added 4 commits November 27, 2026 15:37
… to JS siblings

Shopify default locales start with a // header, so json.loads failed and every | t edge was lost; strip // and /* */ outside strings. A .liquid -> .js reference was dropped by the cross-language guard in build, and the references target was not salted with the colliding id when x.css and x.js share a stem.

Co-Authored-By: Claude <[email protected]>
Templates and section groups of a Shopify theme place sections and blocks in JSON, which were skipped as data JSON. Route them by path (gated on a theme root) before the generic .json dispatch, link each placed section and existing theme block, and link t: schema keys to the default schema locale.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Templates place top-level blocks with section type _blocks, which Shopify provides; it never has a sections/ file, so it must not be reported as a broken reference.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Comment on lines +172 to +175
self._probe[target] = state
if state == "out":
return
if state == "missing":

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Bug  New theme files leave cached references unresolved

If a missing snippet, asset, or section file is added after an initial scan, graphify can continue showing the reference as unresolved until the citing file is re-extracted.

Evidence · checked against the code
  • Independent source review: Checked the cache invalidation path and the test's update helper: the helper runs graphify update twice around creation of the missing snippet, while cache hits bypass extraction for unchanged source. The test specifically asserts the unresolved edge is gone and is marked strict xfail; no test execution is claimed.
Prompt to fix with AI
In graphify/extractors/liquid.py, _Collector.file_edge (lines 172-175):
Problem: New theme files leave cached references unresolved
Fix it at the cause, and add a test that fails without the fix.

Graphify · Checked against the code · View in Graphify

safishamsi pushed a commit that referenced this pull request Nov 28, 2026
…5557)

Squashed landing of @dalexhd's four-PR Liquid/Shopify-theme extractor stack:
a Liquid extractor (.liquid), theme-JSON template→section/block linking, CSS
classes, settings, custom elements and metafields. Pure-stdlib scanners, no
new dependencies; all new extraction is gated to a theme root (layout/
theme.liquid) so non-theme .css/.json files are unaffected. Verified by
adversarial review: zero node/edge diff on Python and a 20-language corpus
(no existing-language regression), new extraction works, broken themes
degrade gracefully.

Schema bump is consolidated with the rest of this release's extraction-output
changes in a following commit.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
safishamsi added a commit that referenced this pull request Nov 28, 2026
…ema 58

Collapse the Shopify stack's internal 58/59/60 bumps and the TS/C++/Markdown
bumps into a single 57->58 bump with one combined entry (TS #5525/#5529,
C++ #5550/#5551, Markdown #5480, Shopify #5553/#5554/#5555/#5557), chaining to
the shipped-57 (0.9.121) entry. Fixes the stack's schema-history mislabel that
had carried the shipped-57 Rust text as 58.

Co-Authored-By: Claude Opus 4.8 <[email protected]>
@safishamsi

Copy link
Copy Markdown
Member

Shipped in v0.9.122 as the Shopify/Liquid theme extractor. The four-PR stack landed as a single squashed commit authored to you (@dalexhd) so it keeps your authorship. Adversarial review confirmed zero regression to existing-language extraction (zero node/edge diff on Python + a 20-language corpus), no new dependencies, and graceful handling of broken themes. Thanks for a substantial feature!

@safishamsi safishamsi closed this Nov 28, 2026
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