Fork me on GitHub
#graphql
<
2019-02-21
>
erwinrooijakkers13:02:25

Does anyone understand the code in https://lacinia.readthedocs.io/en/latest/tutorial/designer-data.html:

(defn resolve-board-game-designers
  [designers-map context args board-game]
  (->> board-game
       :designers
       (map designers-map)))

erwinrooijakkers13:02:02

designers-map:

{"200" {:id "200", :name "Kris Burm", :url ""}, "201" {:id "201", :name "Antoine Bauza", :url ""}, "202" {:id "202", :name "Bruno Cathala", :url ""}, "203" {:id "203", :name "Scott Almes"}, "204" {:id "204", :name "Donald X. Vaccarino"}}
(:designers board-game):
#{"201" "202"}

erwinrooijakkers13:02:36

So (map designers-map #{"201" "202"})

erwinrooijakkers13:02:46

;; =>
({:id "201", :name "Antoine Bauza", :url ""} {:id "202", :name "Bruno Cathala", :url ""})

erwinrooijakkers13:02:39

user> (map {:a "a" :b "b" :c "c"} #{:a :b})
("b" "a")

erwinrooijakkers13:02:16

Mapping a map over a set leads to the keys of that set extracted out of the map, which is logical

erwinrooijakkers13:02:20

Okay ๐Ÿ™‚

๐Ÿ˜€ 1
๐Ÿ‘ 1
hlship14:02:08

Maps can acts like functions ... but perhaps the code in the tutorial is a bit too concise.

erwinrooijakkers14:02:39

Yes I see now it uses (my-map <:key>), but I find it more usual to call it other way around, and to me it was not clear that (:designers board-game) was a set of numberstrings.

erwinrooijakkers14:02:09

So I thought it was doing some set/map magic I did not know yet

erwinrooijakkers14:02:45

But I am very happy with the example

erwinrooijakkers16:02:12

Really really nice tutorial. Thanks!

Lennart Buit19:02:31

So today I tried to implement the node query as specified by the relay specification, I was wondering whether other people are doing the same in Lacinia, and what the best way is to combat code duplication between โ€œnormalโ€ query fields and retrieving entities using the node query

Lennart Buit19:02:32

I basically kinda created a big switch case for schema types, go to the database to retrieve my entity and convert it to the expected value but the last step is duplicated amongst all different ways you can retrieve the same type of entities