Turning Drupal into a data hub #GraphQL
GraphQL is an application layer query language designed by Facebook that enables retrieving and editing structured, hierarchical data based on a schema. GraphQL enables the caller to explicitly and precisely specify its data requirements instead of the server providing a more limited range of predefined resources. It thereby eliminates common problems like over- or under-fetching and shifts that responsibility to the client side.
This idea is not entirely new
There have been similar concepts (e.g. JSON API, SPARQL) for quite some time now. Undoubtedly, GraphQL takes some inspiration from these. However, it drives the core idea quite a bit further and challenges some of the principles around which we have been building web services for the pastyears. Most certainly it offers remedies for some of the most frustrating problems when working with RESTful web interfaces.
Want to learn more?
If you are interested to learn more about GraphQL (you should be!), try the interactive tutorial by KADIRA (offline!)!
Drupal integration is underway
Over the past months I’ve successfully experimented with GraphQL in PHP and have started working on a Drupal 8 module that integrates GraphQL with Drupal. My goal is to enable Drupal as a GraphQL based data hub for client side applications. I am trying to achieve this by generating a full schema from the available entity types and their fields by recursively iterating over their typed data definitions. Ultimately, it will be possible to install the module on your site to automatically expose your entire data graph including support for all possible entity and field types and their properties.
Acquia and Zensations support the effort
After some initial development towards that goal, I shared the idea with the Drupal community through a
as well as a series of Tweets in which I voiced my excitement. The idea was so well received that it was even featured
a few weeks later. Since then, I've also had the pleasure of presenting about this a few times. Due to pressing deadlines, work obligations, and me moving to the other side of the country, progress stalled. Therefore, I am super excited to announce that Acquia is funding me to work on continue working on both the PHP library as well as the Drupal 8 module. I would like to thank Moshe Weitzman, Preston So and Wim Leers as well as Dries Buytaert and generally the Acquia OCTO team for making this possible. I also want to thank Zensations for supporting me over the past weeks and months and giving me time to work on this incredibly interesting project.
Wim, Moshe and I set up a list of short- and long-term goals for the project and I’ve already started working on them. Within the next few weeks, we’ll release a first version of the module including the following features:
- Read support for all content entity types, all their fields and all properties of each possible field type.
- Read support for various other data types that are currently defined as typed data definitions (e.g. Languages).
- Query support for all queryable fields through EntityQuery.
- Query support based on configured Views for complex scenarios where you need a special entry point that exceeds the capabilities of EntityQuery.
- Query support for Views based on contextual filters that can be resolved through any of the entity types for which we are generating the schema. This will allow you to create a View with a contextual filter of type “user” and then have it automatically appear as a traversable reference in the user schema.
- Following references of any data reference type specified through typed data (e.g. entity reference fields).
- Reverse querying of entity reference fields (e.g. fetching all nodes that reference a particular user entity by following the “uid” entity reference field in reverse).
- Entity and field level access checks based on the Entity and Field Access API.
- Manual aliasing of field names to mask some of the uglier machine readable names.
- Extendability through custom type resolvers.
- Graphical interface for crafting queries and exploring the schema by integrating GraphiQL
In the future we will also support write operations (mutations) and we are looking for ways to further control, extend and fine tune the generated schema both through configuration and code.
As we are preparing the release, I’ll post more details about each of the outlined features and our future plans for the module.