A Clojure library designed to provide GraphQL implementation.
This library is an alpha version. It is still under active development. All functions are subject to change.
The implementation of the library follow closely to the GraphQL Draft RFC Specification (https://facebook.github.io/graphql/).
- GraphQL parser
- Query
- Mutation
- Type System
- Variables
- Transformation
- Execution
- Query
- Mutation
- Support List Type
- Support Non-Null Type
- Arguments
- Variables
- List type variable
- Union
- Interface
- Safe parallel execution
- Coerce
- Fragment execution
- Fragment Type
- Support Context
- Type Introspect, IN PROGRESS
- Type introspection schema (http://graphql.org/docs/introspection/)
- Type introspection query (http://facebook.github.io/graphql/#sec-Introspection)
- Directives
- Testing
- Use clojure.spec to generate test resolver automatically
- Schema validation
- Query validation
- Arguments validation
- Argument Coerce
- Variables validation
- Variable Coerce
- Parser error handling
- Execution error handling
- Batch data loading
- Comment as meta data
Add the following dependency to your project.clj file:
[graphql-clj "0.1.12"]
(require '[graphql-clj.parser :as parser])
(require '[graphql-clj.type :as type])
(def parsed-schema (parser/parse "type User {
name: String
age: Int
}
type QueryRoot {
user: User
}
schema {
query: QueryRoot
}"))
(def type-schema (type/create-schema parsed-schema))
(defn resolver-fn [type-name field-name]
(cond
(and (= "QueryRoot" type-name) (= "user" field-name)) (fn [context parent & args]
{:name "test user name"
:age 30})))
(require '[graphql-clj.executor :as executor])
(def query "query {user {name age}}")
(def context nil)
(executor/execute context type-schema resolver-fn query)
;; {:data {"user" {"name" "test user name", "age" 30}}}
$ lein install
$ lein deploy clojars
$ lein test
Copyright © 2016 Lei Wang
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.