8000 Intern field names by DanielThomas · Pull Request #3489 · graphql-java/graphql-java · GitHub
[go: up one dir, main page]

Skip to content
Merged
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
13 changes: 4 additions & 9 deletions src/main/java/graphql/GraphQL.java
Original file line number Diff line number Diff line change
Expand Up @@ -420,17 +420,16 @@ public CompletableFuture<ExecutionResult> executeAsync(ExecutionInput executionI
InstrumentationExecutionParameters inputInstrumentationParameters = new InstrumentationExecutionParameters(executionInputWithId, this.graphQLSchema, instrumentationState);
ExecutionInput instrumentedExecutionInput = instrumentation.instrumentExecutionInput(executionInputWithId, inputInstrumentationParameters, instrumentationState);

CompletableFuture<ExecutionResult> beginExecutionCF = new CompletableFuture<>();
InstrumentationExecutionParameters instrumentationParameters = new InstrumentationExecutionParameters(instrumentedExecutionInput, this.graphQLSchema, instrumentationState);
InstrumentationContext<ExecutionResult> executionInstrumentation = nonNullCtx(instrumentation.beginExecution(instrumentationParameters, instrumentationState));
executionInstrumentation.onDispatched(beginExecutionCF);
executionInstrumentation.onDispatched();

GraphQLSchema graphQLSchema = instrumentation.instrumentSchema(this.graphQLSchema, instrumentationParameters, instrumentationState);

CompletableFuture<ExecutionResult> executionResult = parseValidateAndExecute(instrumentedExecutionInput, graphQLSchema, instrumentationState);
//
// finish up instrumentation
executionResult = executionResult.whenComplete(completeInstrumentationCtxCF(executionInstrumentation, beginExecutionCF));
executionResult = executionResult.whenComplete(completeInstrumentationCtxCF(executionInstrumentation));
//
// allow instrumentation to tweak the result
executionResult = executionResult.thenCompose(result -> instrumentation.instrumentExecutionResult(result, instrumentationParameters, instrumentationState));
Expand Down Expand Up @@ -507,15 +506,13 @@ private PreparsedDocumentEntry parseAndValidate(AtomicReference<ExecutionInput>
private ParseAndValidateResult parse(ExecutionInput executionInput, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) {
InstrumentationExecutionParameters parameters = new InstrumentationExecutionParameters(executionInput, graphQLSchema, instrumentationState);
InstrumentationContext<Document> parseInstrumentationCtx = nonNullCtx(instrumentation.beginParse(parameters, instrumentationState));
CompletableFuture<Document> documentCF = new CompletableFuture<>();
parseInstrumentationCtx.onDispatched(documentCF);
parseInstrumentationCtx.onDispatched();

ParseAndValidateResult parseResult = ParseAndValidate.parse(executionInput);
if (parseResult.isFailure()) {
parseInstrumentationCtx.onCompleted(null, parseResult.getSyntaxException());
return parseResult;
} else {
documentCF.complete(parseResult.getDocument());
parseInstrumentationCtx.onCompleted(parseResult.getDocument(), null);

DocumentAndVariables documentAndVariables = parseResult.getDocumentAndVariables();
Expand All @@ -527,15 +524,13 @@ private ParseAndValidateResult parse(ExecutionInput executionInput, GraphQLSchem

private List<ValidationError> validate(ExecutionInput executionInput, Document document, GraphQLSchema graphQLSchema, InstrumentationState instrumentationState) {
InstrumentationContext<List<ValidationError>> validationCtx = nonNullCtx(instrumentation.beginValidation(new InstrumentationValidationParameters(executionInput, document, graphQLSchema, instrumentationState), instrumentationState));
CompletableFuture<List<ValidationError>> cf = new CompletableFuture<>();
validationCtx.onDispatched(cf);
validationCtx.onDispatched();

Predicate<Class<?>> validationRulePredicate = executionInput.getGraphQLContext().getOrDefault(ParseAndValidate.INTERNAL_VALIDATION_PREDICATE_HINT, r -> true);
Locale locale = executionInput.getLocale() != null ? executionInput.getLocale() : Locale.getDefault();
List<ValidationError> validationErrors = ParseAndValidate.validate(graphQLSchema, document, validationRulePredicate, locale);

validationCtx.onCompleted(validationErrors, null);
cf.complete(validationErrors);
return validationErrors;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ public CompletableFuture<ExecutionResult> execute(ExecutionContext executionCont
Async.CombinedBuilder<FieldValueInfo> futures = getAsyncFieldValueInfo(executionContext, parameters, deferredExecutionSupport);

CompletableFuture<ExecutionResult> overallResult = new CompletableFuture<>();
executionStrategyCtx.onDispatched(overallResult);
executionStrategyCtx.onDispatched();

futures.await().whenComplete((completeValueInfos, throwable) -> {
List<String> fieldsExecutedOnInitialResult = deferredExecutionSupport.getNonDeferredFieldNames(fieldNames);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public CompletableFuture<ExecutionResult> execute(ExecutionContext executionCont
});

CompletableFuture<ExecutionResult> overallResult = new CompletableFuture<>();
executionStrategyCtx.onDispatched(overallResult);
executionStrategyCtx.onDispatched();

resultsFuture.whenComplete(handleResults(executionContext, fieldNames, overallResult));
overallResult.whenComplete(executionStrategyCtx::onCompleted);
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/graphql/execution/Execution.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ private CompletableFuture<ExecutionResult> executeOperation(ExecutionContext exe
ExecutionResult executionResult = new ExecutionResultImpl(Collections.singletonList((GraphQLError) rte));
CompletableFuture<ExecutionResult> resultCompletableFuture = completedFuture(executionResult);

executeOperationCtx.onDispatched(resultCompletableFuture);
executeOperationCtx.onDispatched();
executeOperationCtx.onCompleted(executionResult, rte);
return resultCompletableFuture;
}
Expand Down Expand Up @@ -189,7 +189,7 @@ private CompletableFuture<ExecutionResult> executeOperation(ExecutionContext exe
}

// note this happens NOW - not when the result completes
executeOperationCtx.onDispatched(result);
executeOperationCtx.onDispatched();

// fill out extensions if we have them
result = result.thenApply(er -> mergeExtensionsBuilderIfPresent(er, graphQLContext));
Expand Down
42 changes: 16 additions & 26 deletions src/main/java/graphql/execution/ExecutionStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ protected CompletableFuture<Map<String, Object>> executeObject(ExecutionContext
Async.CombinedBuilder<FieldValueInfo> resolvedFieldFutures = getAsyncFieldValueInfo(executionContext, parameters, deferredExecutionSupport);

CompletableFuture<Map<String, Object>> overallResult = new CompletableFuture<>();
resolveObjectCtx.onDispatched(overallResult);
resolveObjectCtx.onDispatched();

resolvedFieldFutures.await().whenComplete((completeValueInfos, throwable) -> {
List<String> fieldsExecutedOnInitialResult = deferredExecutionSupport.getNonDeferredFieldNames(fieldNames);
Expand Down Expand Up @@ -354,7 +354,7 @@ protected CompletableFuture<FieldValueInfo> resolveFieldWithInfo(ExecutionContex

CompletableFuture<Object> fieldValueFuture = result.thenCompose(FieldValueInfo::getFieldValueFuture);

fieldCtx.onDispatched(fieldValueFuture);
fieldCtx.onDispatched();
fieldValueFuture.whenComplete(fieldCtx::onCompleted);
return result;
}
Expand Down Expand Up @@ -425,7 +425,7 @@ protected CompletableFuture<FetchedValue> fetchField(ExecutionContext executionC
dataFetcher = executionContext.getDataLoaderDispatcherStrategy().modifyDataFetcher(dataFetcher);
CompletableFuture<Object> fetchedValue = invokeDataFetcher(executionContext, parameters, fieldDef, dataFetchingEnvironment, dataFetcher);
executionContext.getDataLoaderDispatcherStrategy().fieldFetched(executionContext, parameters, dataFetcher, fetchedValue);
fetchCtx.onDispatched(fetchedValue);
fetchCtx.onDispatched();
return fetchedValue
.handle((result, exception) -> {
fetchCtx.onCompleted(result, exception);
Expand Down Expand Up @@ -475,18 +475,11 @@ protected FetchedValue unboxPossibleDataFetcherResult(ExecutionContext execution
// if the field returns nothing then they get the context of their parent field
localContext = parameters.getLocalContext();
}
return F B8CC etchedValue.newFetchedValue()
.fetchedValue(executionContext.getValueUnboxer().unbox(dataFetcherResult.getData()))
.rawFetchedValue(dataFetcherResult.getData())
.errors(dataFetcherResult.getErrors())
.localContext(localContext)
.build();
Object unBoxedValue = executionContext.getValueUnboxer().unbox(dataFetcherResult.getData());
return new FetchedValue(unBoxedValue, dataFetcherResult.getErrors(), localContext);
} else {
return FetchedValue.newFetchedValue()
.fetchedValue(executionContext.getValueUnboxer().unbox(result))
.rawFetchedValue(result)
.localContext(parameters.getLocalContext())
.build();
Object unBoxedValue = executionContext.getValueUnboxer().unbox(result);
return new FetchedValue(unBoxedValue, ImmutableList.of(), parameters.getLocalContext());
}
}

Expand Down Expand Up @@ -575,7 +568,7 @@ protected FieldValueInfo completeField(ExecutionContext executionContext, Execut
FieldValueInfo fieldValueInfo = completeValue(executionContext, newParameters);

CompletableFuture<Object> executionResultFuture = fieldValueInfo.getFieldValueFuture();
ctxCompleteField.onDispatched(executionResultFuture);
ctxCompleteField.onDispatched();
executionResultFuture.whenComplete(ctxCompleteField::onCompleted);
return fieldValueInfo;
}
Expand Down Expand Up @@ -608,10 +601,10 @@ protected FieldValueInfo completeValue(ExecutionContext executionContext, Execut
return completeValueForList(executionContext, parameters, result);
} else if (isScalar(fieldType)) {
fieldValue = completeValueForScalar(executionContext, parameters, (GraphQLScalarType) fieldType, result);
return FieldValueInfo.newFieldValueInfo(SCALAR).fieldValue(fieldValue).build();
return new FieldValueInfo(SCALAR, fieldValue);
} else if (isEnum(fieldType)) {
fieldValue = completeValueForEnum(executionContext, parameters, (GraphQLEnumType) fieldType, result);
return FieldValueInfo.newFieldValueInfo(ENUM).fieldValue(fieldValue).build();
return new FieldValueInfo(ENUM, fieldValue);
}

// when we are here, we have a complex type: Interface, Union or Object
Expand All @@ -628,7 +621,7 @@ protected FieldValueInfo completeValue(ExecutionContext executionContext, Execut
// complete field as null, validating it is nullable
return getFieldValueInfoForNull(parameters);
}
return FieldValueInfo.newFieldValueInfo(OBJECT).fieldValue(fieldValue).build();
return new FieldValueInfo(OBJECT, fieldValue);
}

private void handleUnresolvedTypeProblem(ExecutionContext context, ExecutionStrategyParameters parameters, UnresolvedTypeException e) {
Expand All @@ -649,7 +642,7 @@ private void handleUnresolvedTypeProblem(ExecutionContext context, ExecutionStra
*/
private FieldValueInfo getFieldValueInfoForNull(ExecutionStrategyParameters parameters) {
CompletableFuture<Object> fieldValue = completeValueForNull(parameters);
return FieldValueInfo.newFieldValueInfo(NULL).fieldValue(fieldValue).build();
return new FieldValueInfo(NULL, fieldValue);
}

protected CompletableFuture<Object> completeValueForNull(ExecutionStrategyParameters parameters) {
Expand All @@ -674,10 +667,10 @@ protected FieldValueInfo completeValueForList(ExecutionContext executionContext,
try {
resultIterable = parameters.getNonNullFieldValidator().validate(parameters.getPath(), resultIterable);
} catch (NonNullableFieldWasNullException e) {
return FieldValueInfo.newFieldValueInfo(LIST).fieldValue(exceptionallyCompletedFuture(e)).build();
return new FieldValueInfo(LIST, exceptionallyCompletedFuture(e));
}
if (resultIterable == null) {
return FieldValueInfo.newFieldValueInfo(LIST).fieldValue(completedFuture(null)).build();
return new FieldValueInfo(LIST, completedFuture(null));
}
return completeValueForList(executionContext, parameters, resultIterable);
}
Expand Down Expand Up @@ -729,7 +722,7 @@ protected FieldValueInfo completeValueForList(ExecutionContext executionContext,
CompletableFuture<List<Object>> resultsFuture = Async.each(fieldValueInfos, FieldValueInfo::getFieldValueFuture);

CompletableFuture<Object> overallResult = new CompletableFuture<>();
completeListCtx.onDispatched(overallResult);
completeListCtx.onDispatched();
overallResult.whenComplete(completeListCtx::onCompleted);

resultsFuture.whenComplete((results, exception) -> {
Expand All @@ -742,10 +735,7 @@ protected FieldValueInfo completeValueForList(ExecutionContext executionContext,
overallResult.complete(completedResults);
});

return FieldValueInfo.newFieldValueInfo(LIST)
.fieldValue(overallResult)
.fieldValueInfos(fieldValueInfos)
.build();
return new FieldValueInfo(LIST, overallResult, fieldValueInfos);
}

protected <T> void handleValueException(CompletableFuture<T> overallResult, Throwable e, ExecutionContext executionContext) {
Expand Down
62 changes: 2 additions & 60 deletions src/main/java/graphql/execution/FetchedValue.java
52F4 6B28
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import graphql.execution.instrumentation.parameters.InstrumentationFieldCompleteParameters;

import java.util.List;
import java.util.function.Consumer;

/**
* Note: This is returned by {@link InstrumentationFieldCompleteParameters#getFetchedValue()}
Expand All @@ -15,14 +14,12 @@
@PublicApi
public class FetchedValue {
private final Object fetchedValue;
private final Object rawFetchedValue;
private final Object localContext;
private final ImmutableList<GraphQLError> errors;

private FetchedValue(Object fetchedValue, Object rawFetchedValue, ImmutableList<GraphQLError> errors, Object localContext) {
FetchedValue(Object fetchedValue, List<GraphQLError> errors, Object localContext) {
this.fetchedValue = fetchedValue;
this.rawFetchedValue = rawFetchedValue;
this.errors = errors;
this.errors = ImmutableList.copyOf(errors);
this.localContext = localContext;
}

Expand All @@ -33,10 +30,6 @@ public Object getFetchedValue() {
return fetchedValue;
}

public Object getRawFetchedValue() {
return rawFetchedValue;
}

public List<GraphQLError> getErrors() {
return errors;
}
Expand All @@ -45,64 +38,13 @@ public Object getLocalContext() {
return localContext;
}

public FetchedValue transform(Consumer<Builder> builderConsumer) {
Builder builder = newFetchedValue(this);
builderConsumer.accept(builder);
return builder.build();
}

@Override
public String toString() {
return "FetchedValue{" +
"fetchedValue=" + fetchedValue +
", rawFetchedValue=" + rawFetchedValue +
", localContext=" + localContext +
", errors=" + errors +
'}';
}

public static Builder newFetchedValue() {
return new Builder();
}

public static Builder newFetchedValue(FetchedValue otherValue) {
return new Builder()
.fetchedValue(otherValue.getFetchedValue())
.rawFetchedValue(otherValue.getRawFetchedValue())
.errors(otherValue.getErrors())
.localContext(otherValue.getLocalContext())
;
}

public static class Builder {

private Object fetchedValue;
private Object rawFetchedValue;
private Object localContext;
private ImmutableList<GraphQLError> errors = ImmutableList.of();

public Builder fetchedValue(Object fetchedValue) {
this.fetchedValue = fetchedValue;
return this;
}

public Builder rawFetchedValue(Object rawFetchedValue) {
this.rawFetchedValue = rawFetchedValue;
return this;
}

public Builder localContext(Object localContext) {
this.localContext = localContext;
return this;
}

public Builder errors(List<GraphQLError> errors) {
this.errors = ImmutableList.copyOf(errors);
return this;
}

public FetchedValue build() {
return new FetchedValue(fetchedValue, rawFetchedValue, errors, localContext);
}
}
}
44 changes: 8 additions & 36 deletions src/main/java/graphql/execution/FieldValueInfo.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package graphql.execution;

import com.google.common.collect.ImmutableList;
import graphql.ExecutionResult;
import graphql.ExecutionResultImpl;
import graphql.PublicApi;

import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.CompletableFuture;

Expand All @@ -26,7 +26,11 @@ public enum CompleteValueType {
private final CompletableFuture<Object> fieldValue;
private final List<FieldValueInfo> fieldValueInfos;

private FieldValueInfo(CompleteValueType completeValueType, CompletableFuture<Object> fieldValue, List<FieldValueInfo> fieldValueInfos) {
FieldValueInfo(CompleteValueType completeValueType, CompletableFuture<Object> fieldValue) {
this(completeValueType, fieldValue, ImmutableList.of());
}

FieldValueInfo(CompleteValueType completeValueType, CompletableFuture<Object> fieldValue, List<FieldValueInfo> fieldValueInfos) {
assertNotNull(fieldValueInfos, () -> "fieldValueInfos can't be null");
this.completeValueType = completeValueType;
this.fieldValue = fieldValue;
Expand All @@ -37,10 +41,11 @@ public CompleteValueType getCompleteValueType() {
return completeValueType;
}

@Deprecated(since="2023-09-11" )
@Deprecated(since = "2023-09-11")
public CompletableFuture<ExecutionResult> getFieldValue() {
return fieldValue.thenApply(fv -> ExecutionResultImpl.newExecutionResult().data(fv).build());
}

public CompletableFuture<Object> getFieldValueFuture() {
return fieldValue;
}
Expand All @@ -49,9 +54,6 @@ public List<FieldValueInfo> getFieldValueInfos() {
return fieldValueInfos;
}

public static Builder newFieldValueInfo(CompleteValueType completeValueType) {
return new Builder(completeValueType);
}

@Override
public String toString() {
Expand All @@ -62,34 +64,4 @@ public String toString() {
'}';
}

@SuppressWarnings("unused")
public static class Builder {
private CompleteValueType completeValueType;
private CompletableFuture<Object> fieldValueFuture;
private List<FieldValueInfo> listInfos = new ArrayList<>();

public Builder(CompleteValueType completeValueType) {
this.completeValueType = completeValueType;
}

public Builder completeValueType(CompleteValueType completeValueType) {
this.completeValueType = completeValueType;
return this;
}

public Builder fieldValue(CompletableFuture<Object> executionResultFuture) {
this.fieldValueFuture = executionResultFuture;
return this;
}

public Builder fieldValueInfos(List<FieldValueInfo> listInfos) {
assertNotNull(listInfos, () -> "fieldValueInfos can't be null");
this.listInfos = listInfos;
return this;
}

public FieldValueInfo build() {
return new FieldValueInfo(completeValueType, fieldValueFuture, listInfos);
}
}
}
Loading
0