Fork me on GitHub
#datahike
<
2022-02-28
>
awb9901:02:46

Did someone experiment with pantom3 and datahike? I have seen a datomic pantom3 library. What I realized after building my firat datahike app is that there are many situations where that might make sense. An area where I sort of struggle with the datahike api are situations when I add calculated properties to queries. I didn't find a good way to code that. Also I believe pantom3 comes in handy when coding resolvers. And of course it would be huge if we could query graphql apis and datahike from the same queries.

Björn Ebbinghaus14:02:25

I use pathom2 with datahike and will migrate to pathom3 as soon as I have time for it. The datomic-pathom libraries are a neat experiment, but there are many drawbacks… Mostly around access control. Back to your initial problem: What exactly are your problems with calculated properties? Here is an example of function calls in a datahike query used for searching users by substring:

(defn search-for-user [db search-term]
  (d/q '[:find [(pull ?e [::user/id ::user/display-name]) ...]
         :in $ ?search-term
         :where
         [?e ::user/display-name ?dn]
         [(clojure.string/lower-case ?dn) ?lc-dn]
         [(clojure.string/lower-case ?search-term) ?lc-?search-term]
         [(clojure.string/includes? ?lc-dn ?lc-?search-term)]]
    db (str search-term))) 

; and because you asked for pathom: here the resolver where the function above is used.
(defresolver autocomplete-user [{:keys [db] :as env} _]
  {::pc/params [:term :limit]
   ::pc/output [{:autocomplete/users [::user/id ::user/display-name]}]}
  (let [{:keys [term limit] :or {limit 3}} (-> env :ast :params)
        limit (min limit 5)]
    {:autocomplete/users
      (take limit (search-for-user db term))}))
https://github.com/hhucn/decide3/blob/334f691059ffeabaceed2567502a12bfd8fa8b81/src/main/decide/models/user/api.clj#L14

Björn Ebbinghaus14:02:12

Looking at the code right now... I should query the entity ids first, then limit them, then pull the data...

Björn Ebbinghaus14:02:34

@UCSJVFV35 Another thing about calculated properties… Have you looked at https://docs.datomic.com/cloud/query/query-data-reference.html#rules? They are a great way to have reusable logic in your queries.

awb9922:02:36

Thanks for the rules pointer. A great idea !

awb9923:02:56

I did develop webly, and it can deal with oauth2 tokens, and it has a authentication and authorization layer.

awb9923:02:18

The app I developed I use http://github.com/pink-gorilla/goldly with datahike.

awb9923:02:22

And of course full access control.