graphql

Daniel Stephens 2021-06-29T15:48:04.042100Z

@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))
                                                                             distinct
                                                                             seq)]
                                                    (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

đź‘Ť 1
Daniel Stephens 2021-06-29T15:50:08.042200Z

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 https://walmartlabs.github.io/apidocs/lacinia/com.walmartlabs.lacinia.schema.html so I assume it's considered 'supported'

2021-06-29T16:00:50.042400Z

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.

đź‘Ť 1
2021-06-29T17:50:52.042900Z

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