Skip to content
Prev Previous commit
Next Next commit
fix defer support
  • Loading branch information
andimarek committed Sep 24, 2025
commit b25724b28582c893d612c8ee6f00b06a22abc037
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ private static class CallStack {

public ChainedDLStack chainedDLStack = new ChainedDLStack();

private final List<FieldValueInfo> deferredFragmentRootFieldsFetched = new ArrayList<>();
private int deferredFragmentRootFieldsCompleted;

public CallStack() {
}
Expand Down Expand Up @@ -370,14 +370,14 @@ public void deferredOnFieldValue(String resultKey, FieldValueInfo fieldValueInfo
CallStack callStack = getCallStack(parameters);
boolean ready;
synchronized (callStack) {
callStack.deferredFragmentRootFieldsFetched.add(fieldValueInfo);
callStack.deferredFragmentRootFieldsCompleted++;
Assert.assertNotNull(parameters.getDeferredCallContext());
ready = callStack.deferredFragmentRootFieldsFetched.size() == parameters.getDeferredCallContext().getFields();
ready = callStack.deferredFragmentRootFieldsCompleted == parameters.getDeferredCallContext().getFields();
}
// if (ready) {
// int curLevel = parameters.getPath().getLevel();
// onFieldValuesInfoDispatchIfNeeded(callStack.deferredFragmentRootFieldsFetched, curLevel, callStack);
// }
if (ready) {
onCompletionFinished(parameters.getDeferredCallContext().getStartLevel() - 1, callStack);
}

}

//
Expand All @@ -393,16 +393,21 @@ private CallStack getCallStack(@Nullable AlternativeCallContext alternativeCallC
return alternativeCallContextMap.computeIfAbsent(alternativeCallContext, k -> {
CallStack callStack = new CallStack();
// System.out.println("new callstack : " + callStack.hashCode());
// for subscriptions there is only root field which is already fetched
// callStack.expectedFetchCountPerLevel.set(1, 1);
// callStack.happenedFetchCountPerLevel.set(1, 1);
// // the level 0 is done
// callStack.happenedExecuteObjectCallsPerLevel.set(0, 1);
// callStack.happenedCompletionFinishedCountPerLevel.set(0, 1);
// // level is 1 already dispatched
// callStack.setDispatchedLevel(1);
// int startLevel = alternativeCallContext.getStartLevel();
// int fields = alternativeCallContext.getFields();
// on which level the fields are
int startLevel = k.getStartLevel();
// how many fields are deferred on this level
int fields = k.getFields();
if (startLevel > 1) {
// parent level is considered dispatched all fields completed
callStack.dispatchedLevels.add(startLevel - 1);
callStack.happenedExecuteObjectCallsPerLevel.set(startLevel - 2, 1);
callStack.happenedCompletionFinishedCountPerLevel.set(startLevel - 2, 1);
}
// the parent will have one completion therefore we set the expectation to 1
callStack.happenedExecuteObjectCallsPerLevel.set(startLevel - 1, 1);

// for the current level we set the fetch expectations
callStack.expectedFetchCountPerLevel.set(startLevel, fields);
return callStack;
});
}
Expand All @@ -419,7 +424,7 @@ private void resetCallStack(CallStack callStack) {

private boolean markLevelAsDispatchedIfReady(int level, CallStack callStack) {
boolean ready = isLevelReady(level, callStack);
// System.out.println("markLevelAsDispatchedIfReady level: " + level + " ready: " + ready);
// System.out.println("markLevelAsDispatchedIfReady level: " + level + " ready: " + ready + " callstack: " + callStack.hashCode());
if (ready) {
callStack.setDispatchedLevel(level);
return true;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ import org.dataloader.DataLoader
import org.dataloader.DataLoaderFactory
import org.dataloader.DataLoaderRegistry
import org.reactivestreams.Publisher
import spock.lang.Ignore
import spock.lang.Specification
import spock.lang.Unroll

Expand Down Expand Up @@ -1691,7 +1690,6 @@ class DeferExecutionSupportIntegrationTest extends Specification {

}

@Ignore("tmp not working")
def "dataloader used inside defer"() {
given:
def query = '''
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ import org.awaitility.Awaitility
import org.dataloader.BatchLoader
import org.dataloader.DataLoaderFactory
import org.dataloader.DataLoaderRegistry
import spock.lang.Ignore
import spock.lang.RepeatUntilFailure
import spock.lang.Specification

Expand Down Expand Up @@ -61,7 +60,6 @@ class DeferWithDataLoaderTest extends Specification {
}
}

@Ignore
def "query with single deferred field"() {
given:
def query = getQuery(true, false)
Expand Down Expand Up @@ -106,7 +104,6 @@ class DeferWithDataLoaderTest extends Specification {
batchCompareDataFetchers.productsForDepartmentsBatchLoaderCounter.get() == 3
}

@Ignore
def "multiple fields on same defer block"() {
given:
def query = """
Expand Down Expand Up @@ -180,7 +177,6 @@ class DeferWithDataLoaderTest extends Specification {
batchCompareDataFetchers.productsForDepartmentsBatchLoaderCounter.get() == 0
}

@Ignore
def "query with nested deferred fields"() {
given:
def query = getQuery(true, true)
Expand Down Expand Up @@ -232,7 +228,6 @@ class DeferWithDataLoaderTest extends Specification {
batchCompareDataFetchers.productsForDepartmentsBatchLoaderCounter.get() == 9
}

@Ignore
def "query with top-level deferred field"() {
given:
def query = """
Expand Down Expand Up @@ -296,7 +291,6 @@ class DeferWithDataLoaderTest extends Specification {
batchCompareDataFetchers.productsForDepartmentsBatchLoaderCounter.get() == 0
}

@Ignore
def "query with multiple deferred fields"() {
given:
def query = getExpensiveQuery(true)
Expand Down Expand Up @@ -354,7 +348,6 @@ class DeferWithDataLoaderTest extends Specification {
batchCompareDataFetchers.productsForDepartmentsBatchLoaderCounter.get() == 1
}

@Ignore
@RepeatUntilFailure(maxAttempts = 50, ignoreRest = false)
def "dataloader in initial result and chained dataloader inside nested defer block"() {
given:
Expand Down