当前位置: 首页 > 软件库 > 大数据 > 数据查询 >

lacinia-pedestal

Expose Lacinia GraphQL as Pedestal endpoints
授权协议 View license
开发语言 Java
所属分类 大数据、 数据查询
软件类型 开源软件
地区 不详
投 递 者 商昂然
操作系统 跨平台
开源组织
适用人群 未知
 软件概览

com.walmartlabs/lacinia-pedestal

A library that adds thePedestal underpinnings needed when exposingLacinia as an HTTP endpoint.

Lacinia-Pedestal also supports GraphQL subscriptions, using the same protocolas Apollo GraphQL.

Lacinia-Pedestal Manual |API Documentation

Usage

For a basic Pedestal server, simply supply a compiled Lacinia schema tothe com.walmartlabs.lacinia.pedestal2/default-service function togenerate a service, then invoke io.pedestal.http/create-server and /start.

;; This example is based off of the code generated from the template
;;  `lein new pedestal-service graphql-demo`

(ns graphql-demo.server
  (:require [io.pedestal.http :as http]
            [com.walmartlabs.lacinia.pedestal2 :as lp]
            [com.walmartlabs.lacinia.schema :as schema]))

(def hello-schema 
(schema/compile
  {:queries 
    {:hello
      ;; String is quoted here; in EDN the quotation is not required
      {:type 'String
       :resolve (constantly "world")}}}))

;; Use default options:
(def service (lp/default-service hello-schema nil))

;; This is an adapted service map, that can be started and stopped
;; From the REPL you can call server/start and server/stop on this service
(defonce runnable-service (http/create-server service))

(defn -main
  "The entry-point for 'lein run'"
  [& args]
  (println "\nCreating your server...")
  (http/start runnable-service))

Lacinia will handle POST requests at the /api endpoint:

$ curl localhost:8888/api -X POST -H "content-type: application/json" -d '{"query": "{ hello }"}'
{"data":{"hello":"world"}}

You can also access the GraphQL IDE at http://localhost:8888/ide.

Development Mode

When developing an application, it is desirable to be able to change the schemawithout restarting.Lacinia-Pedestal supports this: in the above example, the schema passed todefault-service could be a function that returns the compiled schema.It could even be a Var containing the function that returns the compiled schema.

In this way, the Pedestal stack continues to run, but each request rebuildsthe compiled schema based on the latest code you've loaded into the REPL.

Beyond default-server

default-server is intentionally limited, and exists only to help you get started.Once you start adding anything more complicated, such as authentication, or supportingmultiple schemas (or schema versions) at different paths,you will want to simply create your routes and servers in your own code,using the building-blocks provided by com.walmartlabs.lacinia.pedestal2.

GraphiQL

The GraphiQL packaged inside the library is built using npm, fromversion 1.4.2.

License

Copyright © 2017-2020 Walmart

Distributed under the Apache Software License 2.0.

GraphiQL has its own license.

相关阅读

相关文章

相关问答

相关文档