Fork me on GitHub
#fulcro
<
2022-02-27
>
Ryan Khetlyr15:02:45

I'm going through the https://github.com/fulcrologic/video-series and at full-stack-1 I was hoping to get an all-cars resolver set up - maybe someone can see what I'm missing? I get

Ryan Khetlyr15:02:10

In app.model.car I added:

(pc/defresolver all-cars-resolver [env {:car/keys [id]}]
                {::pc/output [{:all-cars [:car/id]}]}
                {:all-cars
                 (mapv (fn [i] {:cars/id i}) (keys @cars))})

(def resolvers [car-resolver all-cars-resolver])

Ryan Khetlyr15:02:48

tried (restart) in the repl and then a full shutdown and re-load of the IDE to see if that was the issue...

sheluchin15:02:41

Your ::pc/output doesn't match what you are returning.

👀 1
Ryan Khetlyr18:03:18

still fighting with this... I thought that the other data would get returned from the other resolver... here's what I've got now, still not found

(def cars
  (atom {1 {:car/id    1
            :car/make  "Honda"
            :car/model "Accord"}
         2 {:car/id    2
            :car/make  "Ford"
            :car/model "F-150"}}))

(pc/defresolver car-resolver [env {:car/keys [id]}]
  {::pc/input  #{:car/id}
   ::pc/output [:car/id :car/make :car/model]}
  (get @cars id))

(pc/defresolver all-cars-resolver [env {:car/keys [id]}]
                {::pc/output [{:all-cars [:car/id :car/make :car/model]}]}
                {:all-cars
                 (mapv (fn [i] {:cars/id i}) (keys @cars))})

Ryan Khetlyr18:03:59

trying to get this to work like people does - this one works great

(pc/defresolver person-resolver [env {:person/keys [id]}]
  {::pc/input  #{:person/id}
   ::pc/output [:person/name :person/age {:person/cars [:car/id]}]}
  (let [person (-> @people
                 (get id)
                 (update :person/cars (fn [ids] (mapv
                                                  (fn [id] {:car/id id})
                                                  ids))))]
    person))

(pc/defresolver all-people-resolver [env {:person/keys [id]}]
  {::pc/output [{:all-people [:person/id]}]}
  {:all-people
   (mapv (fn [i] {:person/id i}) (keys @people))})

sheluchin18:03:19

What will (mapv (fn [i] {:cars/id i}) [1 2 3]) return?

Ryan Khetlyr20:03:02

Ugh - Thanks so much for your help! in the return I should have had :car/id, not :cars/id

sheluchin20:03:55

Fulcro's two golden rules: 1. Make sure the query is correct 2. Make sure everything is spelled correctly Good luck!