This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2020-03-04
Channels
- # aleph (8)
- # aws (14)
- # babashka (37)
- # beginners (30)
- # calva (5)
- # cider (4)
- # clj-kondo (21)
- # cljsrn (4)
- # clojure (234)
- # clojure-denmark (1)
- # clojure-europe (10)
- # clojure-france (10)
- # clojure-italy (4)
- # clojure-nl (17)
- # clojure-sanfrancisco (1)
- # clojure-spec (8)
- # clojure-uk (44)
- # clojurescript (20)
- # cursive (9)
- # datascript (2)
- # datomic (5)
- # emacs (9)
- # fulcro (50)
- # graalvm (32)
- # jackdaw (18)
- # leiningen (1)
- # malli (10)
- # meander (10)
- # nrepl (10)
- # off-topic (15)
- # pathom (20)
- # re-frame (14)
- # reagent (37)
- # reitit (7)
- # ring (1)
- # shadow-cljs (102)
- # test-check (6)
- # tree-sitter (15)
- # vim (4)
- # xtdb (2)
- # yada (1)
Let's say I have a query like [{[:person/id "
How do I get access to [:person/name]
in my resolver? I have a resolver like:
(pc/defresolver person-resolver
[env {:keys [person/id] :as params}]
{::pc/input #{:person/id}
::pc/output [:person/name :person/email]}
...)
and I don't see where I could grab this out of env
@tvaughan in the resolver you described, you have to provide the :person/name
, if you want to use :person/name
as input for something, you can create another resolver that depends on it, makes sense?
> makes sense?
No, sorry. I mean a client can submit a query like: [[:person/id 42]]
which means "return everything" or [{[:person/id 42][:person/name]}]
which means "return only :person/name
. Right now the resolver returns everything and Pathom returns only what has been requested. However, in my resolver I don't want to fetch everything, I only want to fetch what the client requested. Which means my resolver needs to know what the client sent beyond just the person id. How?
for instance I do
(reduce (fn [acc field]
(conj acc (if (keyword? field)
field
(first (first field)))))
#{}
parent-query)
to then only select those fields in my sql queryReturn basead on parent-query
isn't always a good solution
It may kill the "connect superpowers"
(let [register [(pc/resolver
`user-by-id
{::pc/input #{:user/id}
::pc/output [:user/email
:user/name]}
(fn [{::p/keys [parent-query]} {:user/keys [id]}]
(-> {:user/email (str id "@example.com")
:user/name (str id)}
(p/map-select parent-query))))
(pc/resolver
`slug-by-email
{::pc/input #{:user/email}
::pc/output [:user/slug]}
(fn [env {:user/keys [email]}]
{:user/slug (first (string/split email #"@"))}))]
parser (p/parser {::p/plugins [(pc/connect-plugin {::pc/register register})]})
env {::p/reader [p/map-reader
pc/reader2
pc/open-ident-reader]}]
(parser env `[{[:user/id 42] [:user/name
:user/slug
:user/id
#_:user/email]}]))
Thanks @U2J4FRT2T This is what I have now:
(pc/defresolver person-resolver
[{:keys [::p/parent-query] :as env} {:keys [person/id] :as params}]
{::pc/input #{:person/id}
::pc/output [:person/name :person/email]}
(datomic/q-by-ident (datomic/conn->db conn) [:person/email id] parent-query))
I already used it in a project and I moved back to (d/pull db (-> env ::pc/resolver-data ::pc/output) ei )
after some connect issues
for me that is not an option the resolver is doing a composed sql query with different aggregates to limit roundtrips to the db server
Oh, it seems as though Pathom doesn't support a query like my first example: [[:person/id 42]]
, right? Instead Pathom requires queries like my second example: [{[:person/id 42][:person/name :person/preferred-pronouns]}]
, correct? A query like [[:person/id 42]]
doesn't trigger the person/id resolver
@tvaughan exactly, pathom only loads things that the user requires, you may have dozens of resolvers that can get something from :person/id
, Pathom optimizes to fulfill the client demand (which should be precise, the EQL request must be explicit about what it wants, by design)