在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):tendant/graphql-clj开源软件地址(OpenSource Url):https://github.com/tendant/graphql-clj开源编程语言(OpenSource Language):Clojure 77.7%开源软件介绍(OpenSource Introduction):graphql-cljA Clojure library designed to provide GraphQL implementation. DemoWhat's new in version 0.2
InstallationAdd the following dependency to your project.clj file:
UsageDefine schema(def schema-str "type User {
name: String
age: Int
}
type QueryRoot {
user: User
}
schema {
query: QueryRoot
}")
Define resolver functions(defn resolver-fn [type-name field-name]
(get-in {"QueryRoot" {"user" (fn [context parent args]
{:name "test user name"
:age 30})}}
[type-name field-name])) Execute query (require '[graphql-clj.executor :as executor])
(def query-str "query {user {name age}}")
(executor/execute nil schema-str resolver-fn query-str)
;; => {:data {"user" {"name" "test user name", "age" 30}}}
Caching validated schema and query for performance (require '[graphql-clj.schema-validator :as schema-validator])
(require '[graphql-clj.query-validator :as query-validator])
;; Consider memoizing the result of parsing and validating the query before execution
(def validated-schema (schema-validator/validate-schema schema-str)) ; throw ex-info with ex-data {:errors errors}
(def validated-query (query-validator/validate-query validated-schema query-str)) ; return [errors validated-ast]
(executor/execute nil validated-schema resolver-fn validated-query)
;; => {:data {"user" {"name" "test user name", "age" 30}}} Migrating from 0.1.x to 0.2 version
Deploy to local for development
Release to Clojars
Test
LicenseCopyright © 2016 Lei Wang Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version. |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论