Skip to content

Commit 855d10b

Browse files
committed
Better javadoc on beginFieldFetching
1 parent a93342d commit 855d10b

2 files changed

Lines changed: 25 additions & 19 deletions

File tree

src/main/java/graphql/execution/instrumentation/FieldFetchingInstrumentationContext.java

Lines changed: 20 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,30 @@
22

33
import graphql.Internal;
44
import graphql.PublicSpi;
5+
import graphql.execution.instrumentation.parameters.InstrumentationFieldFetchParameters;
56
import org.jetbrains.annotations.NotNull;
67
import org.jetbrains.annotations.Nullable;
78

9+
/**
10+
* FieldFetchingInstrumentationContext is returned back from the {@link Instrumentation#beginFieldFetching(InstrumentationFieldFetchParameters, InstrumentationState)}
11+
* method, and it's much like the normal {@link InstrumentationContext} type except it also
12+
* gives the value that was returned by a fields {@link graphql.schema.DataFetcher}. This allows
13+
* you to know if the field value is a completely materialised field or if it's a {@link java.util.concurrent.CompletableFuture}
14+
* promise to a value.
15+
*/
816
@PublicSpi
917
public interface FieldFetchingInstrumentationContext extends InstrumentationContext<Object> {
1018

19+
/**
20+
* This is called back with the value fetched for the field by its {@link graphql.schema.DataFetcher}.
21+
* This can be a materialised java object or it maybe a {@link java.util.concurrent.CompletableFuture}
22+
* promise to some async value that has not yet completed.
23+
*
24+
* @param fetchedValue a value that a field's {@link graphql.schema.DataFetcher} returned
25+
*/
26+
default void onFetchedValue(Object fetchedValue) {
27+
}
28+
1129
@Internal
1230
FieldFetchingInstrumentationContext NOOP = new FieldFetchingInstrumentationContext() {
1331
@Override
@@ -17,18 +35,13 @@ public void onDispatched() {
1735
@Override
1836
public void onCompleted(Object result, Throwable t) {
1937
}
20-
21-
@Override
22-
public void onFetchedValue(Object fetchedValue) {
23-
}
2438
};
2539

2640
/**
27-
* This creates a no-op {@link InstrumentationContext} if the one pass in is null
41+
* This creates a no-op {@link InstrumentationContext} if the one passed in is null
2842
*
2943
* @param nullableContext a {@link InstrumentationContext} that can be null
30-
*
31-
* @return a non null {@link InstrumentationContext} that maybe a no-op
44+
* @return a non-null {@link InstrumentationContext} that maybe a no-op
3245
*/
3346
@NotNull
3447
@Internal
@@ -51,18 +64,6 @@ public void onDispatched() {
5164
public void onCompleted(Object result, Throwable t) {
5265
context.onCompleted(result, t);
5366
}
54-
55-
@Override
56-
public void onFetchedValue(Object fetchedValue) {
57-
}
5867
};
5968
}
60-
61-
/**
62-
* This is called back with value fetched for the field.
63-
*
64-
* @param fetchedValue a value that a field's {@link graphql.schema.DataFetcher} returned
65-
*/
66-
default void onFetchedValue(Object fetchedValue) {
67-
}
6869
}

src/main/java/graphql/execution/instrumentation/Instrumentation.java

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -209,6 +209,11 @@ default InstrumentationContext<Object> beginFieldFetch(InstrumentationFieldFetch
209209
* This is called just before a field {@link DataFetcher} is invoked. The {@link FieldFetchingInstrumentationContext#onFetchedValue(Object)}
210210
* callback will be invoked once a value is returned by a {@link DataFetcher} but perhaps before
211211
* its value is completed if it's a {@link CompletableFuture} value.
212+
* <p>
213+
* This method is the replacement method for the now deprecated {@link #beginFieldFetch(InstrumentationFieldFetchParameters, InstrumentationState)}
214+
* method, and it should be implemented in new {@link Instrumentation} classes. This default version of this
215+
* method calls back to the deprecated {@link #beginFieldFetch(InstrumentationFieldFetchParameters, InstrumentationState)} method
216+
* so that older implementations continue to work.
212217
*
213218
* @param parameters the parameters to this step
214219
* @param state the state created during the call to {@link #createStateAsync(InstrumentationCreateStateParameters)}

0 commit comments

Comments
 (0)