diff --git a/.github/workflows/clojure.yml b/.github/workflows/clojure.yml index a432ac2..a588030 100644 --- a/.github/workflows/clojure.yml +++ b/.github/workflows/clojure.yml @@ -8,7 +8,7 @@ on: branches: [main] jobs: - build-clj: + clj: strategy: matrix: # Supported Java versions: LTS releases and latest @@ -28,13 +28,13 @@ jobs: distribution: zulu java-version: ${{ matrix.jdk }} - name: Setup Clojure - uses: DeLaGuardo/setup-clojure@main + uses: DeLaGuardo/setup-clojure@12.5 with: - cli: latest + cli: 1.10.1.693 - name: Run tests run: CLOJURE=clojure-${{ matrix.clojure }} bin/kaocha - build-cljs: + cljs: name: ClojureScript runs-on: ubuntu-latest @@ -46,9 +46,9 @@ jobs: distribution: zulu java-version: 11 - name: Setup Clojure - uses: DeLaGuardo/setup-clojure@main + uses: DeLaGuardo/setup-clojure@12.5 with: - cli: latest + cli: 1.10.1.693 - name: Setup Node.js uses: actions/setup-node@v3.6.0 with: @@ -57,3 +57,16 @@ jobs: run: npm ci - name: Run tests run: bin/node + + bb: + name: Babashka + + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - name: Setup Clojure + uses: DeLaGuardo/setup-clojure@12.5 + with: + bb: 1.3.190 + - name: Run tests + run: bin/bb diff --git a/README.md b/README.md index 32efc21..e9ecae2 100644 --- a/README.md +++ b/README.md @@ -16,13 +16,14 @@ Generate GraphQL queries using Clojure data structures. - Support latest stable [GraphQL spec](https://spec.graphql.org/October2021) - [Malli](https://github.com/metosin/malli)-like syntax or programmatic API -- clojure + clojurescript +- Clojure, ClojureScript, and babashka ## Project status [![Clojars Project](https://img.shields.io/clojars/v/fi.metosin/oksa.svg)](https://clojars.org/fi.metosin/oksa) [![Slack](https://img.shields.io/badge/slack-oksa-orange.svg?logo=slack)](https://clojurians.slack.com/app_redirect?channel=oksa) [![cljdoc badge](https://cljdoc.org/badge/fi.metosin/oksa)](https://cljdoc.org/d/fi.metosin/oksa) +bb compatible Oksa is currently [experimental](https://github.com/topics/metosin-experimental). diff --git a/bb.edn b/bb.edn new file mode 100644 index 0000000..ba5af43 --- /dev/null +++ b/bb.edn @@ -0,0 +1,13 @@ +{:paths ["src"] + :tasks + {test:bb {:extra-paths ["test"] + :extra-deps {io.github.cognitect-labs/test-runner + {:git/tag "v0.5.1" :git/sha "dfb30dd"} + camel-snake-kebab/camel-snake-kebab + {:git/url "https://github.com/clj-commons/camel-snake-kebab" :git/tag "version-0.4.3" :git/sha "526dd86"} + metosin/malli + {:git/url "https://github.com/metosin/malli" :git/tag "0.10.4" :git/sha "44518a9"}} + :task (exec 'cognitect.test-runner.api/test) + :exec-args {:dirs ["test"]} + :org.babashka/cli {:coerce {:nses [:symbol] + :vars [:symbol]}}}}} diff --git a/bin/bb b/bin/bb new file mode 100755 index 0000000..1b1e768 --- /dev/null +++ b/bin/bb @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +set -eo pipefail + +ROOT_DIR="$(dirname $0)/.." + +(cd "$ROOT_DIR" && bb test:bb) diff --git a/examples/babashka/README.md b/examples/babashka/README.md new file mode 100644 index 0000000..79102fb --- /dev/null +++ b/examples/babashka/README.md @@ -0,0 +1,5 @@ +# Run instructions + +``` +bb -f example.bb +``` diff --git a/examples/babashka/bb.edn b/examples/babashka/bb.edn new file mode 100644 index 0000000..76e412b --- /dev/null +++ b/examples/babashka/bb.edn @@ -0,0 +1 @@ +{:deps {fi.metosin/oksa {:mvn/version "0.1.0"}}} diff --git a/examples/babashka/example.bb b/examples/babashka/example.bb index a9fad6e..2609f23 100644 --- a/examples/babashka/example.bb +++ b/examples/babashka/example.bb @@ -1,34 +1,29 @@ (require '[babashka.classpath :refer [add-classpath]] '[clojure.java.shell :refer [sh]] - '[clojure.string :as str]) - -(def deps '{:deps {oksa {:git/url "https://github.com/metosin/oksa.git" - :sha "4b83ae43896022b26636bd29f831a24cb6691c58"}}}) -(def cp (-> (sh "clojure" "-Spath" "-Sdeps" (str deps)) :out str/trim)) -(add-classpath cp) -(require '[babashka.http-client :as http] + '[clojure.string :as str] + '[babashka.http-client :as http] '[cheshire.core :as json] - '[oksa.core :as oksa]) + '[oksa.core :as o]) (println (str "GraphQL conferences in Finland")) (println "==============================") (println) (println (->> (-> (http/post "https://api.react-finland.fi/graphql" - {:headers {:content-type "application/json"} - :body (json/encode {:query (oksa/unparse [:conferences - [:name - :organizers [:company] - :startDate - :endDate - :slogan - :websiteUrl - :locations [:country [:name] - :city - :address] - :organizers [:company] - :schedules [:day :intervals [:begin :end] :description]]]) - :variables nil})}) + {:headers {:content-type "application/json"} + :body (json/encode {:query (o/gql [:conferences + [:name + :organizers [:company] + :startDate + :endDate + :slogan + :websiteUrl + :locations [:country [:name] + :city + :address] + :organizers [:company] + :schedules [:day :intervals [:begin :end] :description]]]) + :variables nil})}) (update :body #(json/decode % true)) (get-in [:body :data :conferences])) (sort-by :startDate #(compare %2 %1)) diff --git a/test/oksa/alpha/api_test.cljc b/test/oksa/alpha/api_test.cljc index 5351815..fe88b01 100644 --- a/test/oksa/alpha/api_test.cljc +++ b/test/oksa/alpha/api_test.cljc @@ -2,16 +2,18 @@ (:require [camel-snake-kebab.core :as csk] [#?(:clj clojure.test :cljs cljs.test) :as t] - [oksa.core :as oksa] - [oksa.alpha.api :as api]) - #?(:clj (:import [graphql.parser Parser]))) + [oksa.alpha.api :as api])) + +#?(:bb nil + :clj (import graphql.parser.Parser)) (defn unparse-and-validate ([x] (unparse-and-validate nil x)) ([opts x] (let [graphql-query (api/gql opts x)] - #?(:clj (Parser/parse graphql-query)) + #?(:bb nil + :clj (Parser/parse graphql-query)) graphql-query))) (t/deftest unparse-test diff --git a/test/oksa/core_test.cljc b/test/oksa/core_test.cljc index 3b7df19..fb7f4d9 100644 --- a/test/oksa/core_test.cljc +++ b/test/oksa/core_test.cljc @@ -4,8 +4,10 @@ :cljs cljs.test) :as t] [oksa.core] [oksa.test-util :refer [unparse-and-validate]] - [oksa.alpha.api :as api]) - #?(:clj (:import [graphql.parser Parser]))) + [oksa.alpha.api :as api])) + +#?(:bb nil + :clj (import graphql.parser.Parser)) (t/deftest unparse-test (t/testing "query" diff --git a/test/oksa/test_util.cljc b/test/oksa/test_util.cljc index 859e3cd..53d20fc 100644 --- a/test/oksa/test_util.cljc +++ b/test/oksa/test_util.cljc @@ -1,11 +1,14 @@ (ns oksa.test-util - (:require [oksa.core :as core]) - #?(:clj (:import [graphql.parser Parser]))) + (:require [oksa.core :as core])) + +#?(:bb nil + :clj (import graphql.parser.Parser)) (defn unparse-and-validate ([x] (unparse-and-validate nil x)) ([opts x] (let [graphql-query (core/unparse opts x)] - #?(:clj (Parser/parse graphql-query)) + #?(:bb nil + :clj (Parser/parse graphql-query)) graphql-query)))