Coder Social home page Coder Social logo

mikewin / lacinia-pedestal Goto Github PK

View Code? Open in Web Editor NEW

This project forked from walmartlabs/lacinia-pedestal

0.0 1.0 0.0 897 KB

Expose Lacinia GraphQL as Pedestal endpoints

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

License: Other

Dockerfile 0.03% Clojure 6.07% HTML 0.26% Shell 0.01% CSS 2.51% JavaScript 91.13%

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.pedestal/service-map 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.pedestal :as lacinia]
            [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")}}}))

(def service (lacinia/service-map hello-schema {:graphiql true}))

;; 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 GET and POST requests at the /graphql endpoint.

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

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 pedestal-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.

GraphiQL

The GraphiQL packaged inside the library is built using npm, from version 0.12.0.

License

Copyright © 2017 Walmart

Distributed under the Apache Software License 2.0.

GraphiQL has its own license.

lacinia-pedestal's People

Contributors

annapawlicka avatar bcarrell avatar candid82 avatar dougdroper avatar frankiesardo avatar frericksm avatar gabrielnau avatar gamell avatar hlship avatar jcf avatar kgann avatar lilactown avatar oliyh avatar ryancrum avatar sashton avatar theikkila avatar timgilbert avatar

Watchers

 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.