Giter VIP home page Giter VIP logo

graphql.el's Introduction

GraphQL.el

MELPA Build Status

GraphQL.el provides a set of generic functions for interacting with GraphQL web services.

See also the following resources:

Syntax Overview

Two macros are provided to express GraphQL queries and mutations:

  • graphql-query encodes the graph provided under a root (query ...) node.
  • graphql-mutation encodes the graph provided under a root (mutation ...) node.

Both macros allow special syntax for query/mutation parameters if this is desired; see the docstrings for details. I will note that backtick notation usually feels more natural in Lisp code.

Basic Queries

The body of these macros is the graph of your query/mutation expressed in a Lispy DSL. Generally speaking, we represent fields as symbols and edges as nested lists with the edge name being the head of that list. For example,

(graphql-query
 (myField1 myField2 (myEdges (edges (node myField3)))))

will construct a query that retrieves myField1, myField2, and myField3 for every node in myEdges. The query is returned as a string without any unnecessary whitespace (i.e., formatting) added.

Following Edges

Multiple edges can of course be followed. Here's an example using GitHub's API:

(graphql-query
 ((viewer login)
  (rateLimit limit cost remaining resetAt)))

Passing Arguments

Usually, queries need explicit arguments. We pass them in an alist set off by the :arguments keyword:

(graphql-query
 ((repository
   :arguments ((owner . "github")
               (name . ($ repo)))
   (issues :arguments ((first . 20)
                       (states . [OPEN CLOSED]))
           (edges
            (node number title url id))))))

As you can see, strings, numbers, vectors, symbols, and variables can all be given as arguments. The above evaluates to the following (formatting added):

query {
  repository (owner: "github", name: $repo) {
    issues (first: 20, states: [OPEN, CLOSED]) {
      edges {
        node {
          number title url id
        }
      }
    }
  }
}

Objects as arguments work, too, though practical examples seem harder to come by:

(graphql-query
 ((object :arguments ((someVariable . ((someComplex . "object")
                                       (with . ($ complexNeeds))))))))

gives

query {
  object (
    someVariable: {
      someComplex: "object",
      with: $complexNeeds
    }
  )
}

Working with Responses

  • graphql-simplify-response-edges

    Simplify structures like

    (field
     (edges
      ((node node1values...))
      ((node node2values...))))
    

    into (field (node1values) (node2values)).

Keyword Reference

  • :arguments

    Pass arguments to fields as an alist of parameters (as symbols) to values. See graphql--encode-argument-value.

  • :op-name, :op-params

    Operation name/parameters. Given to top-level query or mutation operations for later re-use. You should rarely (if ever) need to supply these yourself; the graphql-query and graphql-mutation macros give you natural syntax to do this.

Planned

graphql.el's People

Contributors

iyefrat avatar tarsius avatar vermiculus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

graphql.el's Issues

Parsing graphql queries

Sean, first of all, let me thank you for this awesome library. I just wanted to make something very small first, and I hope if I'm able to make something useful out of it, maybe I'll eventually turn it into a package. I just started playing with ghub and this package, and indeed it looks very nice.

This is not an issue, more like a question. How do you parse existing graphql queries (text) into lisp structures that later can be fed into (graphql-query)?

Fix CI

Need to add sudo:required;dist:trusty.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.