Skip to content

Commit

Permalink
Support babashka (#11)
Browse files Browse the repository at this point in the history
  • Loading branch information
ilmoraunio authored May 24, 2024
1 parent afbf769 commit 9c8075c
Show file tree
Hide file tree
Showing 10 changed files with 80 additions and 38 deletions.
25 changes: 19 additions & 6 deletions .github/workflows/clojure.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
branches: [main]

jobs:
build-clj:
clj:
strategy:
matrix:
# Supported Java versions: LTS releases and latest
Expand All @@ -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
Expand All @@ -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:
Expand All @@ -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
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)
<a href="https://babashka.org" rel="nofollow"><img src="https://github.com/babashka/babashka/raw/master/logo/badge.svg" alt="bb compatible" style="max-width: 100%;"></a>

Oksa is currently [experimental](https://github.com/topics/metosin-experimental).

Expand Down
13 changes: 13 additions & 0 deletions bb.edn
Original file line number Diff line number Diff line change
@@ -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]}}}}}
7 changes: 7 additions & 0 deletions bin/bb
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#!/usr/bin/env bash

set -eo pipefail

ROOT_DIR="$(dirname $0)/.."

(cd "$ROOT_DIR" && bb test:bb)
5 changes: 5 additions & 0 deletions examples/babashka/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Run instructions

```
bb -f example.bb
```
1 change: 1 addition & 0 deletions examples/babashka/bb.edn
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{:deps {fi.metosin/oksa {:mvn/version "0.1.0"}}}
39 changes: 17 additions & 22 deletions examples/babashka/example.bb
Original file line number Diff line number Diff line change
@@ -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))
Expand Down
10 changes: 6 additions & 4 deletions test/oksa/alpha/api_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions test/oksa/core_test.cljc
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
9 changes: 6 additions & 3 deletions test/oksa/test_util.cljc
Original file line number Diff line number Diff line change
@@ -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)))

0 comments on commit 9c8075c

Please sign in to comment.