October 5, 2016 From rOpenSci (https://deploy-preview-488--ropensci.netlify.app/blog/2016/10/05/graphql-release-10/). Except where otherwise noted, content on this site is licensed under the CC-BY license.
The new ropensci graphql package is now on CRAN. It implements R bindings to the libgraphqlparser C++ library to parse GraphQL syntax and export the syntax tree in JSON format:
graphql2json("{ field(complex: { a: { b: [ $var ] } }) }")
A syntax parser is perhaps not super useful to most end-users, but can be used to validate graphql queries or implement a GraphQL API in R. We hope to add more related functionality later on.
From the GraphQL website:
GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.
GraphQL is a new approach and syntax to structuring API queries. It provides a modern, and perhaps more natural alternative to e.g. REST or SQL (which were designed for hypertext and relational data, respectively). A GraphQL query on the other hand resembles the structure of the data. For example the query:
{
me {
name
}
}
Could produce the JSON result:
{
"me": {
"name": "Luke Skywalker"
}
}
The Github API supports GraphQL and illustrates how GraphQL reduces the number of requests and data in comparison with traditional REST queries.