Skip to content

Spring for GraphQL 1.3

Rossen Stoyanchev edited this page May 21, 2024 · 6 revisions

What's New in Spring for GraphQL 1.3

New Features

Virtual Thread Support

On Java 21+, when AnnotatedControllerConfigurer is configured with an Executor, e.g. when the Spring Boot property spring.threads.virtual.enabled is set, controller methods with a blocking method signature are invoked asynchronously. Method are considered blocking if they do not return Flux, Mono or CompletableFuture, and are not a Kotlin suspending function. You can configure a blocking controller method Predicate on AnnotatedControllerConfigurer.

Synchronous GraphQlClient

GraphQlClient provides a common workflow for GraphQL requests over any transport including HTTP, WebSocket, and RSocket. You can now use it on a blocking stack over the synchronous RestClient, and with a synchronous API. See the reference docs for details.

DgsGraphQlClient

DgsGraphQlClient is a thin wrapper around any GraphQlClient that is designed to work with a DGS generated client API. See the reference docs for details. In addition Spring Initializer supports creating Spring GraphQL projects with DGS codegen enabled.

SSE (Server-Sent Events) Transport

There is now support for GraphQL subscriptions over SSE with Spring MVC and WebFlux based on the GraphQL over SSE spec. See the reference docs for details. On the client side, HttpGraphQlClient supports GraphQL subscriptions over SSE via WebClient.

Apollo Federation

There is now built-in support for federation. The FederationSchemaFactory assists with configuration and detects @EntityMapping controller methods to load federated entity types. For details see the reference docs and the updated federation-jvm-spring-example.

Interface Field Mapping

There is now support for mapping schema interface fields by making repeated registrations for the same field once for every implementing object type transparently unless any already exist. This works for both @SchemaMapping and for @BatchMapping methods.

Schema Inspection of Unions and Interfaces

Schema inspection supports interfaces and unions, which may work transparently, depending on the exact naming convention, by discovering Java types that correspond to interface implementing and union member types. If necessary, there are options to customize this to help the inspection.

Schema Inspection of Arguments

Schema inspection reports mismatches between @Argument controller method parameters and field arguments declared in the schema.

Authentication via WebSocket connection_init

You can use built-in interceptors for authentication with GraphQL over WebSocket extracted from the payload of the "connection_init" message, and subsequently propagated to requests on the WebSocket connection. See the reference and the graphql-websocket-auth sample.

WebSocket Keep-Alive

Client and server WebSocket transports support sending PING messages at regular intervals if no other messages have been sent. On the server side, this is enabled through the Spring Boot property spring.graphql.websocket.keep-alive. On the client side, this is enabled through the client builder.

Interceptors on WebSocketGraphQlTester

WebSocketGraphQlTester support configuring interceptors, which can be used for example to specify authentication information through a "connection_init" payload.

Jackson Codec for GraphQL Endpoint

It is now possible to configure a Jackson codec for a GraphQL endpoint separate from the one used for HTTP and web endpoints. This can be important to render GraphQL responses as needed (e.g. with null values) without causing side effects for regular HTTP endpoints.

Kotlin Flow Return Value

Annotated controller methods can return Kotlin Flow.

Other

Incremental Delivery

GraphQL Java 22 provides experimental support for incremental delivery. To learn more see the Working Group page. To experiment, see the spring-graphql-defer sample.