The trending tandem team of Drupal 8 and GraphQL

Behind truly efficient websites and applications, there is an important secret — the right approach to interacting with the data source.
In this regard, you have probably heard (or will hear in the near future) the name of GraphQL. Created in 2015, this new tool is rapidly conquering the hearts of more and more developers. Among them are the hearts of Drupal developers who use GraphQL in headless, or decoupled, Drupal projects. Let’s see what makes GraphQL so special and how it combines with Drupal 8.
GraphQL as a great companion for Drupal 8
In headless (decoupled) Drupal projects, where Drupal’s back-end is combined with some JavaScript front-end, a “bridge” is needed between the two to successfully retrieve Drupal data. Traditionally, the role is associated with RESTful web services, which is especially well developed in Drupal 8.
However, GraphQL, the Facebook-built query language for APIs, is becoming more and more popular, offering an interesting alternative to the REST architecture. GraphQL is meant for fetching structured data on the basis of a schema. It is built around a strong system of types and fields.
Before we move on to one of GraphQL’s major advantages, we’ll ask a little philosophical question. What’s the best way to get exactly what you want? Ask for exactly what you want!
While this rule does not always work in the unpredictable real world, it does work with GraphQL. “GraphQL queries always return predictable results”, say the creators, and there’s no reason to disbelieve them.
GraphQL lets the client-side applications shape their queries to exactly the data they want to get. In addition, everything can be done in a single query. This is especially useful for fetching complex and hierarchical data structures.
No round-trips to the server and no extraneous data! This approach leads to significant performance improvements, even when it comes to huge amount of data and slow mobile connections.
Even Drupal’s founder Dries Buytaert thinks it would be very extremely beneficial to have a GraphQL integration tool in Drupal core. The Drupal community’s interest in GraphQL was greatly kindled by the speech delivered at DrupalCon New Orleans by Sebastian Siemssen, the creator of the module we’re gonna discuss right now.
The GraphQL module to connect GraphQL to Drupal
It’s not in Drupal core (yet), but there exists a special GraphQL module for Drupal 8 to enable Drupal developers to do miracles with GraphQL. Its development is proceeding at a rapid-fire pace, and we’ve recently received a fresh 8.x-3.0-alpha5 release.
Sebastian Siemssen wrote in one of his articles that his main goal was to let Drupal be a GraphQL based data hub for client-side applications by creating a full schema containing the available entity and field types.
This goal has been successfully achieved! The GraphQL module automatically generates GraphQL schemas to expose your entire Drupal 8 site’s data graph via the TypedData API.
A whole infrastructure of useful submodules has grown around the GraphQL to help it perform its mission. They are GraphQL Content, Boolean, File, Image, Entity Reference, Link, Content mutation, Block, Menu, Breadcrumbs, and Views. Their detailed overview is given in the recent article by an active module maintainer, Philipp Melab.
To recap
Following GraphQL’s philosophy, shape your wishes precisely — and they will come true! That’s what we are here for. Drop us a line, and our developers will help you get the results from the GraphQL and Drupal 8 combination!