Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
lacinia optional string params in mutations
(ns tools.graphql-fiddle
(:require [clojure.pprint :refer [pprint]]
[com.walmartlabs.lacinia.schema :as schema]
[com.walmartlabs.lacinia.util :refer [attach-resolvers]]
[com.walmartlabs.lacinia :as lacinia]))
(def definition
{:objects {:person {:fields {:name '{:type String}
:nicknames '{:type (list String)}}}
:saveResult {:fields {:status '{:type String}}}}
:queries {:people {:type :person
:resolve :person}}
:mutations {:savePerson {:type :saveResult
:args {:name '{:type (non-null String)}
:nicknames '{:type (list String)}}
:resolve :save-person}}})
(defn resolve-person
[ctx args v]
{:name "john"
:nicknames ["Jonnie" "Big John"]})
(defn save-person
[ctx args v]
{:status "saved"})
(def resolvers
{:person resolve-person
:save-person save-person})
(def schema
(-> definition
(attach-resolvers resolvers)
(schema/compile {})))
(defn execute
[gql vars]
(let [ctx {::loader (atom {:pending #{} :cache {}})}]
(lacinia/execute schema gql vars ctx)))
"query {
people {
name nicknames
"mutation savePerson($name: String!, $nicknames: [String!]) {
savePerson(name: $name, nicknames: $nicknames) {
{:name "Pete"
:nicknames nil}))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment