Học làm theme với Drupal module GraphQL Twig

5th May 2022
Table of contents

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.

TL;DR

  • Video here: https://youtu.be/QsmeXMZ0foM
  • Repo with slides: github.com/AmazeeLabs/bartik_graphql

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” }
    }
  }
}
Attach
Attachment Size
bartik_graphql-master.zip3.46 MB 3.46 MB

Add new comment

This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.

Image CAPTCHA
Enter the characters shown in the image.

Related Articles

There’s no denying that GraphQL is the latest addition for API development. For front end frameworks many GraphQL clients are available and Apollo

However, there is one case that the Graphql module does not cover: building a Graphql schema for data that is not represented as a Drupal entity.

Over the past decade, REST has become the standard (yet a fuzzy one) for designing web APIs

The same route handler function is called in REST whereas in GraphQL query can be called to form nested response with multiple resources.

This session will introduce GraphQL queries and demonstrate the advantages of changing the Drupal push model to a pull model by letting the template define its data requirements