This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-04-21
Channels
- # babashka (16)
- # beginners (182)
- # calva (13)
- # chlorine-clover (43)
- # clj-kondo (17)
- # cljs-dev (14)
- # cljsrn (19)
- # clojure (97)
- # clojure-argentina (7)
- # clojure-dev (45)
- # clojure-europe (7)
- # clojure-germany (5)
- # clojure-nl (4)
- # clojure-portugal (4)
- # clojure-romania (5)
- # clojure-spec (46)
- # clojure-uk (21)
- # clojuredesign-podcast (2)
- # clojurescript (159)
- # conjure (28)
- # core-async (7)
- # cursive (13)
- # datomic (17)
- # defnpodcast (9)
- # duct (1)
- # fulcro (45)
- # graphql (6)
- # jobs (7)
- # jobs-discuss (1)
- # juxt (3)
- # kaocha (4)
- # leiningen (12)
- # malli (5)
- # observability (1)
- # off-topic (50)
- # pathom (15)
- # re-frame (16)
- # reitit (5)
- # remote-jobs (21)
- # ring (7)
- # shadow-cljs (166)
- # test-check (6)
- # tools-deps (27)
- # xtdb (2)
Hi, I’m exploring the features of Pathom. I’m wondering is there a builtin way to merge independent queries during one request. E.g. I would have an html page with independent blocks.
[:div
[:div {:class "block 1"}
(q [:album/name
{:album/artist
[:artist/name]}])]
[:div {:class "block 2"}
(q [:album/name
{:album/tracks
[:track/name]}])]]
Ideally, I would render this page after collecting all queries, and do only one query to the server:
[:album/name
{:album/tracks
[:track/name]
:album/artist
[:artist/name]}]
After receiving the result of the server it could be split into seperate results for the seperate queries.
Does such an in-memory resolver already exist?Thanks, good to know. But is not part of Panthom? So I have to steal that there. (i’m not using Fulcro)
Maybe I’m looking for the Request cache
(mentioned in the introduction). I’ll have a read
Request cache: For caching the results of parsing repetition that can happen on a single request.
then that single EQL query resolution can be made more efficient inside Pathom using the request cache (and other techniques)
https://github.com/edn-query-language/eql/blob/master/src/edn_query_language/core.cljc#L532-L536
ah thanks
I’ll do some reading and give this a try later
@jeroenvandijk just "merge" your queries
(let [{:>/keys [a b]} (q [{:>/a [:album/name
{:album/artist
[:artist/name]}]}
{:>/b [:album/name
{:album/tracks
[:track/name]}]}])]
[:div
[:div {:class "block 1"}
a]
[:div {:class "block 2"}
b]])
Thank you. I’ll give it a try
Also you can use ::p/entity
(let [a (atom 0)
register [(pc/resolver
`a
{::pc/output [:a]}
(fn [_ _]
{:a (swap! a inc)}))]
parser (p/parser {::p/plugins [(pc/connect-plugin {::pc/register register})]})
env {::p/reader [p/map-reader
pc/reader2
pc/open-ident-reader
p/env-placeholder-reader]
::p/placeholder-prefixes #{">"}}
->cache (fn [parser]
(let [entity (atom {})]
(fn [tx]
(parser (assoc env ::p/entity entity)
tx))))
single-use-cached-parser (->cache parser)]
[:without-cache [:div
(parser env [:a])
(parser env [:a])]
:with-cache [:div
(single-use-cached-parser [:a])
(single-use-cached-parser [:a])]])