Fork me on GitHub
#graphql
<
2021-06-28
>
tlonist08:06:32

I’m trying to use directives for authentication purpose. Has anybody ever tried this using lacinia?

Lennart Buit09:06:26

Well kinda, we have a @possibleTypes directive (like GH also has) and we have a function that wraps a lacinia resolver fn and checks those types / if all is right calls the actual resolver.. But there is nothing automatic here, you really need to remember to wrap your resolver

Lennart Buit09:06:01

So like this:

(defn with-possible-type-check
  [resolver-fn]
  (fn [ctx args val]
     (if (possible-types-correct? ctx args val)
       (resolver-fn ctx args val)
       (resolve-as nil {:message "Nope"}))))

👍 2
Lennart Buit09:06:22

Here be dragons tho, in possible-types-correct? we navigate the parsed directives in ctx, that isn’t promised to be stable, so breaking is on us 😉