Skip to content

Commit fb0656a

Browse files
committed
fix(deps): update graphql-java to v20.0.0
To update graphql-java to version 20.0.0 some changes are necessary: - the signature of DataLoaderDispatcherInstrumentation methods now have the InstrumentationState parameter. The ConfigurableDispatchInstrumentation is aligned to these changes - The SimpleInstrumentation is replaced by SimplePerformantInstrumentation. Now all the codebase uses the new class
1 parent 09747cf commit fb0656a

File tree

8 files changed

+57
-46
lines changed

8 files changed

+57
-46
lines changed

gradle.properties

+1-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ PROJECT_LICENSE=MIT
77
PROJECT_LICENSE_URL=https://github.com/graphql-java-kickstart/spring-java-servlet/blob/master/LICENSE.md
88
PROJECT_DEV_ID=oliemansm
99
PROJECT_DEV_NAME=Michiel Oliemans
10-
LIB_GRAPHQL_JAVA_VER=19.3
10+
LIB_GRAPHQL_JAVA_VER=20.0
1111
LIB_JACKSON_VER=2.14.2
1212
LIB_SLF4J_VER=2.0.6
1313
LIB_LOMBOK_VER=1.18.26

graphql-java-kickstart/src/main/java/graphql/kickstart/execution/GraphQLQueryInvoker.java

+6-4
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import graphql.execution.instrumentation.ChainedInstrumentation;
44
import graphql.execution.instrumentation.Instrumentation;
5-
import graphql.execution.instrumentation.SimpleInstrumentation;
5+
import graphql.execution.instrumentation.SimplePerformantInstrumentation;
66
import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentationOptions;
77
import graphql.execution.preparsed.NoOpPreparsedDocumentProvider;
88
import graphql.execution.preparsed.PreparsedDocumentProvider;
@@ -12,7 +12,9 @@
1212
import java.util.List;
1313
import java.util.function.Supplier;
1414

15-
/** @author Andrew Potter */
15+
/**
16+
* @author Andrew Potter
17+
*/
1618
public class GraphQLQueryInvoker {
1719

1820
private final Supplier<ExecutionStrategyProvider> getExecutionStrategyProvider;
@@ -48,12 +50,12 @@ public static class Builder {
4850

4951
private Supplier<ExecutionStrategyProvider> getExecutionStrategyProvider =
5052
DefaultExecutionStrategyProvider::new;
51-
private Supplier<Instrumentation> getInstrumentation = () -> SimpleInstrumentation.INSTANCE;
53+
private Supplier<Instrumentation> getInstrumentation = () -> SimplePerformantInstrumentation.INSTANCE;
5254
private Supplier<PreparsedDocumentProvider> getPreparsedDocumentProvider =
5355
() -> NoOpPreparsedDocumentProvider.INSTANCE;
5456
private Supplier<DataLoaderDispatcherInstrumentationOptions>
5557
dataLoaderDispatcherInstrumentationOptionsSupplier =
56-
DataLoaderDispatcherInstrumentationOptions::newOptions;
58+
DataLoaderDispatcherInstrumentationOptions::newOptions;
5759

5860
public Builder withExecutionStrategyProvider(ExecutionStrategyProvider provider) {
5961
return withExecutionStrategyProvider(() -> provider);

graphql-java-kickstart/src/main/java/graphql/kickstart/execution/config/GraphQLBuilder.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
import graphql.execution.ExecutionStrategy;
55
import graphql.execution.instrumentation.ChainedInstrumentation;
66
import graphql.execution.instrumentation.Instrumentation;
7-
import graphql.execution.instrumentation.SimpleInstrumentation;
7+
import graphql.execution.instrumentation.SimplePerformantInstrumentation;
88
import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentation;
99
import graphql.execution.preparsed.NoOpPreparsedDocumentProvider;
1010
import graphql.execution.preparsed.PreparsedDocumentProvider;
@@ -20,7 +20,7 @@ public class GraphQLBuilder {
2020
() -> NoOpPreparsedDocumentProvider.INSTANCE;
2121

2222
@Getter
23-
private Supplier<Instrumentation> instrumentationSupplier = () -> SimpleInstrumentation.INSTANCE;
23+
private Supplier<Instrumentation> instrumentationSupplier = () -> SimplePerformantInstrumentation.INSTANCE;
2424

2525
private Supplier<GraphQLBuilderConfigurer> graphQLBuilderConfigurerSupplier = () -> builder -> {};
2626

graphql-java-kickstart/src/main/java/graphql/kickstart/execution/instrumentation/ConfigurableDispatchInstrumentation.java

+37-28
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,9 @@ public class ConfigurableDispatchInstrumentation extends DataLoaderDispatcherIns
3535

3636
private final Function<DataLoaderRegistry, TrackingApproach> approachFunction;
3737

38-
/** Creates a DataLoaderDispatcherInstrumentation with the default options */
38+
/**
39+
* Creates a DataLoaderDispatcherInstrumentation with the default options
40+
*/
3941
public ConfigurableDispatchInstrumentation(
4042
Function<DataLoaderRegistry, TrackingApproach> approachFunction) {
4143
this(DataLoaderDispatcherInstrumentationOptions.newOptions(), approachFunction);
@@ -46,8 +48,7 @@ public ConfigurableDispatchInstrumentation(
4648
*
4749
* @param options the options to control the behaviour
4850
*/
49-
public ConfigurableDispatchInstrumentation(
50-
DataLoaderDispatcherInstrumentationOptions options,
51+
public ConfigurableDispatchInstrumentation(DataLoaderDispatcherInstrumentationOptions options,
5152
Function<DataLoaderRegistry, TrackingApproach> approachFunction) {
5253
this.options = options;
5354
this.approachFunction = approachFunction;
@@ -59,26 +60,27 @@ public InstrumentationState createState(InstrumentationCreateStateParameters par
5960
return new DataLoaderDispatcherInstrumentationState(
6061
registry,
6162
approachFunction.apply(registry),
62-
parameters.getExecutionInput().getExecutionId());
63+
parameters.getExecutionInput().getExecutionId()
64+
);
6365
}
6466

6567
@Override
66-
public DataFetcher<?> instrumentDataFetcher(
67-
DataFetcher<?> dataFetcher, InstrumentationFieldFetchParameters parameters) {
68-
DataLoaderDispatcherInstrumentationState state = parameters.getInstrumentationState();
68+
public DataFetcher<?> instrumentDataFetcher(DataFetcher<?> dataFetcher,
69+
InstrumentationFieldFetchParameters parameters, InstrumentationState instrumentationState) {
70+
DataLoaderDispatcherInstrumentationState state = InstrumentationState.ofState(
71+
instrumentationState);
6972
if (state.isAggressivelyBatching()) {
7073
return dataFetcher;
7174
}
7275
//
7376
// currently only AsyncExecutionStrategy with DataLoader and hence this allows us to "dispatch"
74-
// on every object if its not using aggressive batching for other execution strategies
77+
// on every object if it's not using aggressive batching for other execution strategies
7578
// which allows them to work if used.
76-
return (DataFetcher<Object>)
77-
environment -> {
78-
Object obj = dataFetcher.get(environment);
79-
doImmediatelyDispatch(state);
80-
return obj;
81-
};
79+
return (DataFetcher<Object>) environment -> {
80+
Object obj = dataFetcher.get(environment);
81+
doImmediatelyDispatch(state);
82+
return obj;
83+
};
8284
}
8385

8486
private void doImmediatelyDispatch(DataLoaderDispatcherInstrumentationState state) {
@@ -87,12 +89,14 @@ private void doImmediatelyDispatch(DataLoaderDispatcherInstrumentationState stat
8789

8890
@Override
8991
public InstrumentationContext<ExecutionResult> beginExecuteOperation(
90-
InstrumentationExecuteOperationParameters parameters) {
92+
InstrumentationExecuteOperationParameters parameters,
93+
InstrumentationState instrumentationState) {
9194
if (!isDataLoaderCompatible(parameters.getExecutionContext())) {
92-
DataLoaderDispatcherInstrumentationState state = parameters.getInstrumentationState();
95+
DataLoaderDispatcherInstrumentationState state = InstrumentationState.ofState(
96+
instrumentationState);
9397
state.setAggressivelyBatching(false);
9498
}
95-
return new SimpleInstrumentationContext<>();
99+
return SimpleInstrumentationContext.noOp();
96100
}
97101

98102
private boolean isDataLoaderCompatible(ExecutionContext executionContext) {
@@ -111,8 +115,10 @@ private boolean isDataLoaderCompatible(ExecutionContext executionContext) {
111115

112116
@Override
113117
public ExecutionStrategyInstrumentationContext beginExecutionStrategy(
114-
InstrumentationExecutionStrategyParameters parameters) {
115-
DataLoaderDispatcherInstrumentationState state = parameters.getInstrumentationState();
118+
InstrumentationExecutionStrategyParameters parameters,
119+
InstrumentationState instrumentationState) {
120+
DataLoaderDispatcherInstrumentationState state = InstrumentationState.ofState(
121+
instrumentationState);
116122
//
117123
// if there are no data loaders, there is nothing to do
118124
//
@@ -134,36 +140,39 @@ public void onCompleted(ExecutionResult result, Throwable t) {
134140

135141
@Override
136142
public InstrumentationContext<Object> beginFieldFetch(
137-
InstrumentationFieldFetchParameters parameters) {
138-
DataLoaderDispatcherInstrumentationState state = parameters.getInstrumentationState();
143+
InstrumentationFieldFetchParameters parameters, InstrumentationState instrumentationState) {
144+
DataLoaderDispatcherInstrumentationState state = InstrumentationState.ofState(
145+
instrumentationState);
139146
//
140147
// if there are no data loaders, there is nothing to do
141148
//
142149
if (state.hasNoDataLoaders()) {
143-
return new SimpleInstrumentationContext<>();
150+
return SimpleInstrumentationContext.noOp();
144151
}
145152
return state.getApproach().beginFieldFetch(parameters);
146153
}
147154

148155
@Override
149156
public CompletableFuture<ExecutionResult> instrumentExecutionResult(
150-
ExecutionResult executionResult, InstrumentationExecutionParameters parameters) {
151-
DataLoaderDispatcherInstrumentationState state = parameters.getInstrumentationState();
157+
ExecutionResult executionResult, InstrumentationExecutionParameters parameters,
158+
InstrumentationState instrumentationState) {
159+
DataLoaderDispatcherInstrumentationState state = InstrumentationState.ofState(
160+
instrumentationState);
152161
state.getApproach().removeTracking(parameters.getExecutionInput().getExecutionId());
153162
if (!options.isIncludeStatistics()) {
154163
return CompletableFuture.completedFuture(executionResult);
155164
} else {
156165
Map<Object, Object> currentExt = executionResult.getExtensions();
157-
Map<Object, Object> statsMap =
158-
new LinkedHashMap<>(currentExt == null ? Collections.emptyMap() : currentExt);
166+
Map<Object, Object> statsMap = new LinkedHashMap<>(
167+
currentExt == null ? Collections.emptyMap() : currentExt);
159168
Map<Object, Object> dataLoaderStats = buildStatisticsMap(state);
160169
statsMap.put("dataloader", dataLoaderStats);
161170

162171
log.debug("Data loader stats : {}", dataLoaderStats);
163172

164173
return CompletableFuture.completedFuture(
165-
new ExecutionResultImpl(
166-
executionResult.getData(), executionResult.getErrors(), statsMap));
174+
new ExecutionResultImpl(executionResult.getData(), executionResult.getErrors(),
175+
statsMap));
167176
}
168177
}
169178

Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
package graphql.kickstart.execution.instrumentation;
22

33
import graphql.execution.instrumentation.Instrumentation;
4-
import graphql.execution.instrumentation.SimpleInstrumentation;
4+
import graphql.execution.instrumentation.SimplePerformantInstrumentation;
55
import graphql.kickstart.execution.config.InstrumentationProvider;
66

77
public class NoOpInstrumentationProvider implements InstrumentationProvider {
88

99
@Override
1010
public Instrumentation getInstrumentation() {
11-
return SimpleInstrumentation.INSTANCE;
11+
return SimplePerformantInstrumentation.INSTANCE;
1212
}
1313
}

graphql-java-servlet/build.gradle

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ dependencies {
2929
compileOnly 'org.osgi:org.osgi.service.metatype.annotations:1.4.1'
3030
compileOnly 'org.osgi:org.osgi.annotation:6.0.0'
3131

32-
testImplementation 'io.github.graphql-java:graphql-java-annotations:8.3'
32+
testImplementation 'io.github.graphql-java:graphql-java-annotations:9.1'
3333

3434
// Unit testing
3535
testImplementation "org.apache.groovy:groovy-all:4.0.9"

graphql-java-servlet/src/test/groovy/graphql/kickstart/servlet/DataLoaderDispatchingSpec.groovy

+6-6
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import com.fasterxml.jackson.databind.ObjectMapper
44
import graphql.ExecutionInput
55
import graphql.execution.instrumentation.ChainedInstrumentation
66
import graphql.execution.instrumentation.Instrumentation
7-
import graphql.execution.instrumentation.SimpleInstrumentation
7+
import graphql.execution.instrumentation.SimplePerformantInstrumentation
88
import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentationOptions
99
import graphql.kickstart.execution.context.ContextSetting
1010
import graphql.kickstart.execution.context.DefaultGraphQLContext
@@ -14,7 +14,7 @@ import graphql.kickstart.servlet.context.GraphQLServletContextBuilder
1414
import graphql.schema.DataFetcher
1515
import graphql.schema.DataFetchingEnvironment
1616
import org.dataloader.BatchLoader
17-
import org.dataloader.DataLoader
17+
import org.dataloader.DataLoaderFactory
1818
import org.dataloader.DataLoaderRegistry
1919
import org.springframework.mock.web.MockHttpServletRequest
2020
import org.springframework.mock.web.MockHttpServletResponse
@@ -59,9 +59,9 @@ class DataLoaderDispatchingSpec extends Specification {
5959

6060
def registry() {
6161
DataLoaderRegistry registry = new DataLoaderRegistry()
62-
registry.register("A", DataLoader.newDataLoader(batchLoaderWithCounter(fetchCounterA)))
63-
registry.register("B", DataLoader.newDataLoader(batchLoaderWithCounter(fetchCounterB)))
64-
registry.register("C", DataLoader.newDataLoader(batchLoaderWithCounter(fetchCounterC)))
62+
registry.register("A", DataLoaderFactory.newDataLoader(batchLoaderWithCounter(fetchCounterA)))
63+
registry.register("B", DataLoaderFactory.newDataLoader(batchLoaderWithCounter(fetchCounterB)))
64+
registry.register("C", DataLoaderFactory.newDataLoader(batchLoaderWithCounter(fetchCounterC)))
6565
registry
6666
}
6767

@@ -120,7 +120,7 @@ class DataLoaderDispatchingSpec extends Specification {
120120
mapper.readValue(response.getContentAsByteArray(), List)
121121
}
122122

123-
Instrumentation simpleInstrumentation = new SimpleInstrumentation()
123+
Instrumentation simpleInstrumentation = new SimplePerformantInstrumentation()
124124
ChainedInstrumentation chainedInstrumentation = new ChainedInstrumentation(Collections.singletonList(simpleInstrumentation))
125125
def simpleSupplier = { simpleInstrumentation }
126126
def chainedSupplier = { chainedInstrumentation }

graphql-java-servlet/src/test/groovy/graphql/kickstart/servlet/OsgiGraphQLHttpServletSpec.groovy

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import graphql.annotations.annotationTypes.GraphQLField
55
import graphql.annotations.annotationTypes.GraphQLName
66
import graphql.annotations.processor.GraphQLAnnotations
77
import graphql.execution.instrumentation.InstrumentationState
8-
import graphql.execution.instrumentation.SimpleInstrumentation
8+
import graphql.execution.instrumentation.SimplePerformantInstrumentation
99
import graphql.execution.instrumentation.parameters.InstrumentationCreateStateParameters
1010
import graphql.kickstart.execution.GraphQLRequest
1111
import graphql.kickstart.execution.config.ExecutionStrategyProvider
@@ -349,7 +349,7 @@ class OsgiGraphQLHttpServletSpec extends Specification {
349349
def "instrumentation provider is bound and unbound"() {
350350
setup:
351351
def servlet = new OsgiGraphQLHttpServlet()
352-
def instrumentation = new SimpleInstrumentation()
352+
def instrumentation = new SimplePerformantInstrumentation()
353353
def instrumentationProvider = Mock(InstrumentationProvider)
354354
instrumentationProvider.getInstrumentation() >> instrumentation
355355
def request = GraphQLRequest.createIntrospectionRequest()

0 commit comments

Comments
 (0)