Skip to content

Commit 28fa810

Browse files
hiddewiefedericorispo
authored andcommitted
remove all DataLoaderDispatcherInstrumentation related classes and refactor instrumentation
1 parent ef6e3d8 commit 28fa810

File tree

8 files changed

+26
-363
lines changed

8 files changed

+26
-363
lines changed
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,20 @@
11
package graphql.kickstart.execution;
22

3-
import graphql.ExecutionInput;
43
import graphql.GraphQL;
5-
import graphql.execution.instrumentation.Instrumentation;
6-
import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentationOptions;
74
import graphql.kickstart.execution.config.GraphQLBuilder;
85
import graphql.kickstart.execution.input.GraphQLBatchedInvocationInput;
96
import graphql.kickstart.execution.input.GraphQLSingleInvocationInput;
10-
import java.util.List;
11-
import java.util.function.Supplier;
127

138
public class BatchedDataLoaderGraphQLBuilder {
149

15-
private final Supplier<DataLoaderDispatcherInstrumentationOptions> optionsSupplier;
16-
17-
public BatchedDataLoaderGraphQLBuilder(
18-
Supplier<DataLoaderDispatcherInstrumentationOptions> optionsSupplier) {
19-
if (optionsSupplier != null) {
20-
this.optionsSupplier = optionsSupplier;
21-
} else {
22-
this.optionsSupplier = DataLoaderDispatcherInstrumentationOptions::newOptions;
23-
}
24-
}
25-
2610
GraphQL newGraphQL(GraphQLBatchedInvocationInput invocationInput, GraphQLBuilder graphQLBuilder) {
27-
Supplier<Instrumentation> supplier =
28-
augment(invocationInput, graphQLBuilder.getInstrumentationSupplier());
2911
return invocationInput.getInvocationInputs().stream()
3012
.findFirst()
3113
.map(GraphQLSingleInvocationInput::getSchema)
32-
.map(schema -> graphQLBuilder.build(schema, supplier))
14+
.map(schema -> graphQLBuilder.build(schema, graphQLBuilder.getInstrumentationSupplier()))
3315
.orElseThrow(
3416
() ->
3517
new IllegalArgumentException(
3618
"Batched invocation input must contain at least one query"));
3719
}
38-
39-
private Supplier<Instrumentation> augment(
40-
GraphQLBatchedInvocationInput batchedInvocationInput,
41-
Supplier<Instrumentation> instrumentationSupplier) {
42-
List<ExecutionInput> executionInputs = batchedInvocationInput.getExecutionInputs();
43-
return batchedInvocationInput
44-
.getContextSetting()
45-
.configureInstrumentationForContext(
46-
instrumentationSupplier, executionInputs, optionsSupplier.get());
47-
}
4820
}

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

