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?I have a macro that takes a sort key and generates this (and is also doing some async error handling stuff)
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?
there's no library for this afaik, some discussion of this here: https://github.com/souenzzo/eql-style-guide/issues/4
where’s the best place to look for implementing unions?
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?
@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
@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
https://wilkerlucio.github.io/pathom/v2/pathom/2.2.0/connect/resolvers.html#_union_queries
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
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))}))
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
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
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)})))
sorry
fixing itt
ok, should be right now
ahh so returning no map would be akin
yeah, or empty map
cool! I figured it was strange to return the keyword. that helps, thanks!
ty!
smaller tip, you can use filterv
on the children
it doesn’t look the the source code in the docs for that demo, matches the demo query
ups
fixing it now
🙏:skin-tone-2: thanks!
fixed 👍