Fork me on GitHub
#pathom
<
2019-02-14
>
mss19:02:38

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?

hmaurer19:02:06

@mss try

(pc/defresolver user-data [env params]
  {::pc/input  #{:db/id}
   ::pc/output [:user/name :user/email]}
  ...)

hmaurer19:02:10

will explain later why

hmaurer19:02:04

@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

👍 5
hmaurer19:02:35

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 want

hmaurer19:02:56

What 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]}
  ...)

hmaurer19:02:41

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 🙂

👍 5
hmaurer19:02:26

(that’s the answer to your second question)

hmaurer19:02:19

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]}])

mss19:02:07

that makes perfect sense, knew I was hung up on something simple like that. really appreciate the help

hmaurer19:02:36

no worries 🙂 i had similar questions when I started learning Pathom