Skip to content
ClojureScript library for programmatically constructing GraphQL query strings.
Clojure
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
doc
src/active_graphql
test/active_graphql
.gitignore
CHANGELOG.md
LICENSE
README.md
project.clj

README.md

active-graphql

A ClojureScript library for programmatically building GraphQL query strings. Inlcudes a "micro" DSL for constructing more readable queries.

Usage

Some examples for constructing queries using active-graphql:

(ns active-graphql.examples
  (:require [active-graphql.builder :as b])

(b/query (b/field "user" "firstName" "lastName"))
;; =>
;; query {
;;   user {
;;     firstName
;;     lastName
;;   }
;; }

;; Keywords can be used instead of strings
(b/query (b/field :user :firstName :lastName))
;; =>
;; query {
;;   user {
;;     firstName
;;     lastName
;;   }
;; }

;; Aliasing
(b/query (b/field :user
                  [:name :firstName]))
;; =>
;; query {
;;   user {
;;     name: firstName
;;   }
;; }

(b/mutation (b/field "user" "firstName" "lastName"))
;; =>
;; mutation {
;;   user {
;;     firstName
;;     lastName
;;   }
;; }

;; Utilizing arguments to a query:
(b/query (b/field "user" {"id" 42} "firstName"))
;; =>
;; query {
;;   user(id: 42) {
;;     firstName
;;   }
;; }

;; Nesting
(b/query (b/field "user" {"id" 42} "firstName")
         (b/field "hardware" "type" "model"))
;; =>
;; query {
;;   user(id: 42) {
;;     firstName
;;   }
;;   hardware {
;;     type
;;     model
;;   }
;; }

;; Deeper nesting
(b/query (b/field "user" {"id" 42}
                  "firstName"
                  "other")
         (b/field "person"
                  {"firstName" "Marco"}
                  (b/field "address"
                           "street"
                           "zipCode")))
;; query {
;;   user(id: 42) {
;;     firstName
;;     other
;;   }
;;   person(firstName: "Marco") {
;;     address {
;;       street
;;       zipCode
;;     }
;;   }
;; }

License

Copyright © 2017 Active Group GmbH

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

You can’t perform that action at this time.