private CompletableFuture<ExecutionResult> deferSupport(ExecutionContext executionContext, CompletableFuture<ExecutionResult> result) { return result.thenApply(er -> { DeferSupport deferSupport = executionContext.getDeferSupport(); if (deferSupport.isDeferDetected()) { // we start the rest of the query now to maximize throughput. We have the initial important results // and now we can start the rest of the calls as early as possible (even before some one subscribes) Publisher<ExecutionResult> publisher = deferSupport.startDeferredCalls(); return ExecutionResultImpl.newExecutionResult().from((ExecutionResultImpl) er) .addExtension(GraphQL.DEFERRED_RESULTS, publisher) .build(); } return er; }); }
private boolean isDeferred(ExecutionContext executionContext, ExecutionStrategyParameters parameters, MergedField currentField) { DeferSupport deferSupport = executionContext.getDeferSupport(); if (deferSupport.checkForDeferDirective(currentField)) { DeferredErrorSupport errorSupport = new DeferredErrorSupport(); // with a deferred field we are really resetting where we execute from, that is from this current field onwards Map<String, MergedField> fields = new LinkedHashMap<>(); fields.put(currentField.getName(), currentField); ExecutionStrategyParameters callParameters = parameters.transform(builder -> { MergedSelectionSet mergedSelectionSet = newMergedSelectionSet().subFields(fields).build(); builder.deferredErrorSupport(errorSupport) .field(currentField) .fields(mergedSelectionSet) .parent(null) // this is a break in the parent -> child chain - its a new start effectively .listSize(0) .currentListIndex(0); } ); DeferredCall call = new DeferredCall(deferredExecutionResult(executionContext, callParameters), errorSupport); deferSupport.enqueue(call); return true; } return false; }
private CompletableFuture<ExecutionResult> deferSupport(ExecutionContext executionContext, CompletableFuture<ExecutionResult> result) { return result.thenApply(er -> { DeferSupport deferSupport = executionContext.getDeferSupport(); if (deferSupport.isDeferDetected()) { // we start the rest of the query now to maximize throughput. We have the initial important results // and now we can start the rest of the calls as early as possible (even before some one subscribes) Publisher<ExecutionResult> publisher = deferSupport.startDeferredCalls(); return ExecutionResultImpl.newExecutionResult().from((ExecutionResultImpl) er) .addExtension(GraphQL.DEFERRED_RESULTS, publisher) .build(); } return er; }); }
private boolean isDeferred(ExecutionContext executionContext, ExecutionStrategyParameters parameters, MergedField currentField) { DeferSupport deferSupport = executionContext.getDeferSupport(); if (deferSupport.checkForDeferDirective(currentField)) { DeferredErrorSupport errorSupport = new DeferredErrorSupport(); // with a deferred field we are really resetting where we execute from, that is from this current field onwards Map<String, MergedField> fields = new LinkedHashMap<>(); fields.put(currentField.getName(), currentField); ExecutionStrategyParameters callParameters = parameters.transform(builder -> { MergedSelectionSet mergedSelectionSet = newMergedSelectionSet().subFields(fields).build(); builder.deferredErrorSupport(errorSupport) .field(currentField) .fields(mergedSelectionSet) .parent(null) // this is a break in the parent -> child chain - its a new start effectively .listSize(0) .currentListIndex(0); } ); DeferredCall call = new DeferredCall(deferredExecutionResult(executionContext, callParameters), errorSupport); deferSupport.enqueue(call); return true; } return false; }