clojure-hungary

onetom 2020-02-19T02:32:43.032600Z

tegnap raneztem erre az app-state management / DI libre: https://github.com/juxt/clip korabban hasznaltam elesben stuartsierra/component-et, meg probalkoztam a mount-al es a mount-lite-al, meg a yourt-al is. duct-ot nem is probaltam mert ranezesre is tul bobeszedunek tunt. ez a clip viszont nagyon biztato! kicsit trukkosek az evaluation rule-jai, viszont azon tul nagyon tomor es egyertelmu szerintem.

onetom 2020-02-19T02:34:26.034100Z

tegnap pl egy ilyen teszt rendszert raktam ossze vele, ami egy datomic+graphql+http rendszert inicializal:

(ns xxx.system
  (:require
    [juxt.clip.core :as clip]
    [xxx.datomic :as datomic]
    [datomic.api :as d]
    [com.walmartlabs.lacinia.schema :as lacinia.schema]
    [com.walmartlabs.lacinia.pedestal :as lacinia.pedestal]
    [xxx.graphql.schema :as gql.schema]
    [io.pedestal.http :as http]))

(defmacro with
  [[bound-var binding-expr] & body]
  `(let [system-config# ~binding-expr
         ~bound-var (clip/start system-config#)]
     (try
       ~@body
       (finally
         (clip/stop system-config# ~bound-var)))))

(def datomic
  {:datomic/uri
   {:start `datomic/random-mem-db-uri}

   :datomic/conn
   {:pre-start  `(d/create-database (clip/ref :datomic/uri))
    :start      `(d/connect (clip/ref :datomic/uri))
    :post-start `(d/transact (clip/ref :datomic/conn) (datomic/schema))}})

(def graphql
  {:graphql/schema-fn
   {:start (constantly #(gql.schema/compile (gql.schema/inline)))}})

(def web-service
  {:pedestal/service-map
   {:start `(lacinia.pedestal/service-map
              (clip/ref :graphql/schema-fn)
              {:graphiql false})}

   :pedestal/server
   {:start `(http/create-server (clip/ref :pedestal/service-map))}})

(def http
  {:http/service
   {:start `(::http/service-fn (clip/ref :pedestal/server))}

   :http/server
   {:start `(http/start (clip/ref :pedestal/server))
    :stop  `http/stop}})

(def test
  {:components (merge datomic graphql web-service http)})

(comment

  (def sys (clip/start config))
  (clip/stop config sys)

  (with [sys config]
        (:datomic/conn sys))

  (let [sys (clip/start config)
        {:keys [graphql/schema-fn]} sys]
    [config sys (lacinia.schema/compiled-schema? (schema-fn))])

  )

  )

onetom 2020-02-19T02:40:38.036Z

a #juxt channel-en a @dominicm mar reagalt is es jo 5letnek tartja h legyen egy ilyen with macro is a library-ben out of the box, ugyhogy pl konnyen tud vele az ember kulonbozo integracios szintu test-eket inicializalni.

onetom 2020-02-19T02:45:00.038400Z

(use-fixtures
    :each (fn [test]
            (with [sys {:components (merge datomic graphql)}]
                  (test))))
ennek segitsegevel pl tudjuk a rendszer magjat tesztelni, mindenfele figyelemelvono http reteg nelkul ugy, h a tesztek mindig egy izolalt tiszta rendszeren futnak.