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
33 changes: 28 additions & 5 deletions src/main/java/graphql/execution/ExecutionStrategy.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,9 @@ protected ExecutionStrategy(DataFetcherExceptionHandler dataFetcherExceptionHand
*
* @param executionContext contains the top level execution parameters
* @param parameters contains the parameters holding the fields to be executed and source object
*
* @return a promise to an {@link ExecutionResult}
*
* @throws NonNullableFieldWasNullException in the future if a non null field resolves to a null value
*/
public abstract CompletableFuture<ExecutionResult> execute(ExecutionContext executionContext, ExecutionStrategyParameters parameters) throws NonNullableFieldWasNullException;
Expand All @@ -170,7 +172,9 @@ protected ExecutionStrategy(DataFetcherExceptionHandler dataFetcherExceptionHand
*
* @param executionContext contains the top level execution parameters
* @param parameters contains the parameters holding the fields to be executed and source object
*
* @return a promise to an {@link ExecutionResult}
*
* @throws NonNullableFieldWasNullException in the future if a non null field resolves to a null value
*/
protected CompletableFuture<ExecutionResult> resolveField(ExecutionContext executionContext, ExecutionStrategyParameters parameters) {
Expand All @@ -188,7 +192,9 @@ protected CompletableFuture<ExecutionResult> resolveField(ExecutionContext execu
*
* @param executionContext contains the top level execution parameters
* @param parameters contains the parameters holding the fields to be executed and source object
*
* @return a promise to a {@link FieldValueInfo}
*
* @throws NonNullableFieldWasNullException in the {@link FieldValueInfo#getFieldValue()} future if a non null field resolves to a null value
*/
protected CompletableFuture<FieldValueInfo> resolveFieldWithInfo(ExecutionContext executionContext, ExecutionStrategyParameters parameters) {
Expand Down Expand Up @@ -220,7 +226,9 @@ protected CompletableFuture<FieldValueInfo> resolveFieldWithInfo(ExecutionContex
*
* @param executionContext contains the top level execution parameters
* @param parameters contains the parameters holding the fields to be executed and source object
*
* @return a promise to a fetched object
*
* @throws NonNullableFieldWasNullException in the future if a non null field resolves to a null value
*/
protected CompletableFuture<FetchedValue> fetchField(ExecutionContext executionContext, ExecutionStrategyParameters parameters) {
Expand All @@ -239,7 +247,7 @@ protected CompletableFuture<FetchedValue> fetchField(ExecutionContext executionC
Supplier<NormalizedField> normalizedFieldSupplier = getNormalizedField(executionContext, parameters, executionStepInfo);

// DataFetchingFieldSelectionSet and QueryDirectives is a supplier of sorts - eg a lazy pattern
DataFetchingFieldSelectionSet fieldCollector = DataFetchingFieldSelectionSetImpl.newCollector(fieldType, normalizedFieldSupplier);
DataFetchingFieldSelectionSet fieldCollector = DataFetchingFieldSelectionSetImpl.newCollector(executionContext.getGraphQLSchema(), fieldType, normalizedFieldSupplier);
QueryDirectives queryDirectives = new QueryDirectivesImpl(field, executionContext.getGraphQLSchema(), executionContext.getVariables());


Expand Down Expand Up @@ -297,8 +305,8 @@ protected Supplier<NormalizedField> getNormalizedField(ExecutionContext executio
}

protected FetchedValue unboxPossibleDataFetcherResult(ExecutionContext executionContext,
ExecutionStrategyParameters parameters,
Object result) {
ExecutionStrategyParameters parameters,
Object result) {

if (result instanceof DataFetcherResult) {
//noinspection unchecked
Expand Down Expand Up @@ -326,8 +334,8 @@ protected FetchedValue unboxPossibleDataFetcherResult(ExecutionContext execution
}

protected void handleFetchingException(ExecutionContext executionContext,
DataFetchingEnvironment environment,
Throwable e) {
DataFetchingEnvironment environment,
Throwable e) {
DataFetcherExceptionHandlerParameters handlerParameters = DataFetcherExceptionHandlerParameters.newExceptionParameters()
.dataFetchingEnvironment(environment)
.exception(e)
Expand Down Expand Up @@ -359,7 +367,9 @@ protected void handleFetchingException(ExecutionContext executionContext,
* @param executionContext contains the top level execution parameters
* @param parameters contains the parameters holding the fields to be executed and source object
* @param fetchedValue the fetched raw value
*
* @return a {@link FieldValueInfo}
*
* @throws NonNullableFieldWasNullException in the {@link FieldValueInfo#getFieldValue()} future if a non null field resolves to a null value
*/
protected FieldValueInfo completeField(ExecutionContext executionContext, ExecutionStrategyParameters parameters, FetchedValue fetchedValue) {
Expand Down Expand Up @@ -407,7 +417,9 @@ protected FieldValueInfo completeField(ExecutionContext executionContext, Execut
*
* @param executionContext contains the top level execution parameters
* @param parameters contains the parameters holding the fields to be executed and source object
*
* @return a {@link FieldValueInfo}
*
* @throws NonNullableFieldWasNullException if a non null field resolves to a null value
*/
protected FieldValueInfo completeValue(ExecutionContext executionContext, ExecutionStrategyParameters parameters) throws NonNullableFieldWasNullException {
Expand Down Expand Up @@ -468,6 +480,7 @@ protected CompletableFuture<ExecutionResult> completeValueForNull(ExecutionConte
* @param executionContext contains the top level execution parameters
* @param parameters contains the parameters holding the fields to be executed and source object
* @param result the result to complete, raw result
*
* @return a {@link FieldValueInfo}
*/
protected FieldValueInfo completeValueForList(ExecutionContext executionContext, ExecutionStrategyParameters parameters, Object result) {
Expand All @@ -490,6 +503,7 @@ protected FieldValueInfo completeValueForList(ExecutionContext executionContext,
* @param executionContext contains the top level execution parameters
* @param parameters contains the parameters holding the fields to be executed and source object
* @param iterableValues the values to complete, can't be null
*
* @return a {@link FieldValueInfo}
*/
protected FieldValueInfo completeValueForList(ExecutionContext executionContext, ExecutionStrategyParameters parameters, Iterable<Object> iterableValues) {
Expand Down Expand Up @@ -563,6 +577,7 @@ protected FieldValueInfo completeValueForList(ExecutionContext executionContext,
* @param parameters contains the parameters holding the fields to be executed and source object
* @param scalarType the type of the scalar
* @param result the result to be coerced
*
* @return a promise to an {@link ExecutionResult}
*/
protected CompletableFuture<ExecutionResult> completeValueForScalar(ExecutionContext executionContext, ExecutionStrategyParameters parameters, GraphQLScalarType scalarType, Object result) {
Expand Down Expand Up @@ -593,6 +608,7 @@ protected CompletableFuture<ExecutionResult> completeValueForScalar(ExecutionCon
* @param parameters contains the parameters holding the fields to be executed and source object
* @param enumType the type of the enum
* @param result the result to be coerced
*
* @return a promise to an {@link ExecutionResult}
*/
protected CompletableFuture<ExecutionResult> completeValueForEnum(ExecutionContext executionContext, ExecutionStrategyParameters parameters, GraphQLEnumType enumType, Object result) {
Expand All @@ -617,6 +633,7 @@ protected CompletableFuture<ExecutionResult> completeValueForEnum(ExecutionConte
* @param parameters contains the parameters holding the fields to be executed and source object
* @param resolvedObjectType the resolved object type
* @param result the result to be coerced
*
* @return a promise to an {@link ExecutionResult}
*/
protected CompletableFuture<ExecutionResult> completeValueForObject(ExecutionContext executionContext, ExecutionStrategyParameters parameters, GraphQLObjectType resolvedObjectType, Object result) {
Expand Down Expand Up @@ -661,7 +678,9 @@ private Object handleCoercionProblem(ExecutionContext context, ExecutionStrategy
* Converts an object that is known to should be an Iterable into one
*
* @param result the result object
*
* @return an Iterable from that object
*
* @throws java.lang.ClassCastException if its not an Iterable
*/
protected Iterable<Object> toIterable(Object result) {
Expand Down Expand Up @@ -697,6 +716,7 @@ private void handleTypeMismatchProblem(ExecutionContext context, ExecutionStrate
* @param executionContext contains the top level execution parameters
* @param parameters contains the parameters holding the fields to be executed and source object
* @param field the field to find the definition of
*
* @return a {@link GraphQLFieldDefinition}
*/
protected GraphQLFieldDefinition getFieldDef(ExecutionContext executionContext, ExecutionStrategyParameters parameters, Field field) {
Expand All @@ -710,6 +730,7 @@ protected GraphQLFieldDefinition getFieldDef(ExecutionContext executionContext,
* @param schema the schema in play
* @param parentType the parent type of the field
* @param field the field to find the definition of
*
* @return a {@link GraphQLFieldDefinition}
*/
protected GraphQLFieldDefinition getFieldDef(GraphQLSchema schema, GraphQLObjectType parentType, Field field) {
Expand All @@ -727,6 +748,7 @@ protected GraphQLFieldDefinition getFieldDef(GraphQLSchema schema, GraphQLObject
*
* @param e this indicates that a null value was returned for a non null field, which needs to cause the parent field
* to become null OR continue on as an exception
*
* @throws NonNullableFieldWasNullException if a non null field resolves to a null value
*/
protected void assertNonNullFieldPrecondition(NonNullableFieldWasNullException e) throws NonNullableFieldWasNullException {
Expand Down Expand Up @@ -774,6 +796,7 @@ protected ExecutionResult handleNonNullException(ExecutionContext executionConte
* @param parameters contains the parameters holding the fields to be executed and source object
* @param fieldDefinition the field definition to build type info for
* @param fieldContainer the field container
*
* @return a new type info
*/
protected ExecutionStepInfo createExecutionStepInfo(ExecutionContext executionContext,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ private CompletableFuture<FetchedValues> fetchData(ExecutionContext executionCon
Supplier<NormalizedField> normalizedFieldSupplier = getNormalizedField(executionContext, parameters, parameters::getExecutionStepInfo);

GraphQLOutputType fieldType = fieldDef.getType();
DataFetchingFieldSelectionSet fieldCollector = DataFetchingFieldSelectionSetImpl.newCollector(fieldType, normalizedFieldSupplier);
DataFetchingFieldSelectionSet fieldCollector = DataFetchingFieldSelectionSetImpl.newCollector(executionContext.getGraphQLSchema(), fieldType, normalizedFieldSupplier);

DataFetchingEnvironment environment = newDataFetchingEnvironment(executionContext)
.source(node.getSources())
Comment thread
andimarek marked this conversation as resolved.
Resolved
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/graphql/execution/nextgen/ValueFetcher.java
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ public CompletableFuture<FetchedValue> fetchValue(ExecutionContext executionCont

Supplier<NormalizedQueryTree> normalizedQuery = executionContext.getNormalizedQueryTree();
Supplier<NormalizedField> normalisedField = () -> normalizedQuery.get().getNormalizedField(sameFields, executionInfo.getObjectType(), executionInfo.getPath());
DataFetchingFieldSelectionSet selectionSet = DataFetchingFieldSelectionSetImpl.newCollector(fieldType, normalisedField);
DataFetchingFieldSelectionSet selectionSet = DataFetchingFieldSelectionSetImpl.newCollector(executionContext.getGraphQLSchema(), fieldType, normalisedField);

DataFetchingEnvironment environment = newDataFetchingEnvironment(executionContext)
.source(source)
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/graphql/introspection/Introspection.java
Original file line number Diff line number Diff line change
Expand Up @@ -649,7 +649,7 @@ public static GraphQLFieldDefinition getFieldDef(GraphQLSchema schema, GraphQLCo
assertTrue(parentType instanceof GraphQLFieldsContainer, () -> String.format("should not happen : parent type must be an object or interface %s", parentType));
GraphQLFieldsContainer fieldsContainer = (GraphQLFieldsContainer) parentType;
GraphQLFieldDefinition fieldDefinition = schema.getCodeRegistry().getFieldVisibility().getFieldDefinition(fieldsContainer, fieldName);
Assert.assertTrue(fieldDefinition != null, () -> String.format("Unknown field '%s'", fieldName));
assertTrue(fieldDefinition != null, () -> String.format("Unknown field '%s' for type %s", fieldName, fieldsContainer.getName()));
return fieldDefinition;
}
}
45 changes: 37 additions & 8 deletions src/main/java/graphql/language/AstComparator.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,25 +9,54 @@
@Internal
public class AstComparator {

private AstComparator() {

public boolean isEqual(Node node1, Node node2) {
if (null == node1) return null == node2;
if (!node1.isEqualTo(node2)) return false;
}

public static boolean sameValue(Value value1, Value value2) {
if (value1 == null && value2 == null) {
return true;
}
if (value1 == null) {
return false;
}
if (value2 == null) {
return false;
}
return isEqual(value1, value2);
}


public static boolean isEqual(Node node1, Node node2) {
if (null == node1) {
return null == node2;
}
if (!node1.isEqualTo(node2)) {
return false;
}
List<Node> childs1 = node1.getChildren();
List<Node> childs2 = node2.getChildren();
if (childs1.size() != childs2.size()) return false;
if (childs1.size() != childs2.size()) {
return false;
}
for (int i = 0; i < childs1.size(); i++) {
if (!isEqual(childs1.get(i), childs2.get(i))) return false;
if (!isEqual(childs1.get(i), childs2.get(i))) {
return false;
}
}
return true;
}

public boolean isEqual(List<Node> nodes1, List<Node> nodes2) {
if (nodes1.size() != nodes2.size()) return false;
public static boolean isEqual(List<Node> nodes1, List<Node> nodes2) {
if (nodes1.size() != nodes2.size()) {
return false;
}
Iterator<Node> iter1 = nodes1.iterator();
Iterator<Node> iter2 = nodes2.iterator();
while (iter1.hasNext()) {
if (!isEqual(iter1.next(), iter2.next())) return false;
if (!isEqual(iter1.next(), iter2.next())) {
return false;
}
}
return true;
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/graphql/language/Selection.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,5 @@
import graphql.PublicApi;

@PublicApi
public interface Selection<T extends Selection> extends Node<T> {
public interface Selection<T extends Selection<T>> extends Node<T> {
}
Loading