Fork me on GitHub
Daniel Stephens15:06:04

@tlonist.sang I've done something similar, making use of the :apply-field-directives option on schema/compile. This isn't the exact code but it basically goes like this

(schema/compile schema {:apply-field-directives (fn [field field-resolver]
                                                  (let [directives (:directives field)
                                                        required-scopes (->> directives
                                                                             (filter #(= :required-scope (:directive-type %)))
                                                                             (map (comp :scope :directive-args))
                                                    (fn [{:keys [user] :as ctx} args parent]
                                                      (if (has-scopes? user required-scopes)
                                                        (field-resolver ctx args parent)
                                                        (throw auth-error)))))})
It's a bit more automatic than manually wrapping each resolver

👍 2
Daniel Stephens15:06:08

it was kind of hard to track down that option, I expected to find it on the page you linked, but came across it here so I assume it's considered 'supported'


cool. this can be a workaround! I think the documentation needs a lot more update.. it’s frustrating when the only source of truth is lacking in content.

👍 2
Lennart Buit17:06:52

Oh nice, I didn’t know of that option either