Saturday, May 23, 2015

data: GraphQL (React.js, Relay, Facebook), JsonQL

GraphQL Introduction | React
A GraphQL query is a string interpreted by a server that returns data in a specified format. Here is an example query:
{
  user(id: 3500401) {
    id,
    name,
    isViewerFriend,
    profilePicture(size: 50)  {
      uri,
      width,
      height
    }
  }
}
(Note: this syntax is slightly different from previous GraphQL examples. We've recently been making improvements to the language.)
And here is the response to that query.
{
  "user" : {
    "id": 3500401,
    "name": "Jing Chen",
    "isViewerFriend": true,
    "profilePicture": {
      "uri": "http://someurl.cdn/pic.jpg",
      "width": 50,
      "height": 50
    }
  }
}
Introducing Relay and GraphQL | React
"GraphQL is a data querying language designed to describe the complex, nested data dependencies of modern applications. It's been in production use in Facebook's native apps for several years.

On the server, we configure the GraphQL system to map queries to underlying data-fetching code. This configuration layer allows GraphQL to work with arbitrary underlying storage mechanisms. Relay uses GraphQL as its query language, but it is not tied to a specific implementation of GraphQL."


JSON_QL could be an appropriate name... and as expected it already exists!
(written in Go Lang)

jsonQL

Inspired by GraphQL, build JSON documents from a declarative JSON-based spec.
// select * from users where 1 < id and id < 4 and id != 3
{from: "users", where: "1 < id and id < 4 and id != 3"}
Now, this syntax is more descriptive than template based as in GraphQL...





No comments: