Diese Präsentation wurde erfolgreich gemeldet.
Die SlideShare-Präsentation wird heruntergeladen. ×

Getting Started with Spring for GraphQL

Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Anzeige
Nächste SlideShare
GraphQL + relay
GraphQL + relay
Wird geladen in …3
×

Hier ansehen

1 von 44 Anzeige

Getting Started with Spring for GraphQL

Herunterladen, um offline zu lesen

WaffleCorp is a major provider of breakfast products available direct to consumer or through our strategic partnerships. The current implementation of the e-commerce platform is a monolithic Spring MVC application that serves data through a collection of REST APIs.

Currently, the only provider of the REST API is our e-commerce web application. We've been tasked with opening up our APIs to our new iOS and Android apps, partner microservices, and IoT applications.

The issue we ran into is that a REST API is not a one-size-fits-all approach. We need a more flexible solution to meet the requirements of all of our client applications. This is a perfect use case for the speed and flexibility of GraphQL.

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.

In this session, you’ll learn what GraphQL is and why you should consider it in your next project. You’ll learn how to use GraphQL in your Spring Boot applications by leveraging the Spring for GraphQL project. By the end of this session, you’ll understand how to stand up a GraphQL endpoint and request the data you need, and nothing more.

WaffleCorp is a major provider of breakfast products available direct to consumer or through our strategic partnerships. The current implementation of the e-commerce platform is a monolithic Spring MVC application that serves data through a collection of REST APIs.

Currently, the only provider of the REST API is our e-commerce web application. We've been tasked with opening up our APIs to our new iOS and Android apps, partner microservices, and IoT applications.

The issue we ran into is that a REST API is not a one-size-fits-all approach. We need a more flexible solution to meet the requirements of all of our client applications. This is a perfect use case for the speed and flexibility of GraphQL.

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.

In this session, you’ll learn what GraphQL is and why you should consider it in your next project. You’ll learn how to use GraphQL in your Spring Boot applications by leveraging the Spring for GraphQL project. By the end of this session, you’ll understand how to stand up a GraphQL endpoint and request the data you need, and nothing more.

Anzeige
Anzeige

Weitere Verwandte Inhalte

Ähnlich wie Getting Started with Spring for GraphQL (20)

Weitere von VMware Tanzu (20)

Anzeige

Aktuellste (20)

Getting Started with Spring for GraphQL

  1. 1. SpringOne Tour June, 2022 - Toronto Spring for GraphQL Copyright © 2022 VMware, Inc. or its affiliates.
  2. 2. Cover w/ Image Agenda ● Why GraphQL? ● What is GraphQL? ● GraphQL Java ● Spring for GraphQL ● Q&A
  3. 3. Cover w/ Image WaffleCorp ● WaffleCorp Products ● Direct to Consumer ● Strategic Partnerships ● WaffleCorp e-commerce service ● Monolithic Spring Boot MVC ● REST API ● Vue Front End ● Open up our REST APIs ● Partner Microservices ● iOS and Android applications ● IoT Applications (Smart Toaster)
  4. 4. Why GraphQL?
  5. 5. Current Architecture
  6. 6. Current Architecture GET /products/123
  7. 7. Current Architecture
  8. 8. GraphQL Architecture POST /graphql
  9. 9. Current Architecture GET /products/123 GET /products/123/related GET /products/123/reviews
  10. 10. Current Architecture POST /graphql
  11. 11. What is GraphQL?
  12. 12. GraphQL is a query language for your API, and a server-side runtime for executing queries using a type system you de fi ne for your data. GraphQL isn't tied to any speci fi c database or storage engine and is instead backed by your existing code and data.
  13. 13. What is GraphQL? GraphQL is a technology for client server data exchange ● Alternative to REST APIs ● Provides a really great developer experience ● Created by Facebook in 2012 ● Open Sourced in 2015 ● Governed by a neutral foundation today ● Client + Server: 🤝 ● Client Side Query Language ● Server Side execution engine
  14. 14. Client + Server 🤝 Client ● Custom GraphQL Query Language ● Client crafted query based on their needs ● Responses return only what client requests ● Developer Tooling Server ● GraphQL Schema defines your API ● Schema based on simple static type system ● Schema Definition Language (SDL) is used to describe a schema. ● Implemented in specific languages based on the GraphQL specification.
  15. 15. Type System
  16. 16. Object Type
  17. 17. Object Type Field Field Field
  18. 18. Object Type Field Built-in scalar types Field Field Field
  19. 19. Object Type Field Built-in scalar types non-nullable Field Field Field
  20. 20. Object Type Field Built-in scalar types non-nullable Field Field Field Object Type
  21. 21. Object Type Field Built-in scalar types non-nullable Field Field Field Custom scalar type Object Type
  22. 22. Object Type Field Built-in scalar types non-nullable Field Field Field Custom scalar type Object Type Enum
  23. 23. GraphQL Schema: Scalar Types GraphQL comes with a set of default scalar types out of the box: ● Int: A signed 32-bit Integer. ● Float: A signed double-precision floating point value. ● String: A UTF-8 character sequence. ● Boolean: true or false. ● ID: The ID scalar type represents a unique identifier, often used to refetch an object or as the key for a cache. The ID type is serialized in the same way as a String; however, defining it as an ID signifies that it is not intended to be human ‐ readable.
  24. 24. Operation Types Most types in your schema will just be normal object types, but there are three types that are special within a schema:
  25. 25. Query Name
  26. 26. Query Name Return Type
  27. 27. GraphiQL Demo
  28. 28. GraphQL Java
  29. 29. GraphQL Java GraphQL Java is the GraphQL implementation for Java ● Started mid 2015 ● Andreas Marek, Software Architect at Atlassian ● Bootiful Podcast Interview with Andreas ● Pure Execution Engine: No HTTP or IO. No high level abstractions ● Active on Github ● 5.5k Stars / 1000 Forks ● Adds Custom Scalar Types ● https://www.graphql-java.com/
  30. 30. Spring for GraphQL
  31. 31. What is Spring for GraphQL Spring for GraphQL provides support for Spring applications built on GraphQL Java. ● Joint collaboration between both teams ● GraphQL Java is “limited” on purpose ● Spring Projects - Make complex problems easy ● Requirements ● JDK8 ● Spring Framework 5.3 ● GraphQL Java 17 ● Spring Data 2021.1.0 or later for QueryDSL or Query by Example ● Spring Boot 2.7+ ● Current Version: 1.0.0 🥳 ● 1.0 GA: 05/17/2022
  32. 32. Spring for GraphQL: Server Transports
  33. 33. Spring for GraphQL: Server Transports HTTP WebSocket RSocket
  34. 34. Spring Boot Starter The Spring Boot Starter Graphql (spring-boot-starter-graphql) ● Dependencies ● Autoconfig ● Properties ● Metrics ● GraphiQL UI and Schema Pages
  35. 35. Auto-configured Spring GraphQL Tests
  36. 36. GraphQL Slice Test ● @Controller ● RuntimeWiringConfigurer ● JsonComponent ● Converter ● GenericConverter ● DataFetcherExceptionResolver ● Instrumentation ● GraphQlSourceBuilderCustomizer
  37. 37. Spring for GraphQL: Testing spring-graphql-test GraphQlTester ● Workflow for testing GraphQL ● Fluent API ● Automatic checks to verify no errors in response ● Use JsonPath to specify data to inspect ● Data Decoding WebGraphQlTester ● Extension of GraphQL tests over web transports ● Specific HTTP specific inputs ● Uses WebTestClient
  38. 38. Spring for GraphQL Demo https: / / github.com/danvega/graphql-store
  39. 39. Thank you Contact me at dvega@vmware.com @therealdanvega © 2020 Spring. A VMware-backed project.

×