Skip to content

Instantly share code, notes, and snippets.

@zeitstein
Last active April 12, 2024 11:27
Show Gist options
  • Save zeitstein/683eabe72435b9cbbecc8f3d3a1cc01d to your computer and use it in GitHub Desktop.
Save zeitstein/683eabe72435b9cbbecc8f3d3a1cc01d to your computer and use it in GitHub Desktop.
(ns app.application
(:require
[com.fulcrologic.fulcro.application :as app]
[edn-query-language.core :as eql]
[com.fulcrologic.fulcro.algorithms.tx-processing :as txn]
[promesa.core :as p]
[com.wsscode.pathom3.interface.eql :as p.eql]
[com.wsscode.pathom3.connect.operation :as pco]
[com.wsscode.pathom3.connect.indexes :as pci]))
(def env (pci/register [your-resolvers-here]))
(def pathom (p.eql/boundary-interface env))
(defn pathom-remote [request]
{:transmit! (fn transmit! [_ {::txn/keys [ast result-handler]}]
(let [ok-handler (fn [result]
(try
(result-handler (assoc result :status-code 200))
(catch :default e
(js/console.error e "Result handler for remote failed with an exception."))))
error-handler (fn [error-result]
(try
(result-handler (assoc error-result :status-code 500))
(catch :default e
(js/console.error e "Error handler for remote failed with an exception."))))
key (-> ast :children first :key)
entity (some-> ast :children first :query meta :pathom/entity)
ident-ent {key (conj entity key)}]
(-> (p/let [res (request
(cond-> {:pathom/ast ast}
entity (assoc :pathom/entity ident-ent)))]
(ok-handler {:transaction (eql/ast->query ast)
:body res}))
(p/catch (fn [e]
(js/console.error "Pathom Remote Error" e)
(error-handler {:error e}))))))})
(defonce app (app/fulcro-app
{:remotes {:remote (pathom-remote pathom)}}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment