This page is not created by, affiliated with, or supported by Slack Technologies, Inc.
2018-07-09
Channels
- # beginners (20)
- # boot (4)
- # cider (2)
- # cljs-dev (25)
- # clojure (45)
- # clojure-dev (1)
- # clojure-greece (5)
- # clojure-italy (20)
- # clojure-nl (12)
- # clojure-russia (11)
- # clojure-uk (256)
- # clojurescript (176)
- # data-science (33)
- # datomic (47)
- # docs (1)
- # duct (13)
- # fulcro (54)
- # graphql (24)
- # hoplon (3)
- # jobs (1)
- # leiningen (32)
- # luminus (3)
- # midje (1)
- # mount (2)
- # off-topic (3)
- # onyx (5)
- # overtone (1)
- # parinfer (12)
- # pedestal (4)
- # re-frame (60)
- # reagent (11)
- # reitit (3)
- # ring-swagger (21)
- # rum (1)
- # shadow-cljs (16)
- # spacemacs (23)
- # tools-deps (19)
- # vim (79)
hi all, question: where do folks usually inject the datomic component into a lacinia system?
@curtosis Mine looks like (def web-routes (into [ ...some static routes... ] (map (fn [graphql-route] (update graphql-route 2 #(into [server/webapp-get-db server/check-auth set-error-response] %))))))
Although there's only one tiny reason to use pedestal, and it adds a bunch of heft for that one tiny reason. 😞
i see .. so your routes gets the server injected, and you call webapp-get-db to pull it out of there?
So there's a webapp component, which has all the dependencies needed by the pedestal stuff, (it doesn't do anything, just has dependencies).
(defn- insert-webapp-interceptor
"Returns a Pedestal interceptor that injects the web app component
into the request map as :webapp"
[webapp]
(interceptor
{:name ::insert-webapp
:enter (fn [context]
(assoc-in context [:request :webapp] webapp))}))
(def webapp-get-db
"Pedestal interceptor: Gets the current database value and assoc's
it into the Pedestal context as :request ::db. Uses the `:webapp`
component injected by twou.centralpark.server.server."
(interceptor/interceptor
{:name ::webapp-get-db
:enter (fn [ctx]
(let [database (get-in ctx [:request :webapp :database])]
(assoc-in ctx [:request ::db] (database/db database))))}))
The code was written well before I was on the project. Pedestal is actually not bad, but I think we didn't need it.
Our code very rarely relies on the injecting any data into the field resolver context; we mostly inject Component dependencies into the field resolvers themselves. We do a lot of validation and auth in the Pedestal interceptor chain before executing the GraphQL query.
I was happy to discover, by the way, that I could just reference resolver functions in the uncompiled schema, since our schema 90% computed from our data model description.