Last active
February 15, 2018 17:37
-
-
Save mattly/44d7b96c574c957e37cdc2035b5bdca0 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(ns myapp.server.rest | |
(:require | |
(myapp.server.graphql :as gql) | |
(myapp.server.response :as resp))) | |
(defn- from-body-payload [keys] | |
(comp ;; comp composes functions, this is equiv. to (fn [x] (-> x :request :json-params :payload (select-keys keys))) | |
#(select-keys % keys) | |
:payload ;; keywords in clojure, when used as a function on an associative, will get the value at that keyword | |
:json-params | |
:request)) | |
(def v0-create-note | |
{:query "mutation CreateNote($item: ID!, $content: String!) { note: createNote(item: $item, content: $content) { id item content } }" | |
:variables (from-body-payload [:item :content]) | |
:method :post | |
:path "/note"}) | |
(defn- create-pedestal-route-definition | |
[interceptors | |
{:keys [query variables method path modify-response] | |
:or {variables (comp :json-params :request) | |
modify-response :data}}] | |
[(str "/v0" path) | |
method | |
(conj interceptors | |
{:name (keyword path (name method)) | |
:enter (fn [context] | |
(resp/ok context (modify-response (gql/execute-from-context context query (variables context)))))})]) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment