Skip to content

Instantly share code, notes, and snippets.

@cyppan
Last active November 5, 2021 08:47
Show Gist options
  • Save cyppan/bbdfdb16d267051ad1e675c4a38ced5f to your computer and use it in GitHub Desktop.
Save cyppan/bbdfdb16d267051ad1e675c4a38ced5f to your computer and use it in GitHub Desktop.
(ns dev.pathom-playground
(:require [com.wsscode.pathom3.connect.indexes :as pci]
[com.wsscode.pathom3.connect.operation :as pco]
[com.wsscode.pathom3.interface.eql :as p.eql]))
;; that one works fine
(pco/defresolver timezone-resolver [item]
{::pco/input [:timezone/id]
::pco/output [:timezone/label]}
{:timezone/label (str "label for id " (:timezone/id item))})
;; that one (batched) is buggy
(pco/defresolver timezone-batch-resolver [items]
{::pco/input [:timezone/id]
::pco/output [:timezone/label]
::pco/batch? true}
(mapv (fn [item]
{:timezone/label (str "label for id " (:timezone/id item))})
items))
(pco/defresolver item-checks [item]
{::pco/input [{(pco/? :item/timezone) [:timezone/id :timezone/label]}]
::pco/output [:item/checks]}
{:item/checks {:timezone-id? (some? (get-in item [:item/timezone :timezone/id]))
:timezone-label? (some? (get-in item [:item/timezone :timezone/label]))}})
(comment
;; KO, timezone/label is not resolved
(p.eql/process
(pci/register [timezone-batch-resolver
item-checks])
{:item/name "my item"
:item/timezone {:timezone/id "UTC"}}
[:item/checks])
;; => #:item{:checks {:timezone-id? true, :timezone-label? false}}
;; OK, both timezone/id and timezone/label are found
(p.eql/process
(pci/register [timezone-resolver
item-checks])
{:item/name "my item"
:item/timezone {:timezone/id "UTC"}}
[:item/checks])
;; => #:item{:checks {:timezone-id? true, :timezone-label? true}}
)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment