Created
April 5, 2020 22:41
-
-
Save currentoor/1b8d08a5ab509f7421b534b8f6f1fb63 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(defn elide-params [params elision-predicate] | |
(walk/postwalk (fn [x] | |
(if (and (vector? x) (= 2 (count x)) (elision-predicate (first x))) | |
nil | |
x)) | |
params)) | |
(def blacklist #{:ui.fulcro.client.data-fetch.load-markers/by-id | |
:com.fulcrologic.rad.picker-options/options-cache | |
::uism/asm-id | |
::app/active-remotes | |
:com.fulcrologic.rad.blob/blobs | |
df/marker-table | |
::fs/config}) | |
(defn elide-ast-nodes | |
"Like df/elide-ast-nodes but also applies elision-predicate logic to mutation params." | |
[{:keys [key union-key children] :as ast} elision-predicate] | |
(let [union-elision? (and union-key (elision-predicate union-key))] | |
(when-not (or union-elision? (elision-predicate key)) | |
(when (and union-elision? (<= (count children) 2)) | |
(log/warn "Unions are not designed to be used with fewer than two children. Check your calls to Fulcro | |
load functions where the :without set contains " (pr-str union-key))) | |
(let [new-ast (-> ast | |
(update :children (fn [c] (vec (keep #(elide-ast-nodes % elision-predicate) c)))) | |
(update :params elide-params elision-predicate))] | |
(if (seq (:children new-ast)) | |
new-ast | |
(dissoc new-ast :children)))))) | |
(defn elision-predicate [k] | |
(let [kw-namespace (fn [k] (and (keyword? k) (namespace k))) | |
k (if (vector? k) (first k) k) | |
ns (some-> k kw-namespace)] | |
(or | |
(contains? blacklist k) | |
(and (string? ns) (= "ui" ns))))) | |
(defn global-eql-transform [ast] | |
(let [mutation? (symbol? (:dispatch-key ast))] | |
(cond-> (elide-ast-nodes ast elision-predicate) | |
js/goog.DEBUG (update :children conj (eql/expr->ast :com.wsscode.pathom/trace)) | |
mutation? (update :children conj (eql/expr->ast :tempids) | |
(eql/expr->ast :ucv/mutation-errors))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment