Slide 1

Slide 1 text

Spring GraphQL @maciejwalkowiak

Slide 2

Slide 2 text

Web Applications < 2010

Slide 3

Slide 3 text

Enterprise Applications < 2010

Slide 4

Slide 4 text

Mobile Apps > 2007

Slide 5

Slide 5 text

Angular & SPA > 2011

Slide 6

Slide 6 text

Angular & SPA > 2011

Slide 7

Slide 7 text

Different Clients - Different Needs browser displays more data and more types of data - payload size is not a huge issue mobile client displays small amount of data - small payload size is critical for UX Web: Mobile: GET /books [ { "id": 122, "title": "Modern Java", "publicationYear": 2021, "coverUrl": "https://...", "authorId": 344, "description": "... long description text ..." }, ... ] GET /books [ { "id": 122, "title": "Modern Java", "publicationYear": 2021, "coverUrl": "https://...", "authorId": 344 }, ... ]

Slide 8

Slide 8 text

Data Composition client is responsible for data composition multiple requests sent from client (potential N+1 problem) Fetch books: Fetch authors: GET /books [ { "id": 122, "title": "Modern Java", "publicationYear": 2021, "coverUrl": "https://...", "authorId": 344, }, { "id": 123, "title": "Spring in Action", "publicationYear": 2020, "coverUrl": "https://...", "authorId": 345, } ] GET /authors/344 { "id": 344, "name": "John Smith", "avatarUrl": "https://..." } GET /authors/345 { "id": 344, "name": "John Smith", "avatarUrl": "https://..." }

Slide 9

Slide 9 text

Problem with REST(ish) APIs REST is an architecture style no spec - just principles difficult to get "right" overfetching expensive data composition no schema hypermedia isn’t what developers want

Slide 10

Slide 10 text

This is not a REST critique Also, look at https://jsonapi.org/.

Slide 11

Slide 11 text

Hello GraphQL Forget everything you know about REST Ignore HTTP methods, status codes, caching A query language for your API GraphQL is a query language for APIs and a runtime for fulfilling those queries with your existing data. GraphQL provides a complete and understandable description of the data in your API, gives clients the power to ask for exactly what they need and nothing more, makes it easier to evolve APIs over time, and enables powerful developer tools.

Slide 12

Slide 12 text

GraphQL Schema: Query: Results: type Query { findAuthors: [Author] author(id: ID!): Author } type Author { id: ID! name: String! age: Int books: [Book] } type Book { id: ID! title: String! author: Author! publicationYear: Int } query { findAuthors { id name books { title } } } { "data": { "findAuthors": [ { "id": "1", "name": "maciej", "books": [ { "title": "book 1" },

Slide 13

Slide 13 text

DEMO

Slide 14

Slide 14 text

We have just scratched the surface

Slide 15

Slide 15 text

Challenges microservies & single /graphql endpoint? caching? database transactions? ` `

Slide 16

Slide 16 text

Continue Learning https://www.graphql-java.com/ https://spring.io/projects/spring-graphql https://www.howtographql.com/ https://youtube.com/springacademy <-- that’s me follow @maciejwalkowiak on twitter

Slide 17

Slide 17 text

Thank you!