I've created an om.next server-side endpoint, and I have some questions about the parameters that are passed to it. I know that a reader function is passed environment map, dispatch key, and params.
Let's say I issue a query like [:credentials/by-email "[email protected]"]. The environment map is: {:db-conn #object[datomic.peer.Connection 0x79ee17f4 "{:unsent-updates-queue 0, :pending-txes 0, :next-t 1047, :basis-t 1046, :index-rev 0, :db-id \"villarrica-f820249e-969d-4246-9508-5002c8f113be\"}"], :parser #object[om.next.impl.parser$parser$self__1866 0x38477e12 "om.next.impl.parser$parser$self__1866@38477e12"], :target nil, :query-root [:credentials/by-email "[email protected]"], :path [], :ast {:type :prop, :dispatch-key :credentials/by-email, :key [:credentials/by-email "[email protected]"]}} Where I added :db-conn and everything else was added by om.next. (Links to documentation about this environment map would be really appreciated.) The dispatch key is :credentials/by-email, and the params is null. But if I issue a query like: (:credentials/by-email {:email "[email protected]"}), the environment map is: {:db-conn #object[datomic.peer.Connection 0x79ee17f4 "{:unsent-updates-queue 0, :pending-txes 0, :next-t 1047, :basis-t 1046, :index-rev 0, :db-id \"villarrica-f820249e-969d-4246-9508-5002c8f113be\"}"], :parser #object[om.next.impl.parser$parser$self__1866 0x38477e12 "om.next.impl.parser$parser$self__1866@38477e12"], :target nil, :query-root :om.next/root, :path [], :ast {:type :prop, :dispatch-key :credentials/by-email, :key :credentials/by-email, :params {:email "[email protected]"}}} The dispatch key is :credentials/by-email, and params is {:email "[email protected]"}. I'm only asking as a matter of clarification, to be sure I haven't screwed something up, not as a criticism. My assumption was that in both cases the email address would be somewhere in params. But it's not in the case of a lookup ref. For a lookup ref, the proper place to get the email address would be (-> environment-map :query-root second), right? This is with om.next 1.0.0-apha36. Full disclosure, what I have looks something like: (POST "/" [:as request] (api {:db-conn db-conn} (:body-params request))) (defmulti readf om/dispatch) (defmethod readf :default [_ k _] {:value {:error (str "No read handler for " k)}}) (defmethod readf :credentials/by-email [{:keys [db-conn query-root query]} _ _] {:value (datomic/pull (datomic/db db-conn) (or query '[*]) [:credentials/email (second query-root)])}) (def parser (om/parser {:read readf})) (defn api [env params] (response (parser env params))) Where the readf assumes a lookup ref. Thanks! Also, what's the point of returning the result as {:value result}? What other keys could there be in this map? -- Note that posts from new members are moderated - please be patient with your first post. --- You received this message because you are subscribed to the Google Groups "ClojureScript" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at https://groups.google.com/group/clojurescript.