+3-22
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
import graphql.execution.instrumentation.ChainedInstrumentation;
44
import graphql.execution.instrumentation.Instrumentation;
55
import graphql.execution.instrumentation.SimplePerformantInstrumentation;
6-
import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentationOptions;
76
import graphql.execution.preparsed.NoOpPreparsedDocumentProvider;
87
import graphql.execution.preparsed.PreparsedDocumentProvider;
98
import graphql.kickstart.execution.config.DefaultExecutionStrategyProvider;
@@ -20,17 +19,14 @@ public class GraphQLQueryInvoker {
2019
private final Supplier<ExecutionStrategyProvider> getExecutionStrategyProvider;
2120
private final Supplier<Instrumentation> getInstrumentation;
2221
private final Supplier<PreparsedDocumentProvider> getPreparsedDocumentProvider;
23-
private final Supplier<DataLoaderDispatcherInstrumentationOptions> optionsSupplier;
2422

2523
protected GraphQLQueryInvoker(
2624
Supplier<ExecutionStrategyProvider> getExecutionStrategyProvider,
2725
Supplier<Instrumentation> getInstrumentation,
28-
Supplier<PreparsedDocumentProvider> getPreparsedDocumentProvider,
29-
Supplier<DataLoaderDispatcherInstrumentationOptions> optionsSupplier) {
26+
Supplier<PreparsedDocumentProvider> getPreparsedDocumentProvider) {
3027
this.getExecutionStrategyProvider = getExecutionStrategyProvider;
3128
this.getInstrumentation = getInstrumentation;
3229
this.getPreparsedDocumentProvider = getPreparsedDocumentProvider;
33-
this.optionsSupplier = optionsSupplier;
3430
}
3531

3632
public static Builder newBuilder() {
@@ -43,7 +39,7 @@ public GraphQLInvoker toGraphQLInvoker() {
4339
.executionStrategyProvider(getExecutionStrategyProvider)
4440
.instrumentation(getInstrumentation)
4541
.preparsedDocumentProvider(getPreparsedDocumentProvider);
46-
return new GraphQLInvoker(graphQLBuilder, new BatchedDataLoaderGraphQLBuilder(optionsSupplier));
42+
return new GraphQLInvoker(graphQLBuilder, new BatchedDataLoaderGraphQLBuilder());
4743
}
4844

4945
public static class Builder {
@@ -54,9 +50,6 @@ public static class Builder {
5450
() -> SimplePerformantInstrumentation.INSTANCE;
5551
private Supplier<PreparsedDocumentProvider> getPreparsedDocumentProvider =
5652
() -> NoOpPreparsedDocumentProvider.INSTANCE;
57-
private Supplier<DataLoaderDispatcherInstrumentationOptions>
58-
dataLoaderDispatcherInstrumentationOptionsSupplier =
59-
DataLoaderDispatcherInstrumentationOptions::newOptions;
6053

6154
public Builder withExecutionStrategyProvider(ExecutionStrategyProvider provider) {
6255
return withExecutionStrategyProvider(() -> provider);
@@ -97,23 +90,11 @@ public Builder withPreparsedDocumentProvider(Supplier<PreparsedDocumentProvider>
9790
return this;
9891
}
9992

100-
public Builder withDataLoaderDispatcherInstrumentationOptions(
101-
DataLoaderDispatcherInstrumentationOptions options) {
102-
return withDataLoaderDispatcherInstrumentationOptions(() -> options);
103-
}
104-
105-
public Builder withDataLoaderDispatcherInstrumentationOptions(
106-
Supplier<DataLoaderDispatcherInstrumentationOptions> supplier) {
107-
this.dataLoaderDispatcherInstrumentationOptionsSupplier = supplier;
108-
return this;
109-
}
110-
11193
public GraphQLQueryInvoker build() {
11294
return new GraphQLQueryInvoker(
11395
getExecutionStrategyProvider,
11496
getInstrumentation,
115-
getPreparsedDocumentProvider,
116-
dataLoaderDispatcherInstrumentationOptionsSupplier);
97+
getPreparsedDocumentProvider);
11798
}
11899
}
119100
}

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

-13
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,8 @@
22

33
import graphql.GraphQL;
44
import graphql.execution.ExecutionStrategy;
5-
import graphql.execution.instrumentation.ChainedInstrumentation;
65
import graphql.execution.instrumentation.Instrumentation;
76
import graphql.execution.instrumentation.SimplePerformantInstrumentation;
8-
import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentation;
97
import graphql.execution.preparsed.NoOpPreparsedDocumentProvider;
108
import graphql.execution.preparsed.PreparsedDocumentProvider;
119
import graphql.schema.GraphQLSchema;
@@ -89,18 +87,7 @@ public GraphQL build(
8987

9088
Instrumentation instrumentation = configuredInstrumentationSupplier.get();
9189
builder.instrumentation(instrumentation);
92-
if (containsDispatchInstrumentation(instrumentation)) {
93-
builder.doNotAutomaticallyDispatchDataLoader();
94-
}
9590
graphQLBuilderConfigurerSupplier.get().configure(builder);
9691
return builder.build();
9792
}
98-
99-
private boolean containsDispatchInstrumentation(Instrumentation instrumentation) {
100-
if (instrumentation instanceof ChainedInstrumentation) {
101-
return ((ChainedInstrumentation) instrumentation)
102-
.getInstrumentations().stream().anyMatch(this::containsDispatchInstrumentation);
103-
}
104-
return instrumentation instanceof DataLoaderDispatcherInstrumentation;
105-
}
10693
}

graphql-java-kickstart/src/main/java/graphql/kickstart/execution/context/ContextSetting.java

+7-46
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,10 @@
44
import graphql.execution.ExecutionId;
55
import graphql.execution.instrumentation.ChainedInstrumentation;
66
import graphql.execution.instrumentation.Instrumentation;
7-
import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentationOptions;
87
import graphql.kickstart.execution.GraphQLRequest;
98
import graphql.kickstart.execution.input.GraphQLBatchedInvocationInput;
109
import graphql.kickstart.execution.input.PerQueryBatchedInvocationInput;
1110
import graphql.kickstart.execution.input.PerRequestBatchedInvocationInput;
12-
import graphql.kickstart.execution.instrumentation.ConfigurableDispatchInstrumentation;
1311
import graphql.kickstart.execution.instrumentation.FieldLevelTrackingApproach;
1412
import graphql.kickstart.execution.instrumentation.RequestLevelTrackingApproach;
1513
import graphql.schema.GraphQLSchema;
@@ -28,11 +26,9 @@ public enum ContextSetting {
2826
* A context object, and therefor dataloader registry and subject, should be shared between all
2927
* GraphQL executions in a http request.
3028
*/
31-
PER_REQUEST_WITH_INSTRUMENTATION,
32-
PER_REQUEST_WITHOUT_INSTRUMENTATION,
29+
PER_REQUEST,
3330
/** Each GraphQL execution should always have its own context. */
34-
PER_QUERY_WITH_INSTRUMENTATION,
35-
PER_QUERY_WITHOUT_INSTRUMENTATION;
31+
PER_QUERY;
3632

3733
/**
3834
* Creates a set of inputs with the correct context based on the setting.
@@ -50,13 +46,9 @@ public GraphQLBatchedInvocationInput getBatch(
5046
Supplier<GraphQLKickstartContext> contextSupplier,
5147
Object root) {
5248
switch (this) {
53-
case PER_QUERY_WITH_INSTRUMENTATION:
54-
// Intentional fallthrough
55-
case PER_QUERY_WITHOUT_INSTRUMENTATION:
49+
case PER_QUERY:
5650
return new PerQueryBatchedInvocationInput(requests, schema, contextSupplier, root, this);
57-
case PER_REQUEST_WITHOUT_INSTRUMENTATION:
58-
// Intentional fallthrough
59-
case PER_REQUEST_WITH_INSTRUMENTATION:
51+
case PER_REQUEST:
6052
return new PerRequestBatchedInvocationInput(requests, schema, contextSupplier, root, this);
6153
default:
6254
throw new ContextSettingNotConfiguredException();
@@ -69,43 +61,12 @@ public GraphQLBatchedInvocationInput getBatch(
6961
*
7062
* @param instrumentation the instrumentation supplier to augment
7163
* @param executionInputs the inputs that will be dispatched by the instrumentation
72-
* @param options the DataLoader dispatching instrumentation options that will be used.
64+
// * @param options the DataLoader dispatching instrumentation options that will be used.
7365
* @return augmented instrumentation supplier.
7466
*/
7567
public Supplier<Instrumentation> configureInstrumentationForContext(
7668
Supplier<Instrumentation> instrumentation,
77-
List<ExecutionInput> executionInputs,
78-
DataLoaderDispatcherInstrumentationOptions options) {
79-
ConfigurableDispatchInstrumentation dispatchInstrumentation;
80-
switch (this) {
81-
case PER_REQUEST_WITH_INSTRUMENTATION:
82-
DataLoaderRegistry registry =
83-
executionInputs.stream()
84-
.findFirst()
85-
.map(ExecutionInput::getDataLoaderRegistry)
86-
.orElseThrow(IllegalArgumentException::new);
87-
List<ExecutionId> executionIds =
88-
executionInputs.stream()
89-
.map(ExecutionInput::getExecutionId)
90-
.collect(Collectors.toList());
91-
RequestLevelTrackingApproach requestTrackingApproach =
92-
new RequestLevelTrackingApproach(executionIds, registry);
93-
dispatchInstrumentation =
94-
new ConfigurableDispatchInstrumentation(
95-
options, (dataLoaderRegistry -> requestTrackingApproach));
96-
break;
97-
case PER_QUERY_WITH_INSTRUMENTATION:
98-
dispatchInstrumentation =
99-
new ConfigurableDispatchInstrumentation(options, FieldLevelTrackingApproach::new);
100-
break;
101-
case PER_REQUEST_WITHOUT_INSTRUMENTATION:
102-
// Intentional fallthrough
103-
case PER_QUERY_WITHOUT_INSTRUMENTATION:
104-
return instrumentation;
105-
default:
106-
throw new ContextSettingNotConfiguredException();
107-
}
108-
return () ->
109-
new ChainedInstrumentation(Arrays.asList(dispatchInstrumentation, instrumentation.get()));
69+
List<ExecutionInput> executionInputs) {
70+
return instrumentation;
11071
}
11172
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ public ExecutionStrategyInstrumentationContext beginExecutionStrategy(
4545

4646
return new ExecutionStrategyInstrumentationContext() {
4747
@Override
48-
public void onDispatched(CompletableFuture<ExecutionResult> result) {
48+
public void onDispatched() {
4949
// default empty implementation
5050
}
5151

@@ -110,7 +110,7 @@ public InstrumentationContext<Object> beginFieldFetch(
110110
return new InstrumentationContext<Object>() {
111111

112112
@Override
113-
public void onDispatched(CompletableFuture result) {
113+
public void onDispatched() {
114114
synchronized (stack) {
115115
stack.increaseFetchCount(executionId, level);
116116
stack.setStatus(executionId, dispatchIfNeeded(stack, executionId, level));

0 commit comments

Comments
 (0)