Skip to content

Commit 275eaac

Browse files
committed
wip
1 parent b7379ef commit 275eaac

File tree

5 files changed

+44
-15
lines changed

5 files changed

+44
-15
lines changed

src/main/java/graphql/GraphQL.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ public CompletableFuture<ExecutionResult> executeAsync(ExecutionInput executionI
424424
EngineRunningState engineRunningState = new EngineRunningState(executionInput, profiler);
425425
return engineRunningState.engineRun(() -> {
426426
ExecutionInput executionInputWithId = ensureInputHasId(executionInput);
427-
profiler.setExecutionId(executionInputWithId.getExecutionId());
427+
profiler.executionInput(executionInputWithId);
428428
engineRunningState.updateExecutionId(executionInputWithId.getExecutionId());
429429

430430
CompletableFuture<InstrumentationState> instrumentationStateCF = instrumentation.createStateAsync(new InstrumentationCreateStateParameters(this.graphQLSchema, executionInputWithId));

src/main/java/graphql/Profiler.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package graphql;
22

33
import graphql.execution.EngineRunningObserver;
4-
import graphql.execution.ExecutionId;
54
import graphql.execution.ResultPath;
65
import graphql.language.OperationDefinition;
76
import graphql.schema.DataFetcher;
@@ -25,7 +24,7 @@ default void subSelectionCount(int size) {
2524

2625
}
2726

28-
default void setExecutionId(ExecutionId executionId) {
27+
default void executionInput(ExecutionInput executionInput) {
2928

3029
}
3130

src/main/java/graphql/ProfilerImpl.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import graphql.execution.EngineRunningObserver;
44
import graphql.execution.ExecutionId;
55
import graphql.execution.ResultPath;
6+
import graphql.execution.instrumentation.dataloader.DataLoaderDispatchingContextKeys;
67
import graphql.language.OperationDefinition;
78
import graphql.schema.DataFetcher;
89
import graphql.schema.PropertyDataFetcher;
@@ -29,8 +30,10 @@ public ProfilerImpl(GraphQLContext graphQLContext) {
2930
}
3031

3132
@Override
32-
public void setExecutionId(ExecutionId executionId) {
33-
profilerResult.setExecutionId(executionId);
33+
public void executionInput(ExecutionInput executionInput) {
34+
profilerResult.setExecutionId(executionInput.getExecutionId());
35+
boolean dataLoaderChainingEnabled = executionInput.getGraphQLContext().getBoolean(DataLoaderDispatchingContextKeys.ENABLE_DATA_LOADER_CHAINING, false);
36+
profilerResult.setDataLoaderChainingEnabled(dataLoaderChainingEnabled);
3437
}
3538

3639
@Override
@@ -55,7 +58,7 @@ public void fieldFetched(Object fetchedObject, DataFetcher<?> dataFetcher, Resul
5558
} else {
5659
dataFetcherResultType = ProfilerResult.DataFetcherResultType.MATERIALIZED;
5760
}
58-
profilerResult.setDataFetcherResultType(path.toString(), dataFetcherResultType);
61+
profilerResult.setDataFetcherResultType(key, dataFetcherResultType);
5962
}
6063

6164
profilerResult.setDataFetcherType(key, dataFetcherType);

src/main/java/graphql/ProfilerResult.java

Lines changed: 33 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,10 +26,11 @@ public class ProfilerResult {
2626
private final Map<String, Integer> dataFetcherInvocationCount = new ConcurrentHashMap<>();
2727
private final Map<String, DataFetcherType> dataFetcherTypeMap = new ConcurrentHashMap<>();
2828

29-
// the key is the whole result key, not just the query path
3029
private final Map<String, DataFetcherResultType> dataFetcherResultType = new ConcurrentHashMap<>();
3130
private volatile String operationName;
3231
private volatile String operationType;
32+
private volatile boolean dataLoaderChainingEnabled;
33+
3334

3435

3536
public enum DataFetcherType {
@@ -47,6 +48,11 @@ public enum DataFetcherResultType {
4748

4849
// setters are package private to prevent exposure
4950

51+
void setDataLoaderChainingEnabled(boolean dataLoaderChainingEnabled) {
52+
this.dataLoaderChainingEnabled = dataLoaderChainingEnabled;
53+
}
54+
55+
5056
void setDataFetcherType(String key, DataFetcherType dataFetcherType) {
5157
dataFetcherTypeMap.putIfAbsent(key, dataFetcherType);
5258
totalDataFetcherInvocations.incrementAndGet();
@@ -55,8 +61,8 @@ void setDataFetcherType(String key, DataFetcherType dataFetcherType) {
5561
}
5662
}
5763

58-
void setDataFetcherResultType(String resultPath, DataFetcherResultType fetchedType) {
59-
dataFetcherResultType.put(resultPath, fetchedType);
64+
void setDataFetcherResultType(String key, DataFetcherResultType fetchedType) {
65+
dataFetcherResultType.putIfAbsent(key, fetchedType);
6066
}
6167

6268
void incrementDataFetcherInvocationCount(String key) {
@@ -148,9 +154,7 @@ public Map<String, DataFetcherResultType> getDataFetcherResultType() {
148154
return dataFetcherResultType;
149155
}
150156

151-
152-
@Override
153-
public String toString() {
157+
public String fullSummary() {
154158
return "ProfilerResult{" +
155159
"executionId=" + executionId +
156160
", operation=" + operationType + ":" + operationName +
@@ -164,6 +168,29 @@ public String toString() {
164168
", dataFetcherInvocationCount=" + dataFetcherInvocationCount +
165169
", dataFetcherTypeMap=" + dataFetcherTypeMap +
166170
", dataFetcherResultType=" + dataFetcherResultType +
171+
", dataLoaderChainingEnabled=" + dataLoaderChainingEnabled +
167172
'}';
168173
}
174+
175+
public String shortSummary() {
176+
return "ProfilerResult{" +
177+
"executionId=" + executionId +
178+
", operation=" + operationType + ":" + operationName +
179+
", startTime=" + startTime +
180+
", endTime=" + endTime +
181+
", totalRunTime=" + (endTime - startTime) + "(" + (endTime - startTime) / 1_000_000 + "ms)" +
182+
", engineTotalRunningTime=" + engineTotalRunningTime + "(" + engineTotalRunningTime / 1_000_000 + "ms)" +
183+
", totalDataFetcherInvocations=" + totalDataFetcherInvocations +
184+
", totalPropertyDataFetcherInvocations=" + totalPropertyDataFetcherInvocations +
185+
", fieldsFetchedCount=" + fieldsFetched.size() +
186+
", dataLoaderChainingEnabled=" + dataLoaderChainingEnabled +
187+
'}';
188+
189+
190+
}
191+
192+
@Override
193+
public String toString() {
194+
return shortSummary();
195+
}
169196
}

src/test/groovy/graphql/ProfilerTest.groovy

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,7 @@ class ProfilerTest extends Specification {
132132
given:
133133
def sdl = '''
134134
type Query {
135-
foo: Foo
135+
foo: [Foo]
136136
}
137137
type Foo {
138138
id: String
@@ -144,7 +144,7 @@ class ProfilerTest extends Specification {
144144
foo: { DataFetchingEnvironment dfe ->
145145
return CompletableFuture.supplyAsync {
146146
Thread.sleep(100)
147-
return [id: "1", name: "foo"]
147+
return [[id: "1", name: "foo"]]
148148
}
149149
} as DataFetcher],
150150
Foo : [
@@ -164,7 +164,7 @@ class ProfilerTest extends Specification {
164164
def profilerResult = ei.getGraphQLContext().get(ProfilerResult.PROFILER_CONTEXT_KEY) as ProfilerResult
165165

166166
then:
167-
result.getData() == [foo: [id: "1", name: "foo"]]
167+
result.getData() == [foo: [[id: "1", name: "foo"]]]
168168
profilerResult.getDataFetcherResultType() == ["/foo/name": COMPLETABLE_FUTURE_COMPLETED, "/foo": COMPLETABLE_FUTURE_NOT_COMPLETED]
169169

170170

0 commit comments

Comments
 (0)