• Stars
    star
    61
  • Rank 497,051 (Top 10 %)
  • Language
    Clojure
  • Created about 7 years ago
  • Updated over 1 year ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

Want to use GraphQL with Clojure/script but don't want keBab or snake_keys everywhere? Use locksmith to change all the keys!

locksmith

Want to use GraphQL with Clojure/script but don't want snake_keys or camelKeys everywhere? Use locksmith to change all the keys!

locksmith creates efficient functions to transform GraphQL keys (e.g. snake_key, camelKey, boolean_key) into Clojure keys (snake-key, camel-key, boolean-key?) and vice versa. It does this by inspecting your lacinia GraphQL schema, deciding which keys need renaming and composing functions to do the renames as fast as possible.

This helps you satisfy GraphQL queries on your server and work with idiomatic Clojure data on your client. It uses camel-snake-kebab under the hood, with the addition of adding ? as a suffix for boolean types.

Clojars Project

Usage

Imagine you have a schema for a car race, as follows:

(def lacinia-schema
  '{:enums {:team_name {:description "Some enumerated teams"
                        :values [:ferrari_scuderia :red_bull :mercedes_gp]}}

    :objects {:car_race {:fields {:winning_driver {:type :car_driver}
                                  :competing_drivers {:type (list :car_driver)}
                                  :country_name {:type String}}}
              :car_driver {:fields {:first_name {:type String}
                                    :team_name {:type :team_name}
                                    :champion {:type Boolean}}}}})

On your server you have lots of lovely Clojure data, but you have to put loads of underscores or camels in it to satisfy any GraphQL queries that come in. locksmith's clj->gql does this for you!

(let [car-race-converter (clj->gql lacinia-schema :car_race)]
  (car-race-converter {:country-name "GB"
                       :winning-driver {:first-name "Lewis"
                                        :team-name :mercedes-gp
                                        :champion? true}
                       :competing-drivers [{:first-name "Lewis"
                                            :team-name :mercedes-gp
                                            :champion? true}
                                           {:first-name "Sebastian"
                                            :team-name :ferrari-scuderia
                                            :champion? true}
                                           {:first-name "Max"
                                            :team-name :red-bull
                                            :champion? false}]}))

;; {:country_name "GB",
;;  :competing_drivers
;;  ({:champion true, :team_name "mercedes_gp", :first_name "Lewis"}
;;   {:champion true,
;;    :team_name "ferrari_scuderia",
;;    :first_name "Sebastian"}
;;   {:champion false, :team_name "red_bull", :first_name "Max"}),
;;  :winning_driver
;;  {:champion true, :team_name "mercedes_gp", :first_name "Lewis"}}

On your client you crave Clojure data, but the GraphQL server is trying to force feed you underscores or camels. locksmith's gql->clj sorts it out!

(let [car-race-converter (gql->clj lacinia-schema :car_race)]
  (car-race-converter {:country_name "GB"
                       :winning_driver {:first_name "Lewis"
                                        :team_name "mercedes_gp"
                                        :champion true}
                       :competing_drivers [{:first_name "Lewis"
                                            :team_name "mercedes_gp"
                                            :champion true}
                                           {:first_name "Sebastian"
                                            :team_name "ferrari_scuderia"
                                            :champion true}
                                           {:first_name "Max"
                                            :team_name "red_bull"
                                            :champion false}]}))

;; {:country-name "GB",
;;  :competing-drivers
;;  ({:champion? true, :team-name :mercedes-gp, :first-name "Lewis"}
;;   {:champion? true,
;;    :team-name :ferrari-scuderia,
;;    :first-name "Sebastian"}
;;   {:champion? false, :team-name :red-bull, :first-name "Max"}),
;;  :winning-driver
;;  {:champion? true, :team-name :mercedes-gp, :first-name "Lewis"}}

Development

CircleCI

License

Copyright Β© 2017 oliyh

Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.

More Repositories

1

martian

The HTTP abstraction library for Clojure/script, supporting OpenAPI, Swagger, Schema, re-frame and more
Clojure
470
star
2

re-graph

A graphql client for clojurescript and clojure
Clojure
447
star
3

superlifter

A DataLoader for Clojure/script
Clojure
158
star
4

re-learn

A library for integrating tutorials into your re-frame/reagent application
Clojure
138
star
5

pedestal-api

Easily build APIs in Pedestal using Schema and Swagger
Clojure
106
star
6

kamera

UI testing via image comparison and devcards
Clojure
86
star
7

lacinia-gen

Generators for GraphQL
Clojure
69
star
8

re-jump.el

emacs navigation for re-frame projects
Emacs Lisp
69
star
9

slacky

Memes as a Slack Service
Clojure
33
star
10

angel-interceptor

Express relations between Pedestal interceptors and decouple scope from execution order
Clojure
28
star
11

doo-chrome-devprotocol

A runner for doo which runs tests in Chrome, using the Chrome Dev Protocol with no need for karma or npm.
Clojure
27
star
12

carmine-streams

Utility functions for working with Redis streams in carmine
Clojure
26
star
13

fixa

Better test fixtures for clojure
Clojure
26
star
14

oxbow

A Server Sent Events (SSE) client for Clojurescript based on js/fetch
Clojure
24
star
15

spa-skeleton

A skeleton project for a ClojureScript Single Page Application backed by a Swagger API
Clojure
21
star
16

re-partee

How I build Clojurescript apps
Clojure
15
star
17

carve.el

Emacs plugin for borkdude/carve
Emacs Lisp
9
star
18

alrightee

Tee for re-frame
Clojure
7
star
19

learning-clojure

Learning materials for Clojure
Clojure
5
star
20

tinybeans-archive

Create an archive of a tinybeans journal
Clojure
4
star
21

cljockwork

A REST API for cron4j, written in Clojure
Clojure
4
star
22

stardev-feedback

Capturing feedback for https://stardev.io
3
star
23

haproxy-cert-jwt

A Lua extension for HAProxy to turn an SSL client certificate into a JWT for the backend
Lua
2
star
24

one-route

A Ring webserver with one route
HTML
2
star
25

slacky-bot

All the memes for Slack
Clojure
2
star
26

cljs-webapp-from-scratch

Clojure
2
star
27

ingred

Search recipes by ingredient - a REST api written in Clojure with data scraped from the BBC
Clojure
2
star
28

sunshine

Clojure
2
star
29

fast-feedback

A presentation giving guidance on how to optimise your feedback loop and improve efficiency
HTML
1
star
30

a-taste-of-clojure

A talk to introduce (Java) developers to Clojure
JavaScript
1
star
31

sanakone

Learn Finnish
Clojure
1
star
32

masvn

Subversion integration for emacs based on dsvn and inspired by magit
Emacs Lisp
1
star