nebius/SWE-rebench-V2-PRs huggingface dataset:
Repository: wilkerlucio/pathom
Pull request #130 (2019-10-25 00:02:54)

Defresolver docs


Patch:
diff --git a/src/com/wsscode/pathom/connect.cljc b/src/com/wsscode/pathom/connect.cljc
index a6761dea..d0a2052d 100644
--- a/src/com/wsscode/pathom/connect.cljc
+++ b/src/com/wsscode/pathom/connect.cljc
@@ -1308,14 +1308,24 @@
   (cond-> (merge {::sym sym ::resolve resolve} options)
     transform transform))
 
-(defmacro defresolver [sym arglist config & body]
-  (let [fqsym (if (namespace sym)
+(defmacro defresolver [& args]
+  (let [{:keys [sym docstring arglist config body]}
+        (s/conform (s/cat
+                     :sym simple-symbol?
+                     :docstring (s/? string?)
+                     :arglist (s/coll-of any? :kind vector? :count 2)
+                     :config any?
+                     :body (s/* any?))
+                   args)
+        fqsym (if (namespace sym)
                 sym
-                (symbol (name (ns-name *ns*)) (name sym)))]
-    `(def ~sym
+                (symbol (name (ns-name *ns*)) (name sym)))
+        defdoc (cond-> [] docstring (conj docstring))]
+    `(def ~sym ~@defdoc
        (resolver '~fqsym
-         ~config
-         (fn ~sym ~arglist ~@body)))))
+                 (cond-> ~config
+                   ~docstring (assoc ::docstring ~docstring))
+                 (fn ~sym ~arglist ~@body)))))
 
 (defn attr-alias-name [from to]
   (symbol (str (munge (subs (str from) 1)) "->" (munge (subs (str to) 1)))))
@@ -1762,6 +1772,7 @@
   (s/fdef defresolver
     :args (s/cat
             :sym simple-symbol?
+            :docstring (s/? string?)
             :arglist (s/coll-of any? :kind vector? :count 2)
             :config any?
             :body (s/* any?)))


Test patch:
diff --git a/test/com/wsscode/pathom/connect_test.cljc b/test/com/wsscode/pathom/connect_test.cljc
index e88bfd10..1b2ba8ed 100644
--- a/test/com/wsscode/pathom/connect_test.cljc
+++ b/test/com/wsscode/pathom/connect_test.cljc
@@ -216,6 +216,17 @@
 
 (def indexes @base-indexes)
 
+(pc/defresolver sample-resolver-test
+  "documentation here"
+  [_ _]
+  {::pc/output [:hello]}
+  {})
+
+(deftest test-defresolver
+  (is (= (::pc/docstring sample-resolver-test)
+         (-> #'sample-resolver-test meta :doc)
+         "documentation here")))
+
 (deftest test-resolver-data
   (is (= (dissoc (pc/resolver-data indexes `user-by-id) ::pc/resolve)
          #::pc{:input  #{:user/id}
Repository: wilkerlucio/pathom
Pull request #92 (2019-04-26 03:07:03)

Convert sequential graphql params recursively.
Before:
```clojure
=> (query->graphql '[(:parameterized {:foo [a b]})])
"query { parameterized(foo: [\"a\",\"b\"]) }"
```
After:
```clojure
=> (query->graphql '[(:parameterized {:foo [a b]})])
"query { parameterized(foo: [a, b]) }"
```


Patch:
diff --git a/src/com/wsscode/pathom/graphql.cljc b/src/com/wsscode/pathom/graphql.cljc
index fac5e725..65cb75b7 100644
--- a/src/com/wsscode/pathom/graphql.cljc
+++ b/src/com/wsscode/pathom/graphql.cljc
@@ -45,6 +45,9 @@
          (str "(" params ")")
          (str "{" params "}")))
 
+     (sequential? x)
+     (str "[" (str/join ", " (mapv #(params->graphql % js-name tempid? false) x)) "]")
+
      (symbol? x)
      (name x)
 


Test patch:
diff --git a/test/com/wsscode/pathom/graphql_test.cljc b/test/com/wsscode/pathom/graphql_test.cljc
index 6faad106..88b82fb1 100644
--- a/test/com/wsscode/pathom/graphql_test.cljc
+++ b/test/com/wsscode/pathom/graphql_test.cljc
@@ -28,6 +28,8 @@
     ; params
     '[(:parameterized {:foo "bar"})] "query { parameterized(foo: \"bar\") }"
 
+    '[(:parameterized {:foo [a b]})] "query { parameterized(foo: [a, b]) }"
+
     ; aliasing
     '[(:property {::pg/alias "aliased"})] "query { aliased: property }"
     '[{(:property {::pg/alias "aliased" :another "param"})
Repository: wilkerlucio/pathom
Pull request #95 (2019-06-21 13:54:36)

Fixing ClassCastException in error-handler plugin
Hi,

we encountered  a weird bug during using Pathom in our services. We are using parallel-parsers with `key-process-timeout` set to 5000ms together with `error-handler-plugin`. We have couple of resolvers set up but when one of them times out (we are calling upstreams from them) on the highest level we get `ClassCastException` from `wrap-parser-exception` fn as the parser returns with `::p/reader-error` keyword return by `add-error` fn.
This is a pretty naive fix and does not fix the root cause as I believe the result of the parser should be always a map. But in order to fix that I would require a deeper knowledge of the code base and I just wanted to give a heads up that this issue exists.

Janos


Patch:
diff --git a/src/com/wsscode/pathom/core.cljc b/src/com/wsscode/pathom/core.cljc
index 65cbfef9..5ed6e2b6 100644
--- a/src/com/wsscode/pathom/core.cljc
+++ b/src/com/wsscode/pathom/core.cljc
@@ -828,7 +828,7 @@
   (fn wrap-parser-exception-internal [env tx]
     (let [errors (atom {})]
       (let-chan [res (parser (assoc env ::errors* errors) tx)]
-        (cond-> res
+        (cond-> (if (map? res) res {})
           (seq @errors) (assoc ::errors @errors))))))
 
 (def error-handler-plugin


Test patch:
diff --git a/test/com/wsscode/pathom/connect_test.cljc b/test/com/wsscode/pathom/connect_test.cljc
index 7788c966..23cfef33 100644
--- a/test/com/wsscode/pathom/connect_test.cljc
+++ b/test/com/wsscode/pathom/connect_test.cljc
@@ -3314,6 +3314,16 @@
                 [{[:id 123]
                   [:c :d]}]))))
 
+     (testing "global resolver times out"
+       (is (= {:com.wsscode.pathom.core/errors {nil "class clojure.lang.ExceptionInfo: Parallel read timeout - {:timeout 200}"}}
+              (quick-parser {::p/env       {::pp/key-process-timeout 200}
+                             ::pc/register [(pc/resolver 'a
+                                                         {::pc/input  #{}
+                                                          ::pc/output [:whatever]}
+                                                         (fn [_ _]
+                                                           {:whatever (Thread/sleep 210)}))]}
+                            [:whatever]))))
+
      (testing "rename ident reads"
        (is (= (async/<!!
                 (parser-p {}
Repository: evcc-io/evcc
Pull request #1624 (2021-09-23 12:36:27)

1p3p: fix switching and add more tests
@naltatis 


Patch:
diff --git a/core/loadpoint.go b/core/loadpoint.go
index 51d24c08..0a8c1914 100644
--- a/core/loadpoint.go
+++ b/core/loadpoint.go
@@ -803,16 +803,16 @@ func (lp *LoadPoint) updateChargerStatus() error {
 
 // effectiveCurrent returns the currently effective charging current
 func (lp *LoadPoint) effectiveCurrent() float64 {
+	if lp.GetStatus() != api.StatusC {
+		return 0
+	}
+
 	// adjust actual current for vehicles like Zoe where it remains below target
 	if lp.chargeCurrents != nil {
 		cur := lp.chargeCurrents[0]
 		return math.Min(cur+2.0, lp.chargeCurrent)
 	}
 
-	if lp.GetStatus() != api.StatusC {
-		return 0
-	}
-
 	return lp.chargeCurrent
 }
 
@@ -880,16 +880,17 @@ func (lp *LoadPoint) scalePhases(phases int) error {
 
 // pvScalePhases switches phases if necessary and returns if switch occurred
 func (lp *LoadPoint) pvScalePhases(availablePower, minCurrent, maxCurrent float64) bool {
-	var waiting bool
-
+	// correct charger state inconsistency (https://github.com/evcc-io/evcc/issues/1572)
 	phases := lp.GetPhases()
-	targetCurrent := availablePower / Voltage / float64(lp.activePhases)
 
-	// ignore charger state inconsistency if switchable (https://github.com/evcc-io/evcc/issues/1572)
-	if _, ok := lp.charger.(api.ChargePhases); !ok && phases < lp.activePhases {
-		lp.log.WARN.Printf("charger out of sync: %dp active @ %dp configured", lp.activePhases, phases)
+	if phases < lp.activePhases {
+		phases = 3
+		lp.setPhases(3)
 	}
 
+	var waiting bool
+	targetCurrent := availablePower / Voltage / float64(lp.activePhases)
+
 	// scale down phases
 	if targetCurrent < minCurrent && phases > 1 && lp.activePhases > 1 {
 		lp.log.DEBUG.Printf("available power below %dp min threshold of %.0fW", lp.activePhases, float64(lp.activePhases)*Voltage*minCurrent)


Test patch:
diff --git a/core/loadpoint_test.go b/core/loadpoint_test.go
index aace072f..b9defdc4 100644
--- a/core/loadpoint_test.go
+++ b/core/loadpoint_test.go
@@ -882,7 +882,16 @@ func TestScalePhases(t *testing.T) {
 		{"3/3->1, timer elapsed", 3, 3, 1 * Voltage * maxA, 1, true, func(lp *LoadPoint) {
 			lp.phaseTimer = lp.clock.Now().Add(-dt)
 		}},
-		{"3/3->1, switch executed", 1, 3, 1 * Voltage * maxA, 1, false, func(lp *LoadPoint) {
+
+		// error states from 1p/3p misconfig
+		{"1/3->1, enough power", 1, 3, 1 * Voltage * maxA, 3, false, nil},
+		{"1/3->1, kickoff, correct phase setting", 1, 3, 1 * Voltage * maxA, 3, false, func(lp *LoadPoint) {
+			lp.phaseTimer = time.Time{}
+		}},
+		{"1/3->1, timer running, correct phase setting", 1, 3, 1 * Voltage * maxA, 3, false, func(lp *LoadPoint) {
+			lp.phaseTimer = lp.clock.Now()
+		}},
+		{"1/3->1, switch executed", 1, 3, 1 * Voltage * maxA, 1, true, func(lp *LoadPoint) {
 			lp.phaseTimer = lp.clock.Now().Add(-dt)
 		}},
 	}