public FetchedValue build() { return new FetchedValue(fetchedValue, rawFetchedValue, errors, localContext); } }
public static Builder newFetchedValue(FetchedValue otherValue) { return new Builder() .fetchedValue(otherValue.getFetchedValue()) .rawFetchedValue(otherValue.getRawFetchedValue()) .errors(otherValue.getErrors()) .localContext(otherValue.getLocalContext()) ; }
public FetchedValue transform(Consumer<Builder> builderConsumer) { Builder builder = newFetchedValue(this); builderConsumer.accept(builder); return builder.build(); }
private FetchedValue unboxPossibleOptional(FetchedValue result) { return result.transform( builder -> builder.fetchedValue(UnboxPossibleOptional.unboxPossibleOptional(result.getFetchedValue())) ); }
builder.executionStepInfo(executionStepInfo) .arguments(argumentValues) .source(fetchedValue.getFetchedValue()) .localContext(fetchedValue.getLocalContext()) .nonNullFieldValidator(nonNullableFieldValidator) );
public FetchedValueAnalysis analyzeFetchedValue(ExecutionContext executionContext, FetchedValue fetchedValue, ExecutionStepInfo executionInfo) throws NonNullableFieldWasNullException { return analyzeFetchedValueImpl(executionContext, fetchedValue, fetchedValue.getFetchedValue(), executionInfo); }
private FetchedValueAnalysis(Builder builder) { this.errors = new ArrayList<>(builder.errors); this.errors.addAll(builder.fetchedValue.getErrors()); this.valueType = assertNotNull(builder.valueType); this.completedValue = builder.completedValue; this.nullValue = builder.nullValue; this.children = builder.children; this.resolvedType = builder.resolvedType; this.executionStepInfo = assertNotNull(builder.executionInfo); this.fetchedValue = assertNotNull(builder.fetchedValue); }
public FieldSubSelection createFieldSubSelection(ExecutionContext executionContext, FetchedValueAnalysis analysis) { ExecutionStepInfo executionInfo = analysis.getExecutionStepInfo(); MergedField field = analysis.getField(); Object source = analysis.getCompletedValue(); Object localContext = analysis.getFetchedValue().getLocalContext(); GraphQLOutputType sourceType = executionInfo.getUnwrappedNonNullType(); GraphQLObjectType resolvedObjectType = resolveType.resolveType(executionContext, field, source, executionInfo.getArguments(), sourceType); FieldCollectorParameters collectorParameters = newParameters() .schema(executionContext.getGraphQLSchema()) .objectType(resolvedObjectType) .fragments(executionContext.getFragmentsByName()) .variables(executionContext.getVariables()) .build(); MergedSelectionSet subFields = fieldCollector.collectFields(collectorParameters, executionInfo.getField()); // it is not really a new step but rather a refinement ExecutionStepInfo newExecutionStepInfoWithResolvedType = executionInfo.changeTypeWithPreservedNonNull(resolvedObjectType); return FieldSubSelection.newFieldSubSelection() .source(source) .localContext(localContext) .mergedSelectionSet(subFields) .executionInfo(newExecutionStepInfoWithResolvedType) .build(); }
private FetchedValue unboxPossibleOptional(FetchedValue result) { return result.transform( builder -> builder.fetchedValue(UnboxPossibleOptional.unboxPossibleOptional(result.getFetchedValue())) ); }
builder.executionStepInfo(executionStepInfo) .arguments(argumentValues) .source(fetchedValue.getFetchedValue()) .localContext(fetchedValue.getLocalContext()) .nonNullFieldValidator(nonNullableFieldValidator) );
private CompletableFuture<Publisher<Object>> createSourceEventStream(ExecutionContext executionContext, ExecutionStrategyParameters parameters) { ExecutionStrategyParameters newParameters = firstFieldOfSubscriptionSelection(parameters); CompletableFuture<FetchedValue> fieldFetched = fetchField(executionContext, newParameters); return fieldFetched.thenApply(fetchedValue -> { Object publisher = fetchedValue.getFetchedValue(); if (publisher != null) { assertTrue(publisher instanceof Publisher, "You data fetcher must return a Publisher of events when using graphql subscriptions"); } //noinspection unchecked return (Publisher<Object>) publisher; }); }
private FetchedValueAnalysis(Builder builder) { this.errors = new ArrayList<>(builder.errors); this.errors.addAll(builder.fetchedValue.getErrors()); this.valueType = assertNotNull(builder.valueType); this.completedValue = builder.completedValue; this.nullValue = builder.nullValue; this.children = builder.children; this.resolvedType = builder.resolvedType; this.executionStepInfo = assertNotNull(builder.executionInfo); this.fetchedValue = assertNotNull(builder.fetchedValue); }
public FieldSubSelection createFieldSubSelection(ExecutionContext executionContext, FetchedValueAnalysis analysis) { ExecutionStepInfo executionInfo = analysis.getExecutionStepInfo(); MergedField field = analysis.getField(); Object source = analysis.getCompletedValue(); Object localContext = analysis.getFetchedValue().getLocalContext(); GraphQLOutputType sourceType = executionInfo.getUnwrappedNonNullType(); GraphQLObjectType resolvedObjectType = resolveType.resolveType(executionContext, field, source, executionInfo.getArguments(), sourceType); FieldCollectorParameters collectorParameters = newParameters() .schema(executionContext.getGraphQLSchema()) .objectType(resolvedObjectType) .fragments(executionContext.getFragmentsByName()) .variables(executionContext.getVariables()) .build(); MergedSelectionSet subFields = fieldCollector.collectFields(collectorParameters, executionInfo.getField()); // it is not really a new step but rather a refinement ExecutionStepInfo newExecutionStepInfoWithResolvedType = executionInfo.changeTypeWithPreservedNonNull(resolvedObjectType); return FieldSubSelection.newFieldSubSelection() .source(source) .localContext(localContext) .mergedSelectionSet(subFields) .executionInfo(newExecutionStepInfoWithResolvedType) .build(); }
@SuppressWarnings("unchecked") private List<FetchedValue> extractBatchedValues(FetchedValue fetchedValueContainingList, int expectedSize) { List<Object> list = (List<Object>) fetchedValueContainingList.getFetchedValue(); Assert.assertTrue(list.size() == expectedSize, "Unexpected result size"); List<FetchedValue> result = new ArrayList<>(); for (int i = 0; i < list.size(); i++) { List<GraphQLError> errors; if (i == 0) { errors = fetchedValueContainingList.getErrors(); } else { errors = Collections.emptyList(); } FetchedValue fetchedValue = FetchedValue.newFetchedValue() .fetchedValue(list.get(i)) .rawFetchedValue(fetchedValueContainingList.getRawFetchedValue()) .errors(errors) .localContext(fetchedValueContainingList.getLocalContext()) .build(); result.add(fetchedValue); } return result; }
private FetchedValue handleExceptionWhileFetching(Field field, ExecutionPath path, Throwable exception) { ExceptionWhileDataFetching exceptionWhileDataFetching = new ExceptionWhileDataFetching(path, exception, field.getSourceLocation()); return FetchedValue.newFetchedValue().errors(singletonList(exceptionWhileDataFetching)).build(); }
public FetchedValueAnalysis analyzeFetchedValue(ExecutionContext executionContext, FetchedValue fetchedValue, ExecutionStepInfo executionInfo) throws NonNullableFieldWasNullException { return analyzeFetchedValueImpl(executionContext, fetchedValue, fetchedValue.getFetchedValue(), executionInfo); }
public FetchedValue build() { return new FetchedValue(fetchedValue, rawFetchedValue, errors, localContext); } }
private FetchedValue unboxPossibleDataFetcherResult(MergedField sameField, ExecutionPath executionPath, FetchedValue result, Object localContext) { if (result.getFetchedValue() instanceof DataFetcherResult) { DataFetcherResult<?> dataFetcherResult = (DataFetcherResult) result.getFetchedValue(); List<AbsoluteGraphQLError> addErrors = dataFetcherResult.getErrors().stream() .map(relError -> new AbsoluteGraphQLError(sameField, executionPath, relError)) .collect(Collectors.toList()); List<GraphQLError> newErrors = new ArrayList<>(result.getErrors()); newErrors.addAll(addErrors); Object newLocalContext = dataFetcherResult.getLocalContext(); if (newLocalContext == null) { // if the field returns nothing then they get the context of their parent field newLocalContext = localContext; } return FetchedValue.newFetchedValue() .fetchedValue(dataFetcherResult.getData()) .rawFetchedValue(result.getRawFetchedValue()) .errors(newErrors) .localContext(newLocalContext) .build(); } else { return result; } } }
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(); } }
private CompletableFuture<Publisher<Object>> createSourceEventStream(ExecutionContext executionContext, ExecutionStrategyParameters parameters) { ExecutionStrategyParameters newParameters = firstFieldOfSubscriptionSelection(parameters); CompletableFuture<FetchedValue> fieldFetched = fetchField(executionContext, newParameters); return fieldFetched.thenApply(fetchedValue -> { Object publisher = fetchedValue.getFetchedValue(); if (publisher != null) { assertTrue(publisher instanceof Publisher, "You data fetcher must return a Publisher of events when using graphql subscriptions"); } //noinspection unchecked return (Publisher<Object>) publisher; }); }