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
This commit is contained in:
Brian Clozel
2025-04-07 10:48:58 +02:00
parent eb5a83ab6a
commit 462e73ede6
5 changed files with 16 additions and 15 deletions

View File

@@ -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"
}

View File

@@ -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'

View File

@@ -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 <a href="https://www.graphql-java.com/documentation/v16/batching/">Using DataLoader</a>
* @see <a href="https://www.graphql-java.com/documentation/batching/">Using DataLoader</a>
* @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}.
* <p><strong>Note:</strong> 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<K, V> withOptions(Consumer<DataLoaderOptions> optionsConsumer);
RegistrationSpec<K, V> withOptions(Consumer<DataLoaderOptions.Builder> optionsBuilderConsumer);
/**
* Set the {@link DataLoaderOptions} to use to create the

View File

@@ -132,7 +132,7 @@ public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry {
private DataLoaderOptions options;
@Nullable
private Consumer<DataLoaderOptions> optionsConsumer;
private Consumer<DataLoaderOptions.Builder> optionsBuilderConsumer;
DefaultRegistrationSpec(Class<V> valueType) {
this.valueType = valueType;
@@ -150,9 +150,9 @@ public class DefaultBatchLoaderRegistry implements BatchLoaderRegistry {
}
@Override
public RegistrationSpec<K, V> withOptions(Consumer<DataLoaderOptions> optionsConsumer) {
this.optionsConsumer = (this.optionsConsumer != null) ?
this.optionsConsumer.andThen(optionsConsumer) : optionsConsumer;
public RegistrationSpec<K, V> withOptions(Consumer<DataLoaderOptions.Builder> 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);
};
}
}

View File

@@ -187,6 +187,7 @@ public class GraphQlClientTests extends GraphQlClientTestSupport {
}
@Test
@SuppressWarnings("cast")
void executePartialResponse() {
String document = "fieldErrorResponse";