Skip to content

Commit 77526ec

Browse files
authored
Merge pull request #113 from graphql-java-kickstart/feature/98-dataloader-options
Added supplier for DataLoaderDispatcherInstrumentationOptions (fix #98)
2 parents 3374490 + 6de24db commit 77526ec

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

src/main/java/graphql/servlet/GraphQLQueryInvoker.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import graphql.execution.instrumentation.Instrumentation;
88
import graphql.execution.instrumentation.SimpleInstrumentation;
99
import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentation;
10+
import graphql.execution.instrumentation.dataloader.DataLoaderDispatcherInstrumentationOptions;
1011
import graphql.execution.preparsed.NoOpPreparsedDocumentProvider;
1112
import graphql.execution.preparsed.PreparsedDocumentProvider;
1213
import graphql.schema.GraphQLSchema;
@@ -28,11 +29,13 @@ public class GraphQLQueryInvoker {
2829
private final Supplier<ExecutionStrategyProvider> getExecutionStrategyProvider;
2930
private final Supplier<Instrumentation> getInstrumentation;
3031
private final Supplier<PreparsedDocumentProvider> getPreparsedDocumentProvider;
32+
private final Supplier<DataLoaderDispatcherInstrumentationOptions> dataLoaderDispatcherInstrumentationOptionsSupplier;
3133

32-
protected GraphQLQueryInvoker(Supplier<ExecutionStrategyProvider> getExecutionStrategyProvider, Supplier<Instrumentation> getInstrumentation, Supplier<PreparsedDocumentProvider> getPreparsedDocumentProvider) {
34+
protected GraphQLQueryInvoker(Supplier<ExecutionStrategyProvider> getExecutionStrategyProvider, Supplier<Instrumentation> getInstrumentation, Supplier<PreparsedDocumentProvider> getPreparsedDocumentProvider, Supplier<DataLoaderDispatcherInstrumentationOptions> optionsSupplier) {
3335
this.getExecutionStrategyProvider = getExecutionStrategyProvider;
3436
this.getInstrumentation = getInstrumentation;
3537
this.getPreparsedDocumentProvider = getPreparsedDocumentProvider;
38+
this.dataLoaderDispatcherInstrumentationOptionsSupplier = optionsSupplier;
3639
}
3740

3841
public ExecutionResult query(GraphQLSingleInvocationInput singleInvocationInput) {
@@ -65,7 +68,7 @@ protected Instrumentation getInstrumentation(Object context) {
6568
.map(registry -> {
6669
List<Instrumentation> instrumentations = new ArrayList<>();
6770
instrumentations.add(getInstrumentation.get());
68-
instrumentations.add(new DataLoaderDispatcherInstrumentation(registry));
71+
instrumentations.add(new DataLoaderDispatcherInstrumentation(registry, dataLoaderDispatcherInstrumentationOptionsSupplier.get()));
6972
return new ChainedInstrumentation(instrumentations);
7073
})
7174
.map(Instrumentation.class::cast)
@@ -100,6 +103,7 @@ public static class Builder {
100103
private Supplier<ExecutionStrategyProvider> getExecutionStrategyProvider = DefaultExecutionStrategyProvider::new;
101104
private Supplier<Instrumentation> getInstrumentation = () -> SimpleInstrumentation.INSTANCE;
102105
private Supplier<PreparsedDocumentProvider> getPreparsedDocumentProvider = () -> NoOpPreparsedDocumentProvider.INSTANCE;
106+
private Supplier<DataLoaderDispatcherInstrumentationOptions> dataLoaderDispatcherInstrumentationOptionsSupplier = DataLoaderDispatcherInstrumentationOptions::newOptions;
103107

104108
public Builder withExecutionStrategyProvider(ExecutionStrategyProvider provider) {
105109
return withExecutionStrategyProvider(() -> provider);
@@ -128,8 +132,17 @@ public Builder withPreparsedDocumentProvider(Supplier<PreparsedDocumentProvider>
128132
return this;
129133
}
130134

135+
public Builder withDataLoaderDispatcherInstrumentationOptions(DataLoaderDispatcherInstrumentationOptions options) {
136+
return withDataLoaderDispatcherInstrumentationOptions(() -> options);
137+
}
138+
139+
public Builder withDataLoaderDispatcherInstrumentationOptions(Supplier<DataLoaderDispatcherInstrumentationOptions> supplier) {
140+
this.dataLoaderDispatcherInstrumentationOptionsSupplier = supplier;
141+
return this;
142+
}
143+
131144
public GraphQLQueryInvoker build() {
132-
return new GraphQLQueryInvoker(getExecutionStrategyProvider, getInstrumentation, getPreparsedDocumentProvider);
145+
return new GraphQLQueryInvoker(getExecutionStrategyProvider, getInstrumentation, getPreparsedDocumentProvider, dataLoaderDispatcherInstrumentationOptionsSupplier);
133146
}
134147
}
135148
}

0 commit comments

Comments
 (0)