This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2019-02-14
Channels
- # announcements (1)
- # beginners (206)
- # calva (2)
- # cider (64)
- # cljs-dev (12)
- # clojars (2)
- # clojure (177)
- # clojure-europe (2)
- # clojure-finland (1)
- # clojure-italy (2)
- # clojure-losangeles (5)
- # clojure-nl (7)
- # clojure-russia (69)
- # clojure-spec (41)
- # clojure-uk (92)
- # clojurescript (60)
- # core-async (16)
- # cursive (48)
- # data-science (6)
- # datomic (73)
- # duct (5)
- # events (2)
- # figwheel-main (5)
- # fulcro (29)
- # hoplon (1)
- # off-topic (52)
- # pathom (11)
- # reagent (4)
- # reitit (5)
- # remote-jobs (1)
- # rum (7)
- # shadow-cljs (58)
- # slack-help (10)
- # spacemacs (3)
- # testing (3)
- # tools-deps (5)
a little bit confused about how resolvers are resolved under-the-hood. I have two resolvers that roughly look like:
(pc/defresolver user-data [env params]
{::pc/input #{:db/id}
::pc/output [{:user [:user/name :user/email]}]}
...)
(pc/defresolver current-user [env params]
{::pc/output [{:user [:db/id :user/authenticated?]}]}
{:user {:db/id 123
:user/authenticated? true}})
I elided a lot of internals, but the rough idea is that the current-user
resolver pulls a db/id
, and that db/id
is then fed into further resolvers. for whatever reason, though, I seem to be getting the following result:
(my-parser [{:user [:db/id :user/authenticated? :user/name :user/email]}]) =>
{:user {:db/id 123, :user/authenticated? true, :user/name :com.wsscode.pathom.core/not-found, :user/email :com.wsscode.pathom.core/not-found}}
so, two questions:
1) why are does the user-data
resolver not seem to be getting invoked? what am I missing here?
2) is there a way to say which db/id
should be used in a resolver? right now the input
for the user-data
resolver is just #{:db/id}
. I assume there’s some method of distinguishing {:user [:db/id]}
vs {:something-else [:db/id]}
, or is there not? is that computed based on the output of the resolver?@mss try
(pc/defresolver user-data [env params]
{::pc/input #{:db/id}
::pc/output [:user/name :user/email]}
...)
@mss alright I am back. The short explanation is that you have an extra level of nesting in the output to your user-data
resolver, as I pointed out above with the edited code example. According to your query you want to derive a :user/name
and :user/email
from a :db/id
, but your user-data
resolver allows you to derive a map from your a :db/id
which has the :user/name
and :user/email
attributes
The following query would work:
(my-parser [{:user [:db/id :user/authenticated? {:use [r:user/name :user/email]}]}])
but it’s clearly not what you wantWhat you should do instead is have a flat resolver, e.g.
(pc/defresolver user-data [env params]
{::pc/input #{:db/id}
::pc/output [:user/name :user/email]}
...)
Also note that you should probably use :user/id
for the ID, and not :db/id
. If you use :db/id
then you can’t differentiate between different kinds of IDs. Surely you can’t derive a :user/name
from any ID, but only from a ID that is pointing to a user 🙂
So to put it all together, I would have this:
(pc/defresolver user-data [env params]
{::pc/input #{:user/id}
::pc/output [:user/name :user/email]}
...)
(pc/defresolver current-user [env params]
{::pc/output [{:current-user [:user/id :user/authenticated?]}]}
{:current-user {:user/id 123
:user/authenticated? true}})
and as query:
(my-parser [{:current-user [:user/id :user/authenticated? :user/name :user/email]}])