Repository: wilkerlucio/pathom
Pull request #55 (2018-10-18 04:41:17)

added tests and fix for elided metadata
Fixes issue #54 


Patch:
diff --git a/project.clj b/project.clj
index f51c69ae..dcc969ca 100644
--- a/project.clj
+++ b/project.clj
@@ -1,4 +1,4 @@
-(defproject com.wsscode/pathom "2.2.0-beta13"
+(defproject com.wsscode/pathom "2.2.0-beta14-SNAPSHOT"
   :description "A Clojure library designed to provide a collection of helper functions to support Clojure(script) graph parsers using\nom.next graph syntax."
   :url "https://github.com/wilkerlucio/pathom"
   :license {:name "Eclipse Public License"
@@ -10,6 +10,8 @@
                  [com.wsscode/spec-inspec "1.0.0-alpha2"]
                  [org.clojure/data.json "0.2.6"]
                  [spec-coerce "1.0.0-alpha6"]
+                 [com.cognitect/transit-clj "0.8.313" :scope "test"]
+                 [com.cognitect/transit-cljs "0.8.256" :scope "test"]
 
                  ; provided
 
diff --git a/src/com/wsscode/pathom/core.cljc b/src/com/wsscode/pathom/core.cljc
index e5aad6cf..efe98e0c 100644
--- a/src/com/wsscode/pathom/core.cljc
+++ b/src/com/wsscode/pathom/core.cljc
@@ -192,7 +192,8 @@
   (walk/prewalk
     (fn elide-items-walk [x]
       (if (map? x)
-        (into {} xform x)
+        (let [old-meta (meta x)]
+          (with-meta (into {} xform x) old-meta))
         x))
     input))
 
@@ -217,7 +218,10 @@
 (defn elide-items
   "Removes any item on set item-set from the input"
   [item-set input]
-  (transduce-maps (remove (fn [[_ v]] (contains? item-set v))) input))
+  (let [old-meta (meta input)]
+    (with-meta
+      (transduce-maps (remove (fn [[_ v]] (contains? item-set v))) input)
+      old-meta)))
 
 (defn elide-not-found
   "Convert all ::p/not-found values of maps to nil"


Test patch:
diff --git a/test/com/wsscode/pathom/connect_test.cljc b/test/com/wsscode/pathom/connect_test.cljc
index edfa847a..c6f5df88 100644
--- a/test/com/wsscode/pathom/connect_test.cljc
+++ b/test/com/wsscode/pathom/connect_test.cljc
@@ -548,7 +548,7 @@
 (defmutation 'call/op
   {::pc/output [:user/id]}
   (fn [env input]
-    {:user/id 1}))
+    (with-meta {:user/id 1} {:x 1})))
 
 (defmutation 'call/op-tmpids
   {::pc/output [:user/id]}
@@ -573,6 +573,10 @@
     (is (= (parser {} ['(call/op {})])
            {'call/op {:user/id 1}})))
 
+  (testing "operation metadata is preserved"
+    (is (= (meta ('call/op (parser {} ['(call/op {})])))
+          {:x 1})))
+
   (testing "calling simple operation aliased"
     (is (= (parser {} ['(call/op-alias {})])
            {'call/op-alias {:user/id 1}})))
diff --git a/test/com/wsscode/pathom/core_test.cljc b/test/com/wsscode/pathom/core_test.cljc
index 26c6b517..e120d55f 100644
--- a/test/com/wsscode/pathom/core_test.cljc
+++ b/test/com/wsscode/pathom/core_test.cljc
@@ -247,12 +247,21 @@
          {:a 1 :b "extra"})))
 
 (deftest test-elide-not-found
+  (testing "Removes fields marked not found"
   (is (= (p/elide-not-found {:a 1
                              :b :com.wsscode.pathom.core/not-found
                              :c "extra"
                              :d :com.wsscode.pathom.core/not-found})
          {:a 1
           :c "extra"})))
+  (testing "Preserves metadata"
+    (is (= (meta (p/elide-not-found (with-meta
+                                      {:a 1
+                                       :b :com.wsscode.pathom.core/not-found
+                                       :c "extra"
+                                       :d :com.wsscode.pathom.core/not-found}
+                                      {:x 1})))
+          {:x 1}))))
 
 (deftest test-transduce-items
   (is (= (p/transduce-maps