Write graphql queries with Clojure data structures.
Get the latest version from Clojars
Converting an EDN based query to a GraphQL query
(require '[hql.core :as hql])
(hql/graphql ,,, )
Lets look at some example queries.
[:query
[[:viewer
[[:login]]]]]
This will translate to:
query {
viewer {
login
}
}
Represent a Feild
as a vector and a SelectionSets
as a vector of fields.
[:query
{:$number_of_repos Int!}
[[:viewer
[[:name]
[:repositories
{:last $number_of_repos}
[[:nodes
[[:name]]]]]]]]]
query($number_of_repos: Int!) {
viewer {
name
repositories(last: $number_of_repos) {
nodes {
name
}
}
}
}
Variables ia a query are represented as a map
. And arguments to the field repositories
, in the above query, is represend as a map
too.
[:query
"issuesQuery"
{:$owner String!, :$repo String!}
[[:repository
"repo"
{:owner $owner, :name $repo}
[[:issues
"issues"
{:last 20, :states CLOSED}
[[:edges
[[:node
[[:labels {:first 5} [[:edges [[:node [[:name]]]]]]]]]]]]]]]]]
query issuesQuery($owner: String!, $repo: String!) {
repo: repository(owner: $owner, name: $repo) {
issues: issues(last: 20, states: CLOSED) {
edges {
node {
labels(first: 5) {
edges {
node {
name
}
}
}
}
}
}
}
}
Repo and Issues feilds have aliases "repo" and "issues" in the above query. To specify an alias add it as the second element in the field vector.
[:mutation
"AddReactionToIssue"
[[:addReaction
{:input {:subjectId "MDU6SXNzdWU1MzA1NjgzODQ=", :content HOORAY}}
[[:reaction [[:content]]] [:subject [[:id]]]]]]]
mutation AddReactionToIssue {
addReaction(
input: { subjectId: "MDU6SXNzdWU1MjM5NzY0MDE=", content: HOORAY }
) {
reaction {
content
}
subject {
id
}
}
}
Copyright © 2019 Avichal
Distributed under the Eclipse Public License either version 1.0 or (at your option) any later version.
Can you improve this documentation? These fine people already did:
Avichal Pandey & AvichalEdit on GitHub
cljdoc is a website building & hosting documentation for Clojure/Script libraries
× close