$30 off During Our Annual Pro Sale. View Details »

Spring for GraphQL

Spring for GraphQL

Spring for GraphQL presentation gave at Start of Java online meetup.

https://github.com/maciejwalkowiak/spring-for-graphql-talk

Maciej Walkowiak

September 28, 2022
Tweet

More Decks by Maciej Walkowiak

Other Decks in Programming

Transcript

  1. Spring GraphQL @maciejwalkowiak

  2. Web Applications < 2010

  3. Enterprise Applications < 2010

  4. Mobile Apps > 2007

  5. Angular & SPA > 2011

  6. Angular & SPA > 2011

  7. 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 }, ... ]
  8. 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://..." }
  9. 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
  10. This is not a REST critique Also, look at https://jsonapi.org/.

  11. 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.
  12. 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" },
  13. DEMO

  14. We have just scratched the surface

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

    `
  16. 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
  17. Thank you!