https://github.com/ferossgp/geql
An experimental library agnostic EQL to GraphQL generator
https://github.com/ferossgp/geql
clojure clojurescript eql graphql
Last synced: 9 months ago
JSON representation
An experimental library agnostic EQL to GraphQL generator
- Host: GitHub
- URL: https://github.com/ferossgp/geql
- Owner: Ferossgp
- License: mit
- Created: 2020-03-22T09:35:01.000Z (almost 6 years ago)
- Default Branch: master
- Last Pushed: 2020-06-26T16:14:49.000Z (over 5 years ago)
- Last Synced: 2025-01-25T10:41:25.652Z (11 months ago)
- Topics: clojure, clojurescript, eql, graphql
- Language: Clojure
- Homepage:
- Size: 9.77 KB
- Stars: 2
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# GEQL
A Clojure(Script) qraphql query client library. Generate graphql queries using [EQL](https://edn-query-language.org).
Code extracted from [Pathom](https://github.com/wilkerlucio/pathom) and extended to support extra graphql features.
# Usage
- `geql.core/query->graphql` is a function that can transform data in format of
EQL to graphql string.
- `geql.core/defquery` is a macros that generates a var containing the compiled
string and the query itself. This is useful for the ClojureScript app when you
want to remove some extra computations. The EQL tree is left so it can be used
at the discretion of the developer to parse the response, normalization and other
useful computations with AST.
To make use of macros, it was necessary to introduce the support for variables.
Graphql variables allow having dynamic arguments. This way a query in a form of a
static string and a dynamic map of vars can be sent together to graphql server
without recompiling the query everytime.
### Example queries with variables
```clojure
; Query
(geql.core/query->graphql [{'(:hero {:episode {:variable/name "episode"
:variable/type :String}})
[:name {:friends [:name]}]}])
=> "query ($episode:String){hero(episode:$episode){name,friends{name}}}"
; Mutation
(geql.core/query->graphql [{'(createReview {:episode {:variable/name "episode"
:variable/type :Episode!}
:stars {:variable/name "stars"
:variable/type :ReviewStars!
:variable/default 5}})
[:name :stars]}])
=> "mutation ($episode:Episode!,$stars:ReviewStars!=5){createReview(episode:$episode,stars:$stars){name,stars}}"
```