This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2021-06-29
Channels
- # adventofcode (8)
- # babashka (12)
- # beginners (91)
- # calva (6)
- # cider (2)
- # circleci (11)
- # clj-kondo (19)
- # clojure (202)
- # clojure-australia (7)
- # clojure-brasil (1)
- # clojure-europe (123)
- # clojure-nl (2)
- # clojure-poland (24)
- # clojure-uk (6)
- # clojured (1)
- # clojurescript (91)
- # core-async (23)
- # cursive (16)
- # data-science (5)
- # datomic (26)
- # emacs (27)
- # events (2)
- # graalvm-mobile (50)
- # graphql (4)
- # honeysql (4)
- # instaparse (33)
- # lsp (24)
- # meander (22)
- # nrepl (3)
- # off-topic (26)
- # pedestal (1)
- # re-frame (15)
- # releases (1)
- # sci (1)
- # shadow-cljs (20)
- # tools-deps (22)
@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👍 2
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'
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
Oh nice, I didn’t know of that option either