Push vs. Pull GraphQL in Twig Saa Nikoli Amazee Labs About me - - PowerPoint PPT Presentation

push vs pull
SMART_READER_LITE
LIVE PREVIEW

Push vs. Pull GraphQL in Twig Saa Nikoli Amazee Labs About me - - PowerPoint PPT Presentation

Push vs. Pull GraphQL in Twig Saa Nikoli Amazee Labs About me Hi! :) Developer at Amazee Labs (Zurich, Switzerland) d.o.: sasanikolic Twitter: @sasanikolic90 sasa.nikolic@amazee.com Agenda Current push status


slide-1
SLIDE 1
slide-2
SLIDE 2

GraphQL in Twig

Saša Nikolič Amazee Labs

Push vs. Pull

slide-3
SLIDE 3

Hi! :) ■ Developer at Amazee Labs (Zurich, Switzerland) ■ d.o.: sasanikolic ■ Twitter: @sasanikolic90 ■ sasa.nikolic@amazee.com

About me

slide-4
SLIDE 4

Agenda

■ Current “push” status ■ Problem definition ■ Decoupled Drupal ■ GraphQL Twig ■ Examples ■ Keep in mind ■ Questions

slide-5
SLIDE 5

“Push” all data

Current status in D8

slide-6
SLIDE 6

Current “Push” status

?!

Drupal Preprocessing Twig template

slide-7
SLIDE 7

How to build a gallery?

slide-8
SLIDE 8

Image gallery

Creation steps

  • 1. Modules & libraries
  • 2. Create content
  • 3. Image styles
  • 4. Create views
  • 5. Place the block
  • 6. Edit the view
  • 7. Style it
slide-9
SLIDE 9

Predefined HTML structure

slide-10
SLIDE 10

“Pull” data

Drupal Twig template

slide-11
SLIDE 11

Decoupled Drupal

slide-12
SLIDE 12

Decoupled Drupal

■ Drupal as a content service ■ Exposed content:

  • Rest API
  • JSON API
  • GraphQL

■ Any frontend technology

slide-13
SLIDE 13

This is awesome!

Amazee Labs

“ “

slide-14
SLIDE 14

But… not always suitable

Amazee Labs

“ “

slide-15
SLIDE 15

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

slide-16
SLIDE 16

Progressively decoupled Drupal

slide-17
SLIDE 17

Balanced approach

■ Javascript framework in front-end ■ Drupal for populating data ■ Good compromises

slide-18
SLIDE 18

GraphQL in Twig

slide-19
SLIDE 19

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

slide-20
SLIDE 20

GraphQL provides:

■ Understandable data description ■ No overfetching & underfetching ■ Powerful developer tools

slide-21
SLIDE 21

Gallery example

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

slide-22
SLIDE 22

Template override: node--article.html.twig

slide-23
SLIDE 23

Fetching images added through Paragraphs and Media is relatively easy.

slide-24
SLIDE 24

Gallery component in Fractal.

slide-25
SLIDE 25
slide-26
SLIDE 26

Block example

“Powered by Drupal”

slide-27
SLIDE 27

Template override for “Powered by Drupal” block

slide-28
SLIDE 28

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

slide-29
SLIDE 29

Things to keep in mind

■ Configuration logic moves to templates ■ Not fully covered yet ■ Syntax highlighting ■ Avoid too much mixing

slide-30
SLIDE 30

Credits

Philipp Melab @pmelab Sebastian Siemmsen @thefubhy

slide-31
SLIDE 31

THANKS! Any questions?

slide-32
SLIDE 32

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

slide-33
SLIDE 33

Join us for contribution sprints

Friday, April 13, 2018

9:00-12:00 Room: Stolz 2

Mentored Core sprint First time sprinter workshop General sprint

#drupalsprint

9:00-12:00 Room: Stolz 2 9:00-12:00 Room: Stolz 2

slide-34
SLIDE 34

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