Liking cljdoc? Tell your friends :D

HQL

CircleCI

Write graphql queries with Clojure data structures.

Usage

Get the latest version from Clojars

Latest version

Converting an EDN based query to a GraphQL query

(require '[hql.core :as hql])

(hql/graphql ,,, )

Lets look at some example queries.

Examples

  1. A query to get your username from Github
[:query
  [[:viewer
     [[:login]]]]]

This will translate to:

query {
  viewer {
    login
  }
}

Represent a Feild as a vector and a SelectionSets as a vector of fields.

  1. Get your last N repos using a query with variables.
[: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.

  1. Get closed issues from a repo:
[: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.

  1. Use mutations to add reaction to an issue
[:mutation
 "AddReactionToIssue"
 [[:addReaction
   {:input {:subjectId "MDU6SXNzdWU1MzA1NjgzODQ=", :content HOORAY}}
   [[:reaction [[:content]]] [:subject [[:id]]]]]]]
mutation AddReactionToIssue {
  addReaction(
    input: { subjectId: "MDU6SXNzdWU1MjM5NzY0MDE=", content: HOORAY }
  ) {
    reaction {
      content
    }
    subject {
      id
    }
  }
}

License

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 & Avichal
Edit on GitHub

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close