Fork me on GitHub
#pedestal
<
2017-11-24
>
amilner4220:11:52

Hey everyone, I'm super new to clojure, trying to set up a super basic graphql server with lacinia and lacinia-pedestal but I'm getting CORs errors, anyone have any experience getting cors working with lacinia-pedestal?

amilner4220:11:46

(ns user
  "The user gets loaded by the repl by default, just helps with testing queries out..."
  (:require [api.schema :as s]
            [com.walmartlabs.lacinia :as lacinia]
            [com.walmartlabs.lacinia.pedestal :as lp]
            [io.pedestal.http :as http]
            [clojure.walk :as walk])
  (:import (clojure.lang IPersistentMap)))

...

(defn start-server
  [_]
  (-> schema
      (lp/pedestal-service {:graphiql true})
      http/create-server
      http/start))
I've tried doing something like:
(defn start-server
  [_]
  ( as-> schema pipe-val
      (lp/pedestal-service pipe-val {:graphiql true})
      (merge  pipe-val { ::http/allowed-origins { :allowed-origins (constantly true)}})
      (http/create-server pipe-val)
      (http/start pipe-val)))
And it doesn't seem to work

amilner4220:11:36

That was how I came up with what I tried :S … This is the first code I ever wrote in clojure so I’m kinda learning as I go…

luskwater20:11:37

@amilner42 Can't do much for you at the moment: I'm sitting in a general store near Lancaster, PA, waiting for my wife. I recall a CORS setting or interceptor in code generated by lein vase for a Vase project. Might be worth looking at it.

amilner4220:11:27

Ok no worries, thanks. I’ll generate that and see if it helps

amilner4220:11:54

Ya they seem to do the same thing in the Vase template

amilner4221:11:45

Oh I think this worked:

(defn start-server
  [_]
  (-> schema
      (lp/service-map {:graphiql true})
      (merge { ::http/allowed-origins {:creds true :allowed-origins (constantly true)}})
      http/create-server
      http/start))
It looks like lp/pedestal-service was calling create-server, so that’s why it wasn’t working…

amilner4221:11:41

Ya that was it…ugh so dumb. Thanks