SlideShare a Scribd company logo
GraphQL in Apache Sling...

but isn't it the opposite of REST?
Bertrand Delacrétaz :: Principal Scientist, Adobe

Board Member, Apache :: @bdelacretaz
Images are from stock.adobe.com unless otherwise specified - slides revision: 2020-09-28
What's Apache Sling? ?
GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 3
Content

Repository
Resource

Resolver
Scripting and
Rendering
Script
Resolver
Resource ScriptRequest Output
The Sling HTTP Request Processing Pipeline
1 2 3 4
sling:include
content aggregation!
3
A dynamic Resource-oriented Java and OSGi-based Web Applications Framework
What's GraphQL ?
GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 5
Query with the
same "shape" as
the output JSON.

Also: Mutations and
Subscriptions
POST to server returns

JSON output with just
what you need.
GraphQL in Apache Sling - Bertrand Delacrétaz September 2020
GraphQL Schema
6
In our case, the schema is
generated from an
internal Sling request to
<resource>.GQLschema
So it can be specific to a
given sling:resourceType
GraphQL in Apache Sling - Bertrand Delacrétaz September 2020
GraphQL Schema Introspection
7
The schema information
helps us build this query:
Sling GraphQL Demo
GraphQL in Apache Sling - Bertrand Delacrétaz September 2020
Sling-samples GraphQL website demo
9
Both server-side and client-side
rendering use GraphQL and
Handlebars.

GraphiQL and similar clients
supported out-of-the-box.

Clean JSON rendering

available via GraphQL.
Server-side (GraphQL + hbs)
Client-side

(GraphQL + hbs)
sling-samples/
org.apache.sling.graphql.samples.website
Client-side

queries
GraphQL in Apache Sling - Bertrand Delacrétaz September 2020
Client-side query + rendering
10
GraphQL

Servlet
Content

Repository
Client Sling Server
POST

GraphQL query
JSON results

-> Handlebars
GraphQL in Apache Sling - Bertrand Delacrétaz September 2020
Client Sling Server
11
GraphQL

Script Engine
Content

Repository
Sling Scripts

Resolver
article.hbs

script
Handlebars

Script Engine
Internal Request

<path>.GQLSchema
json.GQL

script
Server-side query + rendering The Handlebars
engine renders
the .json output of
the GraphQL query
GET

article.html
Internal Request

<path>.json
HTML
Sling GraphQL Core
GraphQL in Apache Sling - Bertrand Delacrétaz September 2020
Sling GraphQL Core 0.0.4
13
API

Script Engine

Servlet

Internally uses 

https://github.com/graphql-java/graphql-java
package

o.a.s.graphql.core.api
GraphQL in Apache Sling - Bertrand Delacrétaz September 2020
Default SchemaProvider
14
$ curl http://localhost:8080/content/articles/culture.GQLschema
type Query {
section: Section @fetcher(name:"website/currentResource")
navigation: Navigation @fetcher(name:"website/navigation")
}
type Navigation {
root: String
sections: [Section]
previous: String
next: String
search: String
}
...
Full power of the Sling rendering
pipeline for resource-specific
schemas.

The @fetcher directive points to
SlingDataFetcher services.
GraphQL in Apache Sling - Bertrand Delacrétaz September 2020
SlingDataFetcher
15
Java:

SlingDataFetcher OSGi
service, returns a

Map or POJO
Server-side script:
selected by fetcher name,
returns a Map
GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 16
Sling GraphQL Core
Request Handling
Schema Acquisition
graphql-java

parsing + delegation

www.graphql-java.com
Content

Repository
Other

Data Sources
Under the hood: performance?
SlingDataFetcher Services

Data Acquisition + Processing

Caching?
Client Sling Server
Performance
Happens Here ->
Schema Generation

(Sling Request Processing)
Caching?
GraphQL in Apache Sling - Bertrand Delacrétaz September 2020
HTTP-friendly caching?
18
Queries

Store
GraphQL

Servlet
Default POST-based

interaction is generally

not cacheable.
POST query text
201 Created -> /p/bc6f
GET /p/bc6f
200 OK -> query results

+ Cache-Control headers
Stored

Query

Text
Client Sling Server
future requests

can start here:
GraphQL and REST, BFFs ?
GraphQL in Apache Sling - Bertrand Delacrétaz September 2020
GraphQL and REST (+ RPC?)
20
Quoting Phil Sturgeon, builder of API design tools,
https://phil.tech/2017/graphql-vs-rest-overview/
We do need queries, but also
caching, hypertext, scalability.
GraphQL is certainly better than
a badly designed so-called REST
API...and it's a great query API.
CODA
GraphQL in Apache Sling - Bertrand Delacrétaz September 2020
CODA
GraphQL is a very nice query language
that also looks

useful on the server-side.
It's not better or worse than REST:
different animals that can

play well together!
I'm @bdelacretaz - thank you!

Code at https://github.com/apache/sling-org-apache-sling-graphql-core/

Fun text by https://github.com/apache/sling-whiteboard/tree/master/fake-content-generator
22
The Sling GraphQL Core is V0.0.4:

patches welcome!
Internal Sling requests FTW!

More Related Content

PDF
Building an Apache Sling Rendering Farm
PDF
Paving the way to a native Sling
ODP
Rapid JCR Applications Development with Sling
PDF
Sling and Serverless, Best Friends Forever?
PDF
Repoinit: a mini-language for content repository initialization
PDF
Serverless - introduction et perspectives concrètes
PDF
Day CRX Introduction
PDF
Apache Sling - The whys and the hows
Building an Apache Sling Rendering Farm
Paving the way to a native Sling
Rapid JCR Applications Development with Sling
Sling and Serverless, Best Friends Forever?
Repoinit: a mini-language for content repository initialization
Serverless - introduction et perspectives concrètes
Day CRX Introduction
Apache Sling - The whys and the hows

What's hot (20)

PPTX
Optimizing Spring Boot apps for Docker
PDF
Rh developers fat jar smackdown
PDF
DCSF19 Tips and Tricks of the Docker Captains
PDF
Droidcon Summary 2021
PDF
BBL Premiers pas avec Docker
PDF
DCEU 18: Dockerfile Best Practices
PDF
Continuous Integration: SaaS vs Jenkins in Cloud
PDF
Drone CI/CD 自動化測試及部署
PDF
Deploying 3 times a day without a downtime @ Rocket Tech Summit in Berlin
PDF
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
PDF
Streamline your development environment with docker
PDF
DocuOps & Asciidoctor in a JVM World
PDF
Cooking Perl with Chef: Real World Tutorial with Jitterbug
PDF
Swift Cloud Workshop - Swift Microservices
PDF
GraphQL IN Golang
PDF
Check the version with fixes. Link in description
PDF
jbang: Unleash the power of Java for shell scripting
PPT
Build service with_docker_in_90mins
PPTX
Real World Experience of Running Docker in Development and Production
Optimizing Spring Boot apps for Docker
Rh developers fat jar smackdown
DCSF19 Tips and Tricks of the Docker Captains
Droidcon Summary 2021
BBL Premiers pas avec Docker
DCEU 18: Dockerfile Best Practices
Continuous Integration: SaaS vs Jenkins in Cloud
Drone CI/CD 自動化測試及部署
Deploying 3 times a day without a downtime @ Rocket Tech Summit in Berlin
Hands on Docker - Launch your own LEMP or LAMP stack - SunshinePHP
Streamline your development environment with docker
DocuOps & Asciidoctor in a JVM World
Cooking Perl with Chef: Real World Tutorial with Jitterbug
Swift Cloud Workshop - Swift Microservices
GraphQL IN Golang
Check the version with fixes. Link in description
jbang: Unleash the power of Java for shell scripting
Build service with_docker_in_90mins
Real World Experience of Running Docker in Development and Production
Ad

Similar to GraphQL in Apache Sling - but isn't it the opposite of REST? (20)

PPTX
GraphQL Introduction with Spring Boot
PDF
GraphQL Bangkok meetup 5.0
PDF
Spring GraphQL
PDF
GraphQL across the stack: How everything fits together
PDF
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
PPTX
GraphQL - Missing Link In REST
PDF
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
PDF
Why UI developers love GraphQL
PDF
PHP, the GraphQL ecosystem and GraphQLite
PPTX
Introduction to GraphQL
PDF
GraphQL for Native Apps
PDF
GraphQL - A love story
PDF
Sling Component Filters in CQ5
PDF
Modern APIs with GraphQL
PDF
DEVOXX UK 2018 - GraphQL as an alternative approach to REST
PPTX
CONDG April 23 2020 - Baskar Rao - GraphQL
PDF
Graphql
PDF
Andrea Baldon, Emanuele Di Saverio - GraphQL for Native Apps: the MyAXA case ...
PPTX
GraphQL.pptx
PPTX
GraphQL.pptx
GraphQL Introduction with Spring Boot
GraphQL Bangkok meetup 5.0
Spring GraphQL
GraphQL across the stack: How everything fits together
GraphQL as an alternative approach to REST (as presented at Java2Days/CodeMon...
GraphQL - Missing Link In REST
Why UI Developers Love GraphQL - Sashko Stubailo, Apollo/Meteor
Why UI developers love GraphQL
PHP, the GraphQL ecosystem and GraphQLite
Introduction to GraphQL
GraphQL for Native Apps
GraphQL - A love story
Sling Component Filters in CQ5
Modern APIs with GraphQL
DEVOXX UK 2018 - GraphQL as an alternative approach to REST
CONDG April 23 2020 - Baskar Rao - GraphQL
Graphql
Andrea Baldon, Emanuele Di Saverio - GraphQL for Native Apps: the MyAXA case ...
GraphQL.pptx
GraphQL.pptx
Ad

More from Bertrand Delacretaz (20)

PDF
VanillaJS & the Web Platform, a match made in heaven?
PDF
Surviving large online communities with conciseness and clarity
PDF
The Moving House Model, adhocracy and remote collaboration
PDF
Open Source Changes the World!
PDF
How to convince your left brain (or manager) to follow the Open Source path t...
PDF
L'Open Source change le Monde - BlendWebMix 2019
PDF
Shared Neurons - the Secret Sauce of Open Source communities?
PDF
State of the Feather - ApacheCon North America 2018
PDF
Karate, the black belt of HTTP API testing?
PDF
Open Source at Scale: the Apache Software Foundation (2018)
PDF
They don't understand me! Tales from the multi-cultural trenches
PDF
Prise de Décisions Asynchrone, Devoxx France 2018 (avec vidéo)
PDF
Project and Community Services the Apache Way
PDF
La Fondation Apache - keynote au Paris Open Source Summit 2017
PDF
Asynchronous Decision Making - FOSS Backstage 2017
PDF
Who needs meetings? Asynchronous Decision Making to the rescue
PDF
Simple software is hard...don't give up!
PDF
I will NOT attend your meeting - I'm an Open Source person
PDF
Can we run the Whole Web on Apache Sling?
PDF
Open Development in the Enterprise, 19 minutes 2016 version
VanillaJS & the Web Platform, a match made in heaven?
Surviving large online communities with conciseness and clarity
The Moving House Model, adhocracy and remote collaboration
Open Source Changes the World!
How to convince your left brain (or manager) to follow the Open Source path t...
L'Open Source change le Monde - BlendWebMix 2019
Shared Neurons - the Secret Sauce of Open Source communities?
State of the Feather - ApacheCon North America 2018
Karate, the black belt of HTTP API testing?
Open Source at Scale: the Apache Software Foundation (2018)
They don't understand me! Tales from the multi-cultural trenches
Prise de Décisions Asynchrone, Devoxx France 2018 (avec vidéo)
Project and Community Services the Apache Way
La Fondation Apache - keynote au Paris Open Source Summit 2017
Asynchronous Decision Making - FOSS Backstage 2017
Who needs meetings? Asynchronous Decision Making to the rescue
Simple software is hard...don't give up!
I will NOT attend your meeting - I'm an Open Source person
Can we run the Whole Web on Apache Sling?
Open Development in the Enterprise, 19 minutes 2016 version

Recently uploaded (20)

PPTX
QR Codes Qr codecodecodecodecocodedecodecode
PDF
SASE Traffic Flow - ZTNA Connector-1.pdf
PPT
Design_with_Watersergyerge45hrbgre4top (1).ppt
PDF
Paper PDF World Game (s) Great Redesign.pdf
PPTX
introduction about ICD -10 & ICD-11 ppt.pptx
PPTX
Introduction to Information and Communication Technology
PPTX
Introuction about WHO-FIC in ICD-10.pptx
PPTX
artificial intelligence overview of it and more
PPTX
international classification of diseases ICD-10 review PPT.pptx
PPTX
Job_Card_System_Styled_lorem_ipsum_.pptx
PDF
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
PDF
Cloud-Scale Log Monitoring _ Datadog.pdf
PDF
WebRTC in SignalWire - troubleshooting media negotiation
PPTX
INTERNET------BASICS-------UPDATED PPT PRESENTATION
PDF
The Internet -By the Numbers, Sri Lanka Edition
PPTX
innovation process that make everything different.pptx
PPTX
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
PPTX
Introuction about ICD -10 and ICD-11 PPT.pptx
PDF
RPKI Status Update, presented by Makito Lay at IDNOG 10
PDF
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...
QR Codes Qr codecodecodecodecocodedecodecode
SASE Traffic Flow - ZTNA Connector-1.pdf
Design_with_Watersergyerge45hrbgre4top (1).ppt
Paper PDF World Game (s) Great Redesign.pdf
introduction about ICD -10 & ICD-11 ppt.pptx
Introduction to Information and Communication Technology
Introuction about WHO-FIC in ICD-10.pptx
artificial intelligence overview of it and more
international classification of diseases ICD-10 review PPT.pptx
Job_Card_System_Styled_lorem_ipsum_.pptx
Automated vs Manual WooCommerce to Shopify Migration_ Pros & Cons.pdf
Cloud-Scale Log Monitoring _ Datadog.pdf
WebRTC in SignalWire - troubleshooting media negotiation
INTERNET------BASICS-------UPDATED PPT PRESENTATION
The Internet -By the Numbers, Sri Lanka Edition
innovation process that make everything different.pptx
Introduction about ICD -10 and ICD11 on 5.8.25.pptx
Introuction about ICD -10 and ICD-11 PPT.pptx
RPKI Status Update, presented by Makito Lay at IDNOG 10
Best Practices for Testing and Debugging Shopify Third-Party API Integrations...

GraphQL in Apache Sling - but isn't it the opposite of REST?

  • 1. GraphQL in Apache Sling...
 but isn't it the opposite of REST? Bertrand Delacrétaz :: Principal Scientist, Adobe
 Board Member, Apache :: @bdelacretaz Images are from stock.adobe.com unless otherwise specified - slides revision: 2020-09-28
  • 3. GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 3 Content
 Repository Resource
 Resolver Scripting and Rendering Script Resolver Resource ScriptRequest Output The Sling HTTP Request Processing Pipeline 1 2 3 4 sling:include content aggregation! 3 A dynamic Resource-oriented Java and OSGi-based Web Applications Framework
  • 5. GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 5 Query with the same "shape" as the output JSON.
 Also: Mutations and Subscriptions POST to server returns
 JSON output with just what you need.
  • 6. GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 GraphQL Schema 6 In our case, the schema is generated from an internal Sling request to <resource>.GQLschema So it can be specific to a given sling:resourceType
  • 7. GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 GraphQL Schema Introspection 7 The schema information helps us build this query:
  • 9. GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 Sling-samples GraphQL website demo 9 Both server-side and client-side rendering use GraphQL and Handlebars.
 GraphiQL and similar clients supported out-of-the-box.
 Clean JSON rendering
 available via GraphQL. Server-side (GraphQL + hbs) Client-side
 (GraphQL + hbs) sling-samples/ org.apache.sling.graphql.samples.website Client-side
 queries
  • 10. GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 Client-side query + rendering 10 GraphQL
 Servlet Content
 Repository Client Sling Server POST
 GraphQL query JSON results
 -> Handlebars
  • 11. GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 Client Sling Server 11 GraphQL
 Script Engine Content
 Repository Sling Scripts
 Resolver article.hbs
 script Handlebars
 Script Engine Internal Request
 <path>.GQLSchema json.GQL
 script Server-side query + rendering The Handlebars engine renders the .json output of the GraphQL query GET
 article.html Internal Request
 <path>.json HTML
  • 13. GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 Sling GraphQL Core 0.0.4 13 API
 Script Engine
 Servlet
 Internally uses 
 https://github.com/graphql-java/graphql-java package
 o.a.s.graphql.core.api
  • 14. GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 Default SchemaProvider 14 $ curl http://localhost:8080/content/articles/culture.GQLschema type Query { section: Section @fetcher(name:"website/currentResource") navigation: Navigation @fetcher(name:"website/navigation") } type Navigation { root: String sections: [Section] previous: String next: String search: String } ... Full power of the Sling rendering pipeline for resource-specific schemas.
 The @fetcher directive points to SlingDataFetcher services.
  • 15. GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 SlingDataFetcher 15 Java:
 SlingDataFetcher OSGi service, returns a
 Map or POJO Server-side script: selected by fetcher name, returns a Map
  • 16. GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 16 Sling GraphQL Core Request Handling Schema Acquisition graphql-java
 parsing + delegation
 www.graphql-java.com Content
 Repository Other
 Data Sources Under the hood: performance? SlingDataFetcher Services
 Data Acquisition + Processing
 Caching? Client Sling Server Performance Happens Here -> Schema Generation
 (Sling Request Processing)
  • 18. GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 HTTP-friendly caching? 18 Queries
 Store GraphQL
 Servlet Default POST-based
 interaction is generally
 not cacheable. POST query text 201 Created -> /p/bc6f GET /p/bc6f 200 OK -> query results
 + Cache-Control headers Stored
 Query
 Text Client Sling Server future requests
 can start here:
  • 20. GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 GraphQL and REST (+ RPC?) 20 Quoting Phil Sturgeon, builder of API design tools, https://phil.tech/2017/graphql-vs-rest-overview/ We do need queries, but also caching, hypertext, scalability. GraphQL is certainly better than a badly designed so-called REST API...and it's a great query API.
  • 21. CODA
  • 22. GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 CODA GraphQL is a very nice query language that also looks
 useful on the server-side. It's not better or worse than REST: different animals that can
 play well together! I'm @bdelacretaz - thank you!
 Code at https://github.com/apache/sling-org-apache-sling-graphql-core/
 Fun text by https://github.com/apache/sling-whiteboard/tree/master/fake-content-generator 22 The Sling GraphQL Core is V0.0.4:
 patches welcome! Internal Sling requests FTW!