Fork me on GitHub
#pathom
<
2020-08-18
>
nivekuil07:08:43

this is probably a micro optimization but all my batch resolvers end like this:

(if (> (count input) 1)       (pc/batch-restore-sort {::pc/inputs ids ::pc/key :view/id} result)       result)
is there a better way of doing this pattern?

ak-coram07:08:10

I have a macro that takes a sort key and generates this (and is also doing some async error handling stuff)

mischov14:08:28

Has anybody used any kind of permissions based access control with pathom? If so, was it based on a library or framework, or did you roll your own? Anybody have any examples?

lgessler17:08:43

there's no library for this afaik, some discussion of this here: https://github.com/souenzzo/eql-style-guide/issues/4

šŸ‘ 3
lilactown18:08:35

whereā€™s the best place to look for implementing unions?

lilactown21:08:57

it doesnā€™t look the the source code in the docs for that demo, matches the demo query

wilkerlucio21:08:31

fixing it now

lilactown21:08:42

šŸ™:skin-tone-2: thanks!

wilkerlucio21:08:22

fixed šŸ‘

3
lilactown18:08:38

also, whatā€™s the best way to manually return a ā€œnot foundā€ value? return ::p/not-found? or is there a function I should call?

souenzzo20:08:45

@lilactown for not-found: do not return the key. Resolvers "maybe" return the keys in output. If none, it will be marked as not-found

wilkerlucio20:08:05

@lilactown you can return ::p/not-found directly as a way to short-circuit the thing, the difference will have in cases where there are multiple paths for that, that said, the preferred way is like @souenzzo said, dont return the key

lilactown20:08:04

Iā€™m not sure how to use the terminology correctly yet, so apologies if this is verbose. I have a resolver that I want to return a not-found value from

lilactown21:08:59

to reuse my folders example (because it is the same thing Iā€™m working on šŸ˜„ ) :

(pc/defresolver folder-tree-resolver
  [{:keys [db]} {:keys [::folder/id]}]
  {::pc/input #{::id}
   ::pc/output [{::tree (vec (concat file-keys folder-keys))}]}
  (let [files (list-files db)
        folders (list-folders db)
        children (filter (comp #(= % id) ::folder/parent) (concat files folders))]
    {::tree (if (empty? children)
              ::p/not-found ;; no children for this particular node
              (vec children))}))

lilactown21:08:09

so in this case, when a ::folder/id key exists in the context it will look up to see if any files or folders declare it a parent

lilactown21:08:45

in the case where it found no files or folders, I think itā€™s better to return ::p/not-found (and have it elided by the plugin) then an empty vec

wilkerlucio21:08:47

maybe something like this if I got right:

(pc/defresolver folder-tree-resolver
  [{:keys [db]} {:keys [::folder/id]}]
  {::pc/input #{::id}
   ::pc/output [{::tree (vec (concat file-keys folder-keys))}]}
  (let [files (list-files db)
        folders (list-folders db)
        children (filter (comp #(= % id) ::folder/parent) (concat files folders))]
    (if (seq children)
      {::tree (vec children)})))

wilkerlucio21:08:19

ok, should be right now

lilactown21:08:37

ahh so returning no map would be akin

wilkerlucio21:08:43

yeah, or empty map

lilactown21:08:21

cool! I figured it was strange to return the keyword. that helps, thanks!

wilkerlucio21:08:04

smaller tip, you can use filterv on the children

6