Amazeenar #1 - GraphQL & Twig

“Absolutely incredible!” - just one quote from our first Amazeenar in which we explore the power of GraphQL Twig. Decoupling Drupal is the future, however, it may be a big leap to learn a whole new development stack. With GraphQL Twig, we can take baby steps with a soft-decoupled approach by writing GraphQL inside our Twig templates.

Amazeenars Visual

TL;DR

 

On Friday 11th May, Amazee Labs hosted its first Amazeenar - a live video training session presented by Philipp Melab who demonstrated some of the capabilities of GraphQL with the Drupal module GraphQL Twig.

We started the webinar while a crowd joined live from over 13 countries around the world, including Belgium, Brazil, Canada, South Africa, and as far east as Thailand.

It felt exciting to have a community of enthusiastic people connecting from so many different locations across the globe. This once again reinforced that Drupal is really about coming for the code and staying for the community.

Philipp dove into the talk by giving us a quick introduction to GraphQL, with an example query for us to better understand the concept:


query {
  node:nodeById(id: "1") {
    title:entityLabel
    related:relatedNodes {
      title:entityLabel
    }
  }
}

Running this example GraphQL query would give us the following JSON response:


{
  “node”: {
    “title”: “Article A”,
    “related” {
      { “title”: “Article B” },
      { “title”: “Article C” }
    }
  }
}

laptop

Inversion of control

Philipp then explained the need for decoupling, providing us with a good overview of the fundamental differences between standard Drupal and Decoupled Drupal, in which the control moves from a push approach to a pull approach.

React is great, but the inversion of control is crucial.

Enable the template to define its data requirements, allow's us to achieve a clear data flow with significantly increased readability and maintainability. The GraphQL Twig module allows us to add GraphQL queries to any Twig template, which is then processed during rendering and used to populate the template with data.

Philipp entertained the audience with a live working demo in which, together, we learnt how to enhance the default “powered by Drupal” block to pull in the username of user 1. He then blew our minds with an additional surprise - pulling in the current number of open bug issues for Drupal Core via the GraphQL XML submodule.

Catchup

Did you miss the webinar? Don’t fret; we recorded everything!

Amazee Labs would like to thank everyone who attended the live session, we enjoyed being able to share this with you, and we look forward to hosting another Amazeenar shortly.

May 14, 2018
1 Comment

Get our Newsletter

 
 

Comments

This was very helpful. I'm excited about the "soft" decoupled approach, as implementing fully decoupled approach can often be too expensive.

By Chris
4 weeks ago

Add new comment

You must have Javascript enabled to use this form.
icon
What is Amazee Labs?