https://github.com/active-group/active-graphql
ClojureScript library for programmatically constructing GraphQL query strings.
https://github.com/active-group/active-graphql
clojurescript graphql
Last synced: 11 months ago
JSON representation
ClojureScript library for programmatically constructing GraphQL query strings.
- Host: GitHub
- URL: https://github.com/active-group/active-graphql
- Owner: active-group
- License: epl-1.0
- Created: 2017-05-14T12:20:21.000Z (about 9 years ago)
- Default Branch: master
- Last Pushed: 2021-02-12T16:10:35.000Z (over 5 years ago)
- Last Synced: 2025-01-30T05:47:28.013Z (over 1 year ago)
- Topics: clojurescript, graphql
- Language: Clojure
- Homepage:
- Size: 886 KB
- Stars: 2
- Watchers: 16
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# active-graphql
A ClojureScript library for programmatically building GraphQL query strings. Includes a "micro" DSL for constructing more readable queries.
## Running the tests
We run tests via [lein-doo](https://github.com/bensu/doo) and [phantomjs](https://phantomjs.org).
To execute the tests, run
```
lein doo phantom test once
```
## Usage
Some examples for constructing queries using `active-graphql`:
```Clojure
(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 - 2020 Active Group GmbH
Distributed under the Eclipse Public License either version 1.0 or (at
your option) any later version.