hi, I'm trying to implement some simple authentication via a pathom transform and i'm having some trouble when I want to return something that's not a result of calling resolve
. putting code in reply
yes, looks strange, what parser and reader are you using?
p/parser
and pc/parallel-reader
: https://github.com/lgessler/glam/blob/master/src/main/glam/server/pathom_parser.clj#L46
i'll try the sync reader in a sec and see what happens
confirmed that it doesn't crash with pc/reader
, though the return value is [{:all-users {}}]
instead of {:server/error? true :server/message "..."}
for some reason... anyway, it seems like it succeeds in preventing the call to the resolver to run, so this is good enough 🙂 the error message getting to the client isn't really important anyway
would still be curious to know what i was doing wrong though... and i don't understand how big the perf difference is between parallel-reader and reader but i hope it's not terribly great
thanks for the help @wilkerlucio!
yeah, with the parser you should use the reader2, parallel-reader is only compatible with parallel-parser, this should fix the issue :)
sorry the messy confusion around parsers and readers, thats I pain point I plan to fix
ok great, thanks! also wow i just realized i had both parallel-reader and reader2 in my ::p/reader... i'm surprised that worked at all 😅
they work in a chain processing, so a reader can operate or delegate to the next, if you have then, what would happen is that the first would pick up
so I define my transform:
(defn auth-tx [{::pc/keys [resolve] :keys [auth] :as outer-env}]
"Transform for a Pathom resolver that checks whether the user has sufficient permissions
for a given operation. Checks the resolver's env for the :auth keyword, which can
currently be either :user or :admin"
(assoc
outer-env
::pc/resolve
(fn [env params]
(if (authorized env auth)
(resolve env params)
{:server/error? true :server/message "..."}))))))
and then I put it on my resolver:
(pc/defresolver all-users-resolver [{:keys [neo4j]} _]
{::pc/output [{:all-users [:user/id]}]
::pc/transform mc/auth-tx
:auth :admin}
;;...
)
when the user is authorized to perform the action, everything works OK, but if they're not, I get an error: Exception in thread "async-dispatch-15" java.lang.IllegalArgumentException: No implementation of method: :take! of protocol: #'clojure.core.async.impl.protocols/ReadPort found for class: clojure.lang.PersistentArrayMap
I'm confused because as far as I can tell (resolve env params)
is just returning a plain map--when I replace it with {:all-users []}
I don't get this :take!
error. so shouldn't it be OK for me to return that map literal in the non-authorized case? is there some kind of function i need to use to wrap it?