Coder Social home page Coder Social logo

jleonard-r7 / lacinia-pedestal Goto Github PK

View Code? Open in Web Editor NEW

This project forked from brettatoms/lacinia-pedestal

0.0 0.0 0.0 799 KB

Expose Lacinia GraphQL as Pedestal endpoints

Home Page: http://lacinia-pedestal.readthedocs.io/en/latest/

License: Other

Clojure 96.20% HTML 3.04% Shell 0.45% Dockerfile 0.31%

lacinia-pedestal's Introduction

com.walmartlabs/lacinia-pedestal

Clojars Project

CircleCI

A library that adds the Pedestal underpinnings needed when exposing Lacinia as an HTTP endpoint.

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

Lacinia-Pedestal Manual | API Documentation

Usage

For a basic Pedestal server, simply supply a compiled Lacinia schema to the com.walmartlabs.lacinia.pedestal2/default-service function to generate 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 schema without restarting. Lacinia-Pedestal supports this: in the above example, the schema passed to default-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 rebuilds the 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 supporting multiple 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, from version 1.4.2.

License

Copyright © 2017-2020 Walmart

Distributed under the Apache Software License 2.0.

GraphiQL has its own license.

lacinia-pedestal's People

Contributors

hlship avatar bcarrell avatar theikkila avatar lilactown avatar gabrielnau avatar lennartbuit avatar oliyh avatar snyk-bot avatar annapawlicka avatar transducer avatar sashton avatar frankiesardo avatar youngnh avatar brettatoms avatar jcf avatar gamell avatar lagenorhynque avatar kgann avatar frericksm avatar candid82 avatar ryancrum avatar timgilbert avatar wandersoncferreira avatar dependabot[bot] avatar dougdroper avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.