Skip to content

Commit 462e73e

Browse files
committed
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
1 parent eb5a83a commit 462e73e

File tree

5 files changed

+16
-15
lines changed

5 files changed

+16
-15
lines changed

Diff for: build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ description = "Spring for GraphQL"
33
ext {
44
moduleProjects = [project(":spring-graphql"), project(":spring-graphql-test")]
55
springFrameworkVersion = "6.2.3"
6-
graphQlJavaVersion = "22.3"
6+
graphQlJavaVersion = "23.0"
77
springBootVersion = "3.4.3"
88
}
99

Diff for: spring-graphql/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ dependencies {
3737
compileOnly('com.apollographql.federation:federation-graphql-java-support')
3838
compileOnly('com.netflix.graphql.dgs.codegen:graphql-dgs-codegen-shared-core') {
3939
exclude group: "com.apollographql.federation", module: "federation-graphql-java-support"
40-
exclude group: "com.graphql-java", module: "graphql-java"
40+
exclude group: "com.graphql-java"
4141
}
4242

4343
testImplementation 'org.junit.jupiter:junit-jupiter'

Diff for: spring-graphql/src/main/java/org/springframework/graphql/execution/BatchLoaderRegistry.java

+7-6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2021 the original author or authors.
2+
* Copyright 2002-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -39,7 +39,7 @@
3939
*
4040
* @author Rossen Stoyanchev
4141
* @since 1.0.0
42-
* @see <a href="https://www.graphql-java.com/documentation/v16/batching/">Using DataLoader</a>
42+
* @see <a href="https://www.graphql-java.com/documentation/batching/">Using DataLoader</a>
4343
* @see org.dataloader.BatchLoader
4444
* @see org.dataloader.MappedBatchLoader
4545
* @see org.dataloader.DataLoader
@@ -101,15 +101,16 @@ interface RegistrationSpec<K, V> {
101101
* Customize the {@link DataLoaderOptions} to use to create the
102102
* {@link org.dataloader.DataLoader} via {@link org.dataloader.DataLoaderFactory}.
103103
* <p><strong>Note:</strong> Do not set
104-
* {@link DataLoaderOptions#setBatchLoaderContextProvider(BatchLoaderContextProvider)}
104+
* {@link DataLoaderOptions.Builder#setBatchLoaderContextProvider(BatchLoaderContextProvider)}
105105
* as this will be set later to a provider that returns the context from
106106
* {@link ExecutionInput#getGraphQLContext()}, so that batch loading
107107
* functions and data fetchers can rely on access to the same context.
108-
* @param optionsConsumer callback to customize the options, invoked
109-
* immediately and given access to the options instance
108+
* @param optionsBuilderConsumer callback to customize the options, invoked
109+
* immediately and given access to the options builder instance
110110
* @return a spec to complete the registration
111+
* @since 1.4.0
111112
*/
112-
RegistrationSpec<K, V> withOptions(Consumer<DataLoaderOptions> optionsConsumer);
113+
RegistrationSpec<K, V> withOptions(Consumer<DataLoaderOptions.Builder> optionsBuilderConsumer);
113114

114115
/**
115116
* Set the {@link DataLoaderOptions} to use to create the

Diff for: spring-graphql/src/main/java/org/springframework/graphql/execution/DefaultBatchLoaderRegistry.java

+6-7
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ private class DefaultRegistrationSpec<K, V> implements RegistrationSpec<K, V> {
132132
private DataLoaderOptions options;
133133

134134
@Nullable
135-
private Consumer<DataLoaderOptions> optionsConsumer;
135+
private Consumer<DataLoaderOptions.Builder> optionsBuilderConsumer;
136136

137137
DefaultRegistrationSpec(Class<V> valueType) {
138138
this.valueType = valueType;
@@ -150,9 +150,9 @@ public RegistrationSpec<K, V> withName(String name) {
150150
}
151151

152152
@Override
153-
public RegistrationSpec<K, V> withOptions(Consumer<DataLoaderOptions> optionsConsumer) {
154-
this.optionsConsumer = (this.optionsConsumer != null) ?
155-
this.optionsConsumer.andThen(optionsConsumer) : optionsConsumer;
153+
public RegistrationSpec<K, V> withOptions(Consumer<DataLoaderOptions.Builder> optionsBuilderConsumer) {
154+
this.optionsBuilderConsumer = (this.optionsBuilderConsumer != null) ?
155+
this.optionsBuilderConsumer.andThen(optionsBuilderConsumer) : optionsBuilderConsumer;
156156
return this;
157157
}
158158

@@ -188,14 +188,13 @@ private Supplier<DataLoaderOptions> initOptionsSupplier() {
188188
new DataLoaderOptions((this.options != null) ?
189189
this.options : DefaultBatchLoaderRegistry.this.defaultOptionsSupplier.get());
190190

191-
if (this.optionsConsumer == null) {
191+
if (this.optionsBuilderConsumer == null) {
192192
return optionsSupplier;
193193
}
194194

195195
return () -> {
196196
DataLoaderOptions options = optionsSupplier.get();
197-
this.optionsConsumer.accept(options);
198-
return options;
197+
return options.transform(this.optionsBuilderConsumer);
199198
};
200199
}
201200
}

Diff for: spring-graphql/src/test/java/org/springframework/graphql/client/GraphQlClientTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -187,6 +187,7 @@ private void testExecuteFailedResponse(String document) {
187187
}
188188

189189
@Test
190+
@SuppressWarnings("cast")
190191
void executePartialResponse() {
191192

192193
String document = "fieldErrorResponse";

0 commit comments

Comments
 (0)