Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

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

Slides of my talk at ApacheCon @Home 2020 - code at https://github.com/apache/sling-org-apache-sling-graphql-core/ (look for the "sample website") - video recording at https://youtu.be/KTMObGt0YKU

Related Books

Free with a 30 day trial from Scribd

See all

Related Audiobooks

Free with a 30 day trial from Scribd

See all
  • Be the first to comment

  • Be the first to like this

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

  1. 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
  2. 2. What's Apache Sling? ?
  3. 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
  4. 4. What's GraphQL ?
  5. 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. 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. 7. GraphQL in Apache Sling - Bertrand Delacrétaz September 2020 GraphQL Schema Introspection 7 The schema information helps us build this query:
  8. 8. Sling GraphQL Demo
  9. 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. 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. 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
  12. 12. Sling GraphQL Core
  13. 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. 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. 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. 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)
  17. 17. Caching?
  18. 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:
  19. 19. GraphQL and REST, BFFs ?
  20. 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. 21. CODA
  22. 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!

    Be the first to comment

Slides of my talk at ApacheCon @Home 2020 - code at https://github.com/apache/sling-org-apache-sling-graphql-core/ (look for the "sample website") - video recording at https://youtu.be/KTMObGt0YKU

Views

Total views

451

On Slideshare

0

From embeds

0

Number of embeds

8

Actions

Downloads

1

Shares

0

Comments

0

Likes

0

×