From 462e73ede6d421195a01e6cadfdbd1e2a129af0b Mon Sep 17 00:00:00 2001 From: Brian Clozel Date: Mon, 7 Apr 2025 10:48:58 +0200 Subject: [PATCH] Upgrade to GraphQL Java 23.0 This commit upgrades to GraphQL Java 23.0. Because this new version brings in java-dataloader 4.0.0, this commit also adapts to a breaking change there. `DataLoaderOptions` is now immutable and calling setters on it will return a new instance. As a result, this commit also changes the `BatchLoaderRegistry` to customize the dataloader by consuming a `DataLoaderOptions.Builder` instead of a `DataLoaderOptions` directly. This only breaks binary compatibility as both `DataLoaderOptions` and `DataLoaderOptions.Builder` have identical APIs. Closes gh-1169 --- build.gradle | 2 +- spring-graphql/build.gradle | 2 +- .../graphql/execution/BatchLoaderRegistry.java | 13 +++++++------ .../execution/DefaultBatchLoaderRegistry.java | 13 ++++++------- .../graphql/client/GraphQlClientTests.java | 1 + 5 files changed, 16 insertions(+), 15 deletions(-) diff --git a/build.gradle b/build.gradle index e7f56d3f..6e5d4f00 100644 --- a/build.gradle +++ b/build.gradle @@ -3,7 +3,7 @@ description = "Spring for GraphQL" ext { moduleProjects = [project(":spring-graphql"), project(":spring-graphql-test")] springFrameworkVersion = "6.2.3" - graphQlJavaVersion = "22.3" + graphQlJavaVersion = "23.0" springBootVersion = "3.4.3" } diff --git a/spring-graphql/build.gradle b/spring-graphql/build.gradle index 1c86a786..37c95bb5 100644 --- a/spring-graphql/build.gradle +++ b/spring-graphql/build.gradle @@ -37,7 +37,7 @@ dependencies { compileOnly('com.apollographql.federation:federation-graphql-java-support') compileOnly('com.netflix.graphql.dgs.codegen:graphql-dgs-codegen-shared-core') { exclude group: "com.apollographql.federation", module: "federation-graphql-java-support" - exclude group: "com.graphql-java", module: "graphql-java" + exclude group: "com.graphql-java" } testImplementation 'org.junit.jupiter:junit-jupiter' diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/BatchLoaderRegistry.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/BatchLoaderRegistry.java index a7ad92fe..db8f45f9 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/BatchLoaderRegistry.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/BatchLoaderRegistry.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2021 the original author or authors. + * Copyright 2002-2025 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -39,7 +39,7 @@ import reactor.core.publisher.Mono; * * @author Rossen Stoyanchev * @since 1.0.0 - * @see Using DataLoader + * @see Using DataLoader * @see org.dataloader.BatchLoader * @see org.dataloader.MappedBatchLoader * @see org.dataloader.DataLoader @@ -101,15 +101,16 @@ public interface BatchLoaderRegistry extends DataLoaderRegistrar { * Customize the {@link DataLoaderOptions} to use to create the * {@link org.dataloader.DataLoader} via {@link org.dataloader.DataLoaderFactory}. *

Note: Do not set - * {@link DataLoaderOptions#setBatchLoaderContextProvider(BatchLoaderContextProvider)} + * {@link DataLoaderOptions.Builder#setBatchLoaderContextProvider(BatchLoaderContextProvider)} * as this will be set later to a provider that returns the context from * {@link ExecutionInput#getGraphQLContext()}, so that batch loading * functions and data fetchers can rely on access to the same context. - * @param optionsConsumer callback to customize the options, invoked - * immediately and given access to the options instance + * @param optionsBuilderConsumer callback to customize the options, invoked + * immediately and given access to the options builder instance * @return a spec to complete the registration + * @since 1.4.0 */ - RegistrationSpec withOptions(Consumer optionsConsumer); + RegistrationSpec withOptions(Consumer optionsBuilderConsumer); /** * Set the {@link DataLoaderOptions} to use to create the diff --git a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistry.java b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistry.java index d98a6bdb..468fdc30 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistry.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistry.java @@ -132,7 +132,7 @@ public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry { private DataLoaderOptions options; @Nullable - private Consumer optionsConsumer; + private Consumer optionsBuilderConsumer; DefaultRegistrationSpec(Class valueType) { this.valueType = valueType; @@ -150,9 +150,9 @@ public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry { } @Override - public RegistrationSpec withOptions(Consumer optionsConsumer) { - this.optionsConsumer = (this.optionsConsumer != null) ? - this.optionsConsumer.andThen(optionsConsumer) : optionsConsumer; + public RegistrationSpec withOptions(Consumer optionsBuilderConsumer) { + this.optionsBuilderConsumer = (this.optionsBuilderConsumer != null) ? + this.optionsBuilderConsumer.andThen(optionsBuilderConsumer) : optionsBuilderConsumer; return this; } @@ -188,14 +188,13 @@ public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry { new DataLoaderOptions((this.options != null) ? this.options : DefaultBatchLoaderRegistry.this.defaultOptionsSupplier.get()); - if (this.optionsConsumer == null) { + if (this.optionsBuilderConsumer == null) { return optionsSupplier; } return () -> { DataLoaderOptions options = optionsSupplier.get(); - this.optionsConsumer.accept(options); - return options; + return options.transform(this.optionsBuilderConsumer); }; } } diff --git a/spring-graphql/src/test/java/org/springframework/graphql/client/GraphQlClientTests.java b/spring-graphql/src/test/java/org/springframework/graphql/client/GraphQlClientTests.java index 63eb9251..e1e95fa9 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/client/GraphQlClientTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/client/GraphQlClientTests.java @@ -187,6 +187,7 @@ public class GraphQlClientTests extends GraphQlClientTestSupport { } @Test + @SuppressWarnings("cast") void executePartialResponse() { String document = "fieldErrorResponse";