Skip to content

feat(extract): add Liquid extractor for Shopify theme references - #5553

Closed
dalexhd wants to merge 4 commits into
Graphify-Labs:v8from
dalexhd:feat/liquid-extractor
Closed

dalexhd wants to merge 4 commits into
Graphify-Labs:v8from
dalexhd:feat/liquid-extractor

Conversation

@dalexhd

@dalexhd dalexhd commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

What does this PR do?

Adds a deterministic regex extractor for Shopify theme .liquid files, so graphify affected snippets/card.liquid follows render, section and content_for edges, and a broken render 'missing' becomes visible. Closes #5552. Part 1 of 2; the theme JSON extractor follows in a stacked PR.

Type of change

  • Bug fix
  • New feature
  • Documentation
  • Tests or CI
  • Refactor
  • Security fix

Implementation

  • graphify/extractors/liquid.py: a regex extractor in the style of the Blade and EJS ones. Deterministic, no LLM, no new dependency. Registered in LANGUAGE_EXTRACTORS and the .liquid dispatch. docs/how-it-works.md is updated.
  • Theme gate: a .liquid file is read for references only when an ancestor (at most 3 levels up) holds layout/theme.liquid. Jekyll and Eleventy also use .liquid; outside a theme only the file node is emitted.
  • Relations:
    • render, include, section, sections, content_for 'block' and block types in {% schema %} -> imports edge to the target file, so affected follows them.
    • 'x' | asset_url and 'a.b' | t -> references edge to the asset or the locale key.
  • Broken references: a static name whose file or key does not exist becomes an AMBIGUOUS edge (score 0.2) to a node with unresolved: true and ref_kind (snippet, section, block, asset, t). Dynamic names (render some_var), names containing /, \ or .., and absolute asset names get no edge.
  • An asset literal with a query or fragment (font.eot?#iefix) resolves the part before ? or #.

Verification & Invariants

  • Invariant: extraction is deterministic and fail-closed. Two runs give identical nodes and edges; a name that cannot be resolved statically gets no edge (dynamic) or an AMBIGUOUS edge to an unresolved: true node, never a guessed target.
  • Outside a theme root only the file node is emitted, so Jekyll and Eleventy .liquid files are unaffected.
  • No persisted state format changes.

Commands run on the PR head:

uv run pytest tests/test_liquid_extractor.py -q
uv run ruff check graphify/extractors/liquid.py tests/test_liquid_extractor.py
uv run pyright graphify/extractors/liquid.py
uv run pytest tests -q
  • tests/test_liquid_extractor.py uses a synthetic theme fixture (generic names only). One strict xfail documents the limit below.
  • Full suite, rebased on current v8: the same 30 failures as an unmodified v8 checkout in the same environment, none new (tests/test_serve_reload_off_loop.py skipped: anyio not installed locally).
  • Both fixes in the last commit have a regression test that fails when the source change is reverted (checked on a throwaway branch).
  • Real data: three production themes (largest has about 5,800 nodes) were built with graphify update, no API key set, in 5 to 8 seconds each. Two runs per theme gave identical nodes and edges. graphify affected snippets/icon.liquid lists the sections, blocks and snippets that render it.

Limitations

  • Incremental update keeps a stale unresolved node until a full rebuild if the missing file appears later (strict xfail, documented in the module docstring).
  • CSS and JS inside {% stylesheet %} / {% javascript %}, the {% block %} / {% partial %} preview tags, app blocks and section-local blocks are not read.
  • content_for 'blocks' (the placeholder form) produces no edge.

How was this tested?

uv run pytest tests/test_liquid_extractor.py -q
uv run ruff check graphify/extractors/liquid.py tests/test_liquid_extractor.py
uv run pyright graphify/extractors/liquid.py
uv run pytest tests -q

Graphify-specific checklist

  • I confirmed that AST/structural extraction remains deterministic (no ambient state dependencies like ENV variables).
  • I confirmed no API keys or local-only graph data are included.
  • I disclosed AI authorship in my commit messages (Co-Authored-By: trailer).
  • Skill artifacts: no skill source fragments changed; uv run python -m tools.skillgen --check passes.

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

Nothing blocking · 6 possible issues to check · Merge confidence 5/5

6 possible issues to check · High impact

The change adds a Shopify-theme Liquid extractor for template, asset, and translation references.

6 possible issues we couldn't confirm
  • Liquid theme files are counted as supported code even if no Liquid extractor is registered, which hides them from the unsupported-file warni · graphify/detect.py:48
  • Liquid-file imports and references skip the cross-language guard, so bare names can bind to other-language nodes · graphify/build.py:2308
  • Calls from inline <script> blocks in Liquid theme files to theme JavaScript are dropped by the new liquid family mapping · graphify/extract.py:4892
  • +3 more in Graphify

They don't change the score.

What this review covered
  • We didn't review 8 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.
  • 8 of 8 changed files inspected. This is scope, not a correctness guarantee.
Code graph · 7527 functions depend on this change
  • 3 functions became more coupled. extract() (1398 callers), build_from_json() (347 callers), extract_liquid() (10 callers).
  • Gate, test list and every flagged function: in the Graphify check.

Reviewed 45963e8 · 3 earlier findings not re-checked

Comment thread graphify/extractors/liquid.py Resolved
… 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]>
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.

Add Shopify theme support: Liquid files and theme JSON templates

2 participants