Top Banner
34

GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

May 23, 2020

Download

Documents

dariahiddleston
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...
Page 2: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

GraphQL in Twig

Saša NikoličAmazee Labs

Push vs. Pull

Page 3: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Hi! :)

■ Developer at Amazee Labs (Zurich,

Switzerland)

■ d.o.: sasanikolic

■ Twitter: @sasanikolic90

[email protected]

About me

Page 4: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Agenda

■ Current “push” status

■ Problem definition

■ Decoupled Drupal

■ GraphQL Twig

■ Examples

■ Keep in mind

■ Questions

Page 5: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

“Push” all data

Current status in D8

Page 6: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Current “Push” status

?!

Drupal Preprocessing Twig template

Page 7: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

How to build a gallery?

Page 8: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Image galleryCreation steps

1. Modules & libraries

2. Create content

3. Image styles

4. Create views

5. Place the block

6. Edit the view

7. Style it

Page 9: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Predefined HTML structure

Page 10: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

“Pull” data

DrupalTwig template

Page 11: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Decoupled Drupal

Page 12: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Decoupled Drupal

■ Drupal as a content service

■ Exposed content:

- Rest API

- JSON API

- GraphQL

■ Any frontend technology

Page 13: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

This is awesome!

Amazee Labs

“ “

Page 14: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

But…not always suitable

Amazee Labs

“ “

Page 15: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Decouple or not?

■ One or multiple experiences?

■ Drupal as site or repository?

■ Editorial needs?

■ Security?

■ Performance?

■ Javascript vs. PHP?

■ Budget

Read more: https://dri.es/how-to-decouple-drupal-in-2018

Page 16: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Progressively decoupled Drupal

Page 17: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Balanced approach

■ Javascript framework in front-end

■ Drupal for populating data

■ Good compromises

Page 18: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

GraphQL in Twig

Page 19: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

GraphQL

“Query language for APIs and a runtime

for fulfilling those queries with your

existing data.“

■ https://graphql.org

■ https://www.drupal.org/project/graphql

Page 20: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

GraphQL provides:

■ Understandable data description

■ No overfetching & underfetching

■ Powerful developer tools

Page 21: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Gallery example

Why “push” data? - “Pull” what you need!

Page 22: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Template override: node--article.html.twig

Page 23: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Fetching images added through Paragraphs and Media is relatively easy.

Page 24: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Gallery component in Fractal.

Page 25: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...
Page 26: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Block example

“Powered by Drupal”

Page 27: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Template override for “Powered by Drupal” block

Page 28: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Benefits

✓ Separation of concerns

✓ Rapid product iterations

✓ Less sitebuilding work

✓ Get exactly what you need

✓ Strong type system - provides a

schema

✓ Interfaces

✓ Full control of template structure

✓ Reasoning about data flow

✓ Tooling

✓ Well suited for atomic design

Page 29: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Things to keep in mind

■ Configuration logic moves to templates

■ Not fully covered yet

■ Syntax highlighting

■ Avoid too much mixing

Page 30: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Credits

Philipp Melab@pmelab

Sebastian Siemmsen@thefubhy

Page 31: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

THANKS!Any questions?

Page 32: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Resources

Philipp Melab, Don’t push it: using GraphQL in Twig: https://www.amazeelabs.com/en/blog/dont-push-it-using-graphql-twig

The fullstack tutorial for GraphQL: https://www.howtographql.com

Dries Buytaert, How to decouple Drupal in 2018: https://dri.es/how-to-decouple-drupal-in-2018

Preston So, Progressively Decoupled Drupal Approaches: https://dev.acquia.com/blog/progressively-decoupled-drupal-approaches/22/08/2016/1629

Druplicon: https://www.drupal.org/about/media-kit/logos

Twig icon: https://industrialagency.ca/blog/10-tips-twig-drupal-8

Page 33: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

Join us forcontribution sprints

Friday, April 13, 2018

9:00-12:00Room: Stolz 2

Mentored Core sprint

First timesprinter workshop

Generalsprint

#drupalsprint

9:00-12:00Room: Stolz 2

9:00-12:00Room: Stolz 2

Page 34: GraphQL in Twig - DrupalCon · -Rest API-JSON API-GraphQL Any frontend technology. This is awesome! Amazee Labs ...

What did you think?

Locate this session at the DrupalCon Nashville website:

http://nashville2018.drupal.org/schedule

Take the Survey!

https://www.surveymonkey.com/r/DrupalConNashville