Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,9 @@ default InstrumentationContext<Object> beginFieldFetch(InstrumentationFieldFetch
@Nullable
default FieldFetchingInstrumentationContext beginFieldFetching(InstrumentationFieldFetchParameters parameters, InstrumentationState state) {
InstrumentationContext<Object> ctx = beginFieldFetch(parameters, state);
if (ctx == noOp()) {
return FieldFetchingInstrumentationContext.NOOP;
}
return FieldFetchingInstrumentationContext.adapter(ctx);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
package graphql.execution.instrumentation

import graphql.execution.instrumentation.parameters.InstrumentationFieldFetchParameters
import spock.lang.Specification

class InstrumentationDefaultMethodsTest extends Specification {

def "default begin field fetching does not allocate an adapter for inherited no-op"() {
given:
def instrumentation = new Instrumentation() {}

when:
def context = instrumentation.beginFieldFetching(null, null)

then:
context.is(FieldFetchingInstrumentationContext.NOOP)
}

def "simple performant instrumentation begin field fetching does not allocate an adapter for inherited no-op"() {
when:
def context = SimplePerformantInstrumentation.INSTANCE.beginFieldFetching(null, null)

then:
context.is(FieldFetchingInstrumentationContext.NOOP)
}

def "default begin field fetching does not allocate an adapter when deprecated override returns no-op"() {
given:
def instrumentation = new Instrumentation() {
@Override
InstrumentationContext<Object> beginFieldFetch(InstrumentationFieldFetchParameters parameters, InstrumentationState state) {
return SimpleInstrumentationContext.noOp()
}
}

when:
def context = instrumentation.beginFieldFetching(null, null)

then:
context.is(FieldFetchingInstrumentationContext.NOOP)
}

def "default begin field fetching still adapts deprecated begin field fetch overrides"() {
given:
def events = []
def instrumentation = new Instrumentation() {
@Override
InstrumentationContext<Object> beginFieldFetch(InstrumentationFieldFetchParameters parameters, InstrumentationState state) {
return new InstrumentationContext<Object>() {
@Override
void onDispatched() {
events.add("dispatched")
}

@Override
void onCompleted(Object result, Throwable t) {
events.add(result)
}
}
}
}

when:
def context = instrumentation.beginFieldFetching(null, null)
context.onDispatched()
context.onFetchedValue("ignored")
context.onCompleted("completed", null)

then:
events == ["dispatched", "completed"]
}
}