From 38488c2612c42ea52349825cf3ef3a4e3ca00083 Mon Sep 17 00:00:00 2001 From: Alejandro Alonso Date: Mon, 13 Jul 2026 18:20:02 +0200 Subject: [PATCH] :sparkles: Validate graph ingest projections with Malli --- backend/src/app/graph/ingest.clj | 7 +++++++ backend/src/app/graph/project/document.clj | 16 ++++++++++++---- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/backend/src/app/graph/ingest.clj b/backend/src/app/graph/ingest.clj index 5623f09431..180f0cc342 100644 --- a/backend/src/app/graph/ingest.clj +++ b/backend/src/app/graph/ingest.clj @@ -10,6 +10,7 @@ [app.binfile.common :as bfc] [app.common.exceptions :as ex] [app.common.logging :as l] + [app.common.types.file :as ctf] [app.db :as db] [app.graph.ladybug :as ladybug] [app.graph.project.document :as project.document] @@ -28,6 +29,12 @@ (ex/raise :type :not-found :code :file-not-found :file-id (str file-id))) + (when-not (:data file) + (ex/raise :type :validation + :code :file-without-data + :hint "file has no data to project" + :file-id (str file-id))) + (ctf/check-file-data (:data file)) (when reset-db? (ladybug/reset-db-path! db-path)) (l/inf :hint "graph ingest" diff --git a/backend/src/app/graph/project/document.clj b/backend/src/app/graph/project/document.clj index 09b900c79a..80606944bf 100644 --- a/backend/src/app/graph/project/document.clj +++ b/backend/src/app/graph/project/document.clj @@ -13,6 +13,7 @@ [app.common.logging :as l] [app.common.uuid :as uuid] [app.graph.ladybug :as ladybug] + [app.graph.project.specs :as specs] [clojure.string :as str])) (def root-frame-id @@ -37,6 +38,10 @@ attrs))] (str "CREATE (n:`" table "` {" props "});"))) +(defn- validated-node-statement + [check-fn table attrs] + (create-node-statement table (check-fn attrs))) + (defn- merge-edge-statement [from-table from-id to-table to-id position] (str "MATCH (c:`" from-table "` {`id`: " (ladybug/format-uuid from-id) "}), " @@ -67,7 +72,8 @@ root (get objects root-frame-id) top-level-ids (when root (vec (reverse (:shapes root)))) statements' (conj statements - (create-node-statement "Page" (page-attrs page position)) + (validated-node-statement specs/check-page "Page" + (page-attrs page position)) (merge-edge-statement "Page" page-id "Document" doc-id position)) stats' (update stats :pages inc)] (if (seq top-level-ids) @@ -76,8 +82,9 @@ (if-let [shape (get objects shape-id)] (if-let [table (shape-table shape)] [(-> stmts - (conj (create-node-statement table {:id (:id shape) - :name (:name shape)}) + (conj (validated-node-statement specs/check-shape-node table + {:id (:id shape) + :name (:name shape)}) (merge-edge-statement table (:id shape) "Page" page-id shape-pos))) (update st :shapes inc)] @@ -98,7 +105,8 @@ [data file] (let [doc-id (or (:id data) (:id file)) pages (seq (reverse (:pages data))) - initial [(create-node-statement "Document" (document-attrs file data))] + initial [(validated-node-statement specs/check-document "Document" + (document-attrs file data))] [statements stats] (if (empty? pages) [initial {:documents 1 :pages 0 :shapes 0}]