Skip to content

AST import edges silently dropped: short ID vs full path ID mismatch #256

Closed

Description

@77DidO

Bug

imports_from edges extracted by graphify.extract.extract() are silently dropped during build_from_json() because the import target IDs don't match the file node IDs.

Repro

from graphify.extract import extract
from pathlib import Path

result = extract([
    Path('backend/src/pipeline/steps/summarise-step.ts'),
    Path('backend/src/services/openai/structured-generation.ts'),
])

# Import edge created:
#   source: "backend_src_pipeline_steps_summarise_step_ts"
#   target: "structured_generation_js"     <-- SHORT ID
#
# But the actual file node ID is:
#   "backend_src_services_openai_structured_generation_ts"  <-- FULL PATH ID
#
# Result: edge points to a non-existent node and is silently dropped

Impact

On a 388-file TypeScript codebase, AST extraction found 1443 raw import edges but the final graph had 0 imports_from edges. This makes all cross-file dependencies invisible, causing the graph to fragment into hundreds of disconnected communities that should be connected.

Root cause

extract() creates import target IDs from the import specifier ('./structured-generation.js' → structured_generation_js) without resolving the relative path to the full filesystem path. File node IDs use the full path (backend_src_services_openai_structured_generation_ts).

Expected behavior

Import target IDs should resolve to the actual file node IDs, either:

  1. During extraction (resolve ./foo.js relative to the importing file's directory)
  2. During build_from_json() (fuzzy match foo_js → *_foo_ts)

Workaround

Post-build script that matches import targets by stem name:

# Strip _js suffix, match stem to file node
stem = "structured_generation"  # from "structured_generation_js"
full_id = file_nodes.get(stem)  # -> "backend_src_services_openai_structured_generation_ts"

This recovered 527 out of 1443 import edges (the rest are external/node_modules).

Environment

  • graphifyy 0.4.2
  • TypeScript/ESM codebase with .js import extensions
  • Windows 11

Activity

  1. added a commit that references this issue on Apr 12, 2026
  2. safishamsi commented on Apr 12, 2026

    @safishamsi
    Member

    Fixed in v0.4.3. Relative JS/TS imports (e.g. ./foo.js) now resolve to the full filesystem path before generating the node ID, so they match the file node IDs introduced in v0.4.2. Python relative imports (from .foo import bar) fixed the same way.

  3. added a commit that references this issue on Apr 23, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions