Fork me on GitHub
#datomic
<
2019-05-26
>
hadils20:05:41

Hi! I am trying to use lacinia-pedestal as an Lambda function datomic ion. Does anyone have any suggestions on how to do this? Here's some example code:

(defn web-handler*
  []
  (-> (load-schema)
      (service-map {:graphiql false})
      http/create-server
      http/start))

(def web-handler
  (apigw/ionize web-handler*))
The error message I get is: Wrong number of args (1) passed to: stackz.graphql/web-handler* This is because web-handler* is being passed the request argument.

kardan20:05:50

I know nothing about lancia-pedestal but I would guess that you don’t need to start any http server but just go straight to the web handler. Maybe that means to skip the last two threaded function calls so what you ionize is (service-map …)

kardan20:05:01

And I guess web-handler* should not be a fn but something like (def web-handler* (service-map (load-schema) {:graphical false})

kardan20:05:22

Might be totally wrong. I had wine and should go to bed 😇

hadils20:05:26

Thanks! Would this be true for http direct as well?

lilactown20:05:27

Afaict yes. The api gateway essentially serves as the http layer in this case

lilactown20:05:46

You’ll need to do some work to map the Lacinia service-map to the ions req/res format

lilactown20:05:56

You might want to look at using lacinia directly instead of lacinia-pedestal

hadils20:05:21

Thanks a lot! I might just use the interceptor functionality in pedestal

lilactown20:05:12

yes, that would be good too I just couldn’t find an easy example of that

hadils20:05:04

Maybe if I just don’t start the server...

hadils21:05:15

There is code in the pedestal/pedestal github repo for AWS Lambda functions with API Gateway…

Joe Lane22:05:29

@hadilsabbagh18 You’re going to want something like this for your ion, then you’ll need a dev namespace so that in dev you create a local jetty server.

(def the-schema
  (-> (io/resource "graphql/schema.edn")
      slurp
      edn/read-string
      (util/attach-resolvers {
                              :query/Moments                                   moments ;;a resolver function
                              :mutation/create-moment                          create-moment ;; another resolver that does mutations
                              })
      schema/compile))

(def service (-> the-schema
                 (lacinia/service-map {:graphiql  true})
                 (assoc ::http/chain-provider provider/ion-provider
                        ::http/resource-path "/public"
                        ::http/allowed-origins {:creds true})))

(defn handler
  "Ion handler"
  [service-map]
  (-> service-map
      http/default-interceptors
      http/create-provider))

(def app (apigw/ionize (handler service)))

hadils22:05:01

Thanks a lot @joe.lane! I really appreciate the effort you put into this answer!

Joe Lane22:05:48

Haha, well thanks. I happen to be working on an app that uses lacinia.pedestal + pedestal.ions at this very moment so it was mostly copy+paste. LMK if you get stuck I’ll try to be available.

hadils22:05:40

I am very lucky indeed!