Fork me on GitHub
#pathom
<
2019-10-19
>
Spencer Apple05:10:21

Hey! Thanks for your work on Pathom! I am struggling with two things and if you have some time I would love some help. 1. what's the best way to pass a request env (like ring's) into pathom?

;; I call this api-parser via the fulcro websockets networking
(defn api-parser
  ([query] (pathom-parser {} query))
  ([env query]
   ;; should I just pass the env directly here?
   (pathom-parser {:user (:user (:request env))} query)))
2. I have the following resolvers and am making a query which to me makes sense, but it's not returning my room.
(pc/defresolver room-resolver [env input]
  {::pc/input #{:room/id :user/id}
   ::pc/output [:room/id
                :room/status]}
  (util/log "calling room-resolver")
  (get-in @state/room-table [(:user/id input) (:room/id input)]))

(pc/defresolver user-resolver [env input]
  {::pc/output [:user/id]}
  {:user/id :base-state})
Then I can run the query which finds the user-resolver but not the room resolver
(api-parser [:user/id {[:room/id :] [:room/id :room/status]}])
;; => {:user/id :base-state, [:room/id :] :com.wsscode.pathom.core/not-found}
My understanding is that pathom should realize that the room resolver can be fulfilled since there is a :user/id and :room/id. Any ideas?

wilkerlucio12:10:14

@cjsauer yes, you can query for the indexes, that's how the auto-complete for queries currently works, it downloads the indexes and show it, there is also the index explorer: https://wilkerlucio.github.io/pathom/v2/pathom/2.2.0/connect/exploration.html

metal 4
wilkerlucio12:10:22

@splayemu to send stuff to env, use the first argument of the parser, as you used, I suggest you pass the whole request, like: (pathom-parser {::request request} [...])

wilkerlucio12:10:37

also, remember to use qualified keywords to avoid collisions

wilkerlucio12:10:47

about the resolvers, they look strange as is

wilkerlucio12:10:18

::pc/input #{:room/id :user/id} is not a good way, you are making a dependency hard to reach, if you can use a single id would be great (and have normalized structures to request from)

Spencer Apple17:10:49

Thanks, yeah as you suggested, it does make sense to use a single id. I turned it into a single id and built a resolver to combine the user-id and room-id:

(pc/defresolver user-room-resolver [env {:keys [room/id]}]
  {::pc/input #{:room/id}
   ::pc/output [:user-room/id]}
  (let [user-id (-> env :user :user/id)]
    {:user-room/id [user-id id]}))