private FetchedValue unboxPossibleOptional(FetchedValue result) { return result.transform( builder -> builder.fetchedValue(UnboxPossibleOptional.unboxPossibleOptional(result.getFetchedValue())) ); }
private BiFunction<List<Object>, Throwable, FetchedValues> handleResult(ExecutionContext executionContext, ExecutionStrategyParameters parameters, List<MapOrList> parentResults, DataFetchingEnvironment environment) { return (result, exception) -> { if (exception != null) { if (exception instanceof CompletionException) { exception = exception.getCause(); } DataFetcherExceptionHandlerParameters handlerParameters = DataFetcherExceptionHandlerParameters.newExceptionParameters() .dataFetchingEnvironment(environment) .exception(exception) .build(); DataFetcherExceptionHandlerResult handlerResult = dataFetcherExceptionHandler.onException(handlerParameters); handlerResult.getErrors().forEach(executionContext::addError); result = Collections.nCopies(parentResults.size(), null); } List<Object> values = result; List<FetchedValue> retVal = new ArrayList<>(); for (int i = 0; i < parentResults.size(); i++) { Object value = unboxPossibleOptional(values.get(i)); retVal.add(new FetchedValue(parentResults.get(i), value)); } return new FetchedValues(retVal, parameters.getExecutionStepInfo(), parameters.getPath()); }; }
FetchedValue unboxPossibleDataFetcherResult(ExecutionContext executionContext, ExecutionStrategyParameters parameters, Object result) { if (result instanceof DataFetcherResult) { //noinspection unchecked DataFetcherResult<?> dataFetcherResult = (DataFetcherResult) result; dataFetcherResult.getErrors().stream() .map(relError -> new AbsoluteGraphQLError(parameters, relError)) .forEach(executionContext::addError); Object localContext = dataFetcherResult.getLocalContext(); if (localContext == null) { // if the field returns nothing then they get the context of their parent field localContext = parameters.getLocalContext(); } return FetchedValue.newFetchedValue() .fetchedValue(UnboxPossibleOptional.unboxPossibleOptional(dataFetcherResult.getData())) .rawFetchedValue(dataFetcherResult.getData()) .errors(dataFetcherResult.getErrors()) .localContext(localContext) .build(); } else { return FetchedValue.newFetchedValue() .fetchedValue(UnboxPossibleOptional.unboxPossibleOptional(result)) .rawFetchedValue(result) .build(); } }
@SuppressWarnings("unchecked") private List<ExecutionNode> handleList(ExecutionContext executionContext, Map<String, Object> argumentValues, FetchedValues fetchedValues, String fieldName, MergedField fields, ExecutionStepInfo executionStepInfo) { GraphQLList listType = (GraphQLList) executionStepInfo.getUnwrappedNonNullType(); List<FetchedValue> flattenedValues = new ArrayList<>(); for (FetchedValue value : fetchedValues.getValues()) { MapOrList mapOrList = value.getParentResult(); if (value.getValue() == null) { mapOrList.putOrAdd(fieldName, null); continue; } MapOrList listResult = mapOrList.createAndPutList(fieldName); for (Object rawValue : toIterable(value.getValue())) { rawValue = unboxPossibleOptional(rawValue); flattenedValues.add(new FetchedValue(listResult, rawValue)); } } GraphQLOutputType innerSubType = (GraphQLOutputType) listType.getWrappedType(); ExecutionStepInfo newExecutionStepInfo = executionStepInfo.changeTypeWithPreservedNonNull((GraphQLOutputType) GraphQLTypeUtil.unwrapNonNull(innerSubType)); FetchedValues flattenedFetchedValues = new FetchedValues(flattenedValues, newExecutionStepInfo, fetchedValues.getPath()); return completeValues(executionContext, flattenedFetchedValues, newExecutionStepInfo, fieldName, fields, argumentValues); }
Object result = UnboxPossibleOptional.unboxPossibleOptional(parameters.getSource()); GraphQLType fieldType = executionStepInfo.getUnwrappedNonNullType(); CompletableFuture<ExecutionResult> fieldValue;
private FetchedValue unboxPossibleOptional(FetchedValue result) { return result.transform( builder -> builder.fetchedValue(UnboxPossibleOptional.unboxPossibleOptional(result.getFetchedValue())) ); }
private BiFunction<List<Object>, Throwable, FetchedValues> handleResult(ExecutionContext executionContext, ExecutionStrategyParameters parameters, List<MapOrList> parentResults, DataFetchingEnvironment environment) { return (result, exception) -> { if (exception != null) { if (exception instanceof CompletionException) { exception = exception.getCause(); } DataFetcherExceptionHandlerParameters handlerParameters = DataFetcherExceptionHandlerParameters.newExceptionParameters() .dataFetchingEnvironment(environment) .exception(exception) .build(); DataFetcherExceptionHandlerResult handlerResult = dataFetcherExceptionHandler.onException(handlerParameters); handlerResult.getErrors().forEach(executionContext::addError); result = Collections.nCopies(parentResults.size(), null); } List<Object> values = result; List<FetchedValue> retVal = new ArrayList<>(); for (int i = 0; i < parentResults.size(); i++) { Object value = unboxPossibleOptional(values.get(i)); retVal.add(new FetchedValue(parentResults.get(i), value)); } return new FetchedValues(retVal, parameters.getExecutionStepInfo(), parameters.getPath()); }; }
.fetchedValue(UnboxPossibleOptional.unboxPossibleOptional(dataFetcherResult.getData())) .rawFetchedValue(dataFetcherResult.getData()) .errors(dataFetcherResult.getErrors()) } else { return FetchedValue.newFetchedValue() .fetchedValue(UnboxPossibleOptional.unboxPossibleOptional(result)) .rawFetchedValue(result) .build();
@SuppressWarnings("unchecked") private List<ExecutionNode> handleList(ExecutionContext executionContext, Map<String, Object> argumentValues, FetchedValues fetchedValues, String fieldName, MergedField fields, ExecutionStepInfo executionStepInfo) { GraphQLList listType = (GraphQLList) executionStepInfo.getUnwrappedNonNullType(); List<FetchedValue> flattenedValues = new ArrayList<>(); for (FetchedValue value : fetchedValues.getValues()) { MapOrList mapOrList = value.getParentResult(); if (value.getValue() == null) { mapOrList.putOrAdd(fieldName, null); continue; } MapOrList listResult = mapOrList.createAndPutList(fieldName); for (Object rawValue : toIterable(value.getValue())) { rawValue = unboxPossibleOptional(rawValue); flattenedValues.add(new FetchedValue(listResult, rawValue)); } } GraphQLOutputType innerSubType = (GraphQLOutputType) listType.getWrappedType(); ExecutionStepInfo newExecutionStepInfo = executionStepInfo.changeTypeWithPreservedNonNull((GraphQLOutputType) GraphQLTypeUtil.unwrapNonNull(innerSubType)); FetchedValues flattenedFetchedValues = new FetchedValues(flattenedValues, newExecutionStepInfo, fetchedValues.getPath()); return completeValues(executionContext, flattenedFetchedValues, newExecutionStepInfo, fieldName, fields, argumentValues); }
Object result = UnboxPossibleOptional.unboxPossibleOptional(parameters.getSource()); GraphQLType fieldType = executionStepInfo.getUnwrappedNonNullType(); CompletableFuture<ExecutionResult> fieldValue;