jspωiki
GraphQL

Overview[1]#

GraphQL is a protocol and a query Interface Definition Language for APIs and a run-time for performing 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 data query language developed internally by Facebook in 2012 before being publicly released in 2015

GraphQL provides an alternative to REST and ad-hoc Web Service architectures

GraphQL allows the client to specify the properties of a Resource that is to be provided rather than the properties dictated by an API, schema, Interface Definition Language or the server author.

Architecture[2] #

Architecture

GraphQL requires a GraphQL Server and a GraphQL Client which use a JSON based GraphQL schema language.

GraphQL query is a string that is sent to a server to be interpreted and fulfilled, which then returns JSON back to the client.
Example GraphQL Request:

{
  hero {
    id
    name
    friends {
      id
      name
    }
  }
}


Example GraphQL Response:

{
  "hero": {
    "id": "2001",
    "name": "R2-D2",
    "friends": [
      {
        "id": "1000",
        "name": "Luke Skywalker"
      },
      {
        "id": "1002",
        "name": "Han Solo"
      },
      {
        "id": "1003",
        "name": "Leia Organa"
      }
    ]
  }
}

GraphQL queries access not just the properties of one resource but also smoothly follow references between them. While typical REST APIs require loading from multiple URLs, GraphQL APIs get all the data your app needs in a single request. Apps using GraphQL can be quick even on slow mobile network connections.

More Information#

There might be more information for this subject on one of the following: