OverviewΒΆ
Warning
The newer com.walmartlabs.lacinia.pedestal2 namespace is recommended over the
now-deprecated com.walmartlabs.lacinia.pedestal namespace. The new namespace was
introduced to maintain backwards compatibility, but be aware of which you use,
as the default URLs served differ with each namespace. This guide assumes you
are using the latest pedestal2 namespace and its defaults.
You start with a schema file, resources/hello-world-schema.edn, in this example:
{:queries
{:hello
{:type String}}}
From there there are three steps:
- Load and compile the schema
- Create a Pedestal service around the schema
- Start the Pedestal service
(ns demo.server
(:require
[clojure.edn :as edn]
[clojure.java.io :as io]
[com.walmartlabs.lacinia.pedestal2 :as p2]
[com.walmartlabs.lacinia.schema :as schema]
[com.walmartlabs.lacinia.util :as util]
[io.pedestal.http :as http]))
(defn ^:private resolve-hello
[context args value]
"Hello, Clojurians!")
(defn ^:private hello-schema
[]
(-> (io/resource "hello-world-schema.edn")
slurp
edn/read-string
(util/inject-resolvers {:queries/hello resolve-hello})
schema/compile))
(def service (-> (hello-schema)
(p2/default-service nil)
http/create-server
http/start))
At the end of this, an instance of Jetty is launched on port 8888.
The GraphQL endpoint will be at http://localhost:8888/api and the GraphIQL client will be at
http://localhost:8888/ide.
The options map provided to default-service allow a number of features of Lacinia-Pedestal
to be configured or customized, though the intent of default-service is to just be
initial scaffolding - it should be replaced with application-specific code.