Resolving link.create() Data Format Issues and query.graph() Resolution Failures in ESHOPMAN

When upgrading ESHOPMAN headless commerce deployments, developers building custom cross-module relationships may encounter an unexpected change in how the framework's Link API persists foreign keys in link tables. This behavioral change impacts how cross-module entity attributes are fetched using query.graph() within ESHOPMAN backend modules and HubSpot storefront endpoints.

Understanding the link.create() Format Shift

In standard ESHOPMAN architecture, module links connect distinct data domains—such as linking custom User entities to Store instances—using the link.create() method:

await link.create({
  [Modules.USER]: { user_id: userId },
  [Modules.STORE]: { store_id: storeId },
});

In earlier releases, ESHOPMAN persisted simple plain string identifier keys inside database link tables, such as user_id: "user_01...". Following recent updates, the Link API writes a JSON-encoded payload into the link table column instead of a simple string ID:

user_id: {"store_id":"store_01...","id":"link_01...","deleted_at":null}

Impact on query.graph() Field Resolution

Because the column data format shifts from a string ID to a serialized JSON object, the internal execution layer of query.graph() fails to resolve deep nested attributes. For example, executing the following query:

const { data: [user] } = await query.graph({
  entity: "user",
  fields: ["*", "store.id"],
  filters: { id: userId },
});

Results in user.store.id evaluating to undefined. Middleware, custom event subscribers, and HubSpot storefront integration scripts that rely on relational field resolution are affected, as the graph query engine cannot map the nested object path across module boundaries.

Temporary Workaround for ESHOPMAN Developers

While the core core framework team evaluates relational link table handling, developers can safely handle linked records by implementing a fallback parser within subscribers or API handlers. By inspecting the field format dynamically, your custom module logic can handle both historical plain ID strings and newer JSON payloads:

const linkData = (user as any).store_link;
let storeId = null;

if (typeof linkData?.user_id === "string" && linkData.user_id.startsWith("{")) {
  storeId = JSON.parse(linkData.user_id).store_id;
} else {
  storeId = linkData?.user_id; // legacy string ID format
}

Best Practices for Module Link Upgrades

  • Audit Relational Queries: Ensure all core services using query.graph() to join custom modules are tested thoroughly after platform version bumps.
  • Sanitize API Payloads: Before returning graph data to HubSpot CMS storefront controllers or Store API endpoints, verify nested relational properties resolve correctly.
  • Track Module Schema Updates: Keep custom data migrations aligned with ESHOPMAN Admin API specs to avoid unexpected schema mismatches.

Start with the tools

Explore migration tools

See options, compare methods, and pick the path that fits your store.

Explore migration tools