SpringOne Tour June, 2022 - Toronto Spring for GraphQL Copyright © 2022 VMware, Inc. or its affiliates.
Cover w/ Image Agenda ● Why GraphQL? ● What is GraphQL? ● GraphQL Java ● Spring for GraphQL ● Q&A
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)
Why GraphQL?
Current Architecture
Current Architecture GET /products/123
Current Architecture
GraphQL Architecture POST /graphql
Current Architecture GET /products/123 GET /products/123/related GET /products/123/reviews
Current Architecture POST /graphql
What is GraphQL?
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.
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
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.
Type System
Object Type
Object Type Field Field Field
Object Type Field Built-in scalar types Field Field Field
Object Type Field Built-in scalar types non-nullable Field Field Field
Object Type Field Built-in scalar types non-nullable Field Field Field Object Type
Object Type Field Built-in scalar types non-nullable Field Field Field Custom scalar type Object Type
Object Type Field Built-in scalar types non-nullable Field Field Field Custom scalar type Object Type Enum
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.
Operation Types Most types in your schema will just be normal object types, but there are three types that are special within a schema:
Query Name
Query Name Return Type
GraphiQL Demo
GraphQL Java
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/
Spring for GraphQL
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
Spring for GraphQL: Server Transports
Spring for GraphQL: Server Transports HTTP WebSocket RSocket
Spring Boot Starter The Spring Boot Starter Graphql (spring-boot-starter-graphql) ● Dependencies ● Autoconfig ● Properties ● Metrics ● GraphiQL UI and Schema Pages
Auto-configured Spring GraphQL Tests
GraphQL Slice Test ● @Controller ● RuntimeWiringConfigurer ● JsonComponent ● Converter ● GenericConverter ● DataFetcherExceptionResolver ● Instrumentation ● GraphQlSourceBuilderCustomizer
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
Spring for GraphQL Demo https: / / github.com/danvega/graphql-store
Thank you Contact me at dvega@vmware.com @therealdanvega © 2020 Spring. A VMware-backed project.

Getting Started with Spring for GraphQL