Skip to content

Commit 5ce8fd8

Browse files
federicorispooliemansm
authored andcommitted
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 (cherry picked from commit 76fb7bd)
1 parent 5e8d15b commit 5ce8fd8

File tree

7 files changed

+42
-46
lines changed

7 files changed

+42
-46
lines changed

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,12 @@ public static class Builder {
5050

5151
private Supplier<ExecutionStrategyProvider> getExecutionStrategyProvider =
5252
DefaultExecutionStrategyProvider::new;
53-
private Supplier<Instrumentation> getInstrumentation =
54-
() -> SimplePerformantInstrumentation.INSTANCE;
53+
private Supplier<Instrumentation> getInstrumentation = () -> SimplePerformantInstrumentation.INSTANCE;
5554
private Supplier<PreparsedDocumentProvider> getPreparsedDocumentProvider =
5655
() -> NoOpPreparsedDocumentProvider.INSTANCE;
5756
private Supplier<DataLoaderDispatcherInstrumentationOptions>
5857
dataLoaderDispatcherInstrumentationOptionsSupplier =
59-
DataLoaderDispatcherInstrumentationOptions::newOptions;
58+
DataLoaderDispatcherInstrumentationOptions::newOptions;
6059

6160
public Builder withExecutionStrategyProvider(ExecutionStrategyProvider provider) {
6261
return withExecutionStrategyProvider(() -> provider);

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

+1-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,7 @@ public class GraphQLBuilder {
2020
() -> NoOpPreparsedDocumentProvider.INSTANCE;
2121

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

2625
private Supplier<GraphQLBuilderConfigurer> graphQLBuilderConfigurerSupplier = () -> builder -> {};
2726

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

+28-30
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,29 +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,
68-
InstrumentationFieldFetchParameters parameters,
69-
InstrumentationState instrumentationState) {
70-
DataLoaderDispatcherInstrumentationState state =
71-
InstrumentationState.ofState(instrumentationState);
68+
public DataFetcher<?> instrumentDataFetcher(DataFetcher<?> dataFetcher,
69+
InstrumentationFieldFetchParameters parameters, InstrumentationState instrumentationState) {
70+
DataLoaderDispatcherInstrumentationState state = InstrumentationState.ofState(
71+
instrumentationState);
7272
if (state.isAggressivelyBatching()) {
7373
return dataFetcher;
7474
}
7575
//
7676
// currently only AsyncExecutionStrategy with DataLoader and hence this allows us to "dispatch"
7777
// on every object if it's not using aggressive batching for other execution strategies
7878
// which allows them to work if used.
79-
return (DataFetcher<Object>)
80-
environment -> {
81-
Object obj = dataFetcher.get(environment);
82-
doImmediatelyDispatch(state);
83-
return obj;
84-
};
79+
return (DataFetcher<Object>) environment -> {
80+
Object obj = dataFetcher.get(environment);
81+
doImmediatelyDispatch(state);
82+
return obj;
83+
};
8584
}
8685

8786
private void doImmediatelyDispatch(DataLoaderDispatcherInstrumentationState state) {
@@ -93,8 +92,8 @@ public InstrumentationContext<ExecutionResult> beginExecuteOperation(
9392
InstrumentationExecuteOperationParameters parameters,
9493
InstrumentationState instrumentationState) {
9594
if (!isDataLoaderCompatible(parameters.getExecutionContext())) {
96-
DataLoaderDispatcherInstrumentationState state =
97-
InstrumentationState.ofState(instrumentationState);
95+
DataLoaderDispatcherInstrumentationState state = InstrumentationState.ofState(
96+
instrumentationState);
9897
state.setAggressivelyBatching(false);
9998
}
10099
return SimpleInstrumentationContext.noOp();
@@ -118,8 +117,8 @@ private boolean isDataLoaderCompatible(ExecutionContext executionContext) {
118117
public ExecutionStrategyInstrumentationContext beginExecutionStrategy(
119118
InstrumentationExecutionStrategyParameters parameters,
120119
InstrumentationState instrumentationState) {
121-
DataLoaderDispatcherInstrumentationState state =
122-
InstrumentationState.ofState(instrumentationState);
120+
DataLoaderDispatcherInstrumentationState state = InstrumentationState.ofState(
121+
instrumentationState);
123122
//
124123
// if there are no data loaders, there is nothing to do
125124
//
@@ -142,8 +141,8 @@ public void onCompleted(ExecutionResult result, Throwable t) {
142141
@Override
143142
public InstrumentationContext<Object> beginFieldFetch(
144143
InstrumentationFieldFetchParameters parameters, InstrumentationState instrumentationState) {
145-
DataLoaderDispatcherInstrumentationState state =
146-
InstrumentationState.ofState(instrumentationState);
144+
DataLoaderDispatcherInstrumentationState state = InstrumentationState.ofState(
145+
instrumentationState);
147146
//
148147
// if there are no data loaders, there is nothing to do
149148
//
@@ -155,26 +154,25 @@ public InstrumentationContext<Object> beginFieldFetch(
155154

156155
@Override
157156
public CompletableFuture<ExecutionResult> instrumentExecutionResult(
158-
ExecutionResult executionResult,
159-
InstrumentationExecutionParameters parameters,
157+
ExecutionResult executionResult, InstrumentationExecutionParameters parameters,
160158
InstrumentationState instrumentationState) {
161-
DataLoaderDispatcherInstrumentationState state =
162-
InstrumentationState.ofState(instrumentationState);
159+
DataLoaderDispatcherInstrumentationState state = InstrumentationState.ofState(
160+
instrumentationState);
163161
state.getApproach().removeTracking(parameters.getExecutionInput().getExecutionId());
164162
if (!options.isIncludeStatistics()) {
165163
return CompletableFuture.completedFuture(executionResult);
166164
} else {
167165
Map<Object, Object> currentExt = executionResult.getExtensions();
168-
Map<Object, Object> statsMap =
169-
new LinkedHashMap<>(currentExt == null ? Collections.emptyMap() : currentExt);
166+
Map<Object, Object> statsMap = new LinkedHashMap<>(
167+
currentExt == null ? Collections.emptyMap() : currentExt);
170168
Map<Object, Object> dataLoaderStats = buildStatisticsMap(state);
171169
statsMap.put("dataloader", dataLoaderStats);
172170

173171
log.debug("Data loader stats : {}", dataLoaderStats);
174172

175173
return CompletableFuture.completedFuture(
176-
new ExecutionResultImpl(
177-
executionResult.getData(), executionResult.getErrors(), statsMap));
174+
new ExecutionResultImpl(executionResult.getData(), executionResult.getErrors(),
175+
statsMap));
178176
}
179177
}
180178

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
@@ -28,7 +28,7 @@ dependencies {
2828
compileOnly 'org.osgi:org.osgi.service.metatype.annotations:1.4.1'
2929
compileOnly 'org.osgi:org.osgi.annotation:6.0.0'
3030

31-
testImplementation 'io.github.graphql-java:graphql-java-annotations:8.3'
31+
testImplementation 'io.github.graphql-java:graphql-java-annotations:9.1'
3232

3333
// Unit testing
3434
testImplementation "org.codehaus.groovy:groovy-all:3.0.12"

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)