GraphQL

GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data.

graphql.org

The purpose of this post is to help explain to a largely non-technical audience the attraction of GraphQL, and where this fits with the software development services provided by TiePy.

Modern Software Applications

Many modern software applications are based on services provided over the Internet. The front-end to these applications are typically (currently) websites or mobile applications.

It is not uncommon for there to be more than one front-end sharing the same API back-end. You can expect that new human-computer interfaces will continue to emerge, and that these will continue to share a common API.

The Persistence of Data

Separation of the back-end services and front-end interactions already made a lot of sense in supporting both web and mobile applications sharing the same data. It also allows for the front-end to be completely refreshed should it need to keep pace with the competition, without requiring a complete re-implementation. The front-end should be focused on presentation and interactions, and often the real value is in the data and data-processing.

It can be expected that the architecture of databases and of data to have a longer shelf-life than a particular front-end user-interface. While front-end user-interfaces are sometimes re-designed, the data architecture should hopefully be future-proof. The database will still grow and change over time, so these changes should be possible without a burden of complexity.

It is recommended that you consider when commissioning software solutions that you invest in your data API. We recommend that this API implements and supports GraphQL. It is important to get this right, and to develop a strategy with the support of experienced GraphQL developers such as TiePy. We can help design and implement a solution that will establish a platform for current and future application needs. In some cases this may mean developing a new application that provides a separation of concerns with regards to front-end interactions, and back-end data & services. In other cases we can upgrade an existing API, such as REST, with a new GraphQL API.

GraphQL, The Query Language

SQL is a well-known language for relational-database queries. It became a standard in 1986 and still widely used today. GraphQL may use one or more SQL databases, but it can be used to provide a standard interface across data sources, including the expanding family of NoSQL type database options. These options include graph and document-oriented data stores.

There are significantly more options for data persistence now and GraphQL can provide a common interface across different sources. GraphQL is powerful, and flexible.

GraphQL is defined using a strongly-typed schema. The schema is self-describing and this can be very helpful. Once you have a GraphQL API up and running, there are some useful applications which can be used to visualise and query the data at this point. This is useful when building applications that use the API. It can also provide a useful reference when looking to understand the data relationships. The following screenshot shows the Voyager application.

Represent any GraphQL API as an interactive graph, with Voyager!

Articles on learning GraphQL often use a Star Wars data model. The following code block shows one such example GraphQL query.

{
  hero {
    name
    # Queries can have comments!
    friends {
      name
    }
  }
}

Note that the author of the GraphQL query is free to choose the data of interest from the available schema. This includes nested information, following the relationship of the data in the graph defined by the schema.

The result of the query above is returned as a JSON data-structure. This format is ideal for web-applications, but being such a simple structure it is ubiquitous across many applications nowadays.

As you can see below, the structure of the result is similar to the specification made in the query request. Only the requested data is returned.

{
  "data": {
    "hero": {
      "name": "R2-D2",
      "friends": [
        {
          "name": "Luke Skywalker"
        },
        {
          "name": "Han Solo"
        },
        {
          "name": "Leia Organa"
        }
      ]
    }
  }
}

That is really a very brief introduction to GraphQL queries.

Evolution of The Web

Web applications have evolved considerably in recent years due to the quickly evolving nature of web-browser technology. Browser-based applications known as Single Page Applications are common. These are often built using services provided directly with a single server through a web API.

Single Page Applications (SPA) can often be stand-alone. So much so that the term “Server-less computing” has been generally adopted to acknowledge that these new web-applications are different in nature. These applications can utilise the web APIs of a variety of servers, and GraphQL is easy to integrate, and can be significantly easier to consume.

The Ubiquitous Web-API Standard In The Near Future

The growth of GraphQL adoption is remarkable.

Many current web-APIs are provided using REST principles. The REST API style was at least easier to use than some competing alternatives such as SOAP, in the earlier days of the Internet.

It may be fair to say that GraphQL is the better REST. GraphQL really feels like a big leap forward. It is a great example of the evolving nature of the technology landscape, where new technologies succeed in improving the efficiency of delivering and maintaining applications.

Perhaps one day we’ll see a better GraphQL. More likely we will see further advances built on these foundations.

GraphQL is a big step in the right direction, and very much worth adopting.

Other Companies Using GraphQL

Many well-known companies are already using GraphQL.

See more companies listed on Who’s Using GraphQL.

Build a GraphQL API!

TiePy can help you build great GraphQL APIs, and integrated applications. Get in touch.

TiePy Ltd, Director and Software Developer. You can read more posts by me on the DomainDriven.Dev Blog.

Post a Comment