Skip to content

Commit

Permalink
Revert "Kaqqao parsed directive arguments (#1289)"
Browse files Browse the repository at this point in the history
This reverts commit 40027fc
  • Loading branch information
bbakerman committed Nov 28, 2018
1 parent 4dc1e0c commit b808a72
Show file tree
Hide file tree
Showing 13 changed files with 15 additions and 382 deletions.
9 changes: 0 additions & 9 deletions src/main/java/graphql/DirectivesUtil.java
Expand Up @@ -23,13 +23,4 @@ public static Optional<GraphQLArgument> directiveWithArg(List<GraphQLDirective>
}
return Optional.ofNullable(argument);
}

public static Optional<GraphQLArgument> directiveWithArg(Map<String,GraphQLDirective> directives, String directiveName, String argumentName) {
GraphQLDirective directive =directives.get(directiveName);
GraphQLArgument argument = null;
if (directive != null) {
argument = directive.getArgument(argumentName);
}
return Optional.ofNullable(argument);
}
}
61 changes: 0 additions & 61 deletions src/main/java/graphql/execution/DirectivesResolver.java

This file was deleted.

49 changes: 4 additions & 45 deletions src/main/java/graphql/execution/ExecutionStepInfo.java
@@ -1,10 +1,7 @@
package graphql.execution;

import graphql.DirectivesUtil;
import graphql.PublicApi;
import graphql.language.Field;
import graphql.schema.GraphQLArgument;
import graphql.schema.GraphQLDirective;
import graphql.schema.GraphQLFieldDefinition;
import graphql.schema.GraphQLInterfaceType;
import graphql.schema.GraphQLNonNull;
Expand Down Expand Up @@ -34,18 +31,16 @@ public class ExecutionStepInfo {
private final GraphQLFieldDefinition fieldDefinition;
private final ExecutionPath path;
private final Map<String, Object> arguments;
private final Map<String, GraphQLDirective> directives;
private final ExecutionStepInfo parent;

private ExecutionStepInfo(GraphQLType type, GraphQLFieldDefinition fieldDefinition, Field field, ExecutionPath path, ExecutionStepInfo parent, Map<String, Object> arguments, Map<String, GraphQLDirective> directives) {
private ExecutionStepInfo(GraphQLType type, GraphQLFieldDefinition fieldDefinition, Field field, ExecutionPath path, ExecutionStepInfo parent, Map<String, Object> arguments) {
this.fieldDefinition = fieldDefinition;
this.field = field;
this.path = path;
this.parent = parent;
this.type = assertNotNull(type, "you must provide a graphql type");
this.arguments = arguments;

this.directives = directives;
}

/**
Expand Down Expand Up @@ -126,36 +121,6 @@ public <T> T getArgument(String name) {
return (T) arguments.get(name);
}

/**
* @return the resolved directives that have been passed to this field
*/
public Map<String, GraphQLDirective> getDirectives() {
return new LinkedHashMap<>(directives);
}

/**
* Returns a named directive or null if it is not present
*
* @param directiveName the name of the directive
*
* @return a named directive or null if it is not present
*/
public GraphQLDirective getDirective(String directiveName) {
return directives.get(directiveName);
}

/**
* Returns a named argument for a named directive or null if there is not one present
*
* @param directiveName the name of the directive
* @param argumentName the name of the argument
*
* @return a named argument for a named directive or null if there is not one present
*/
public GraphQLArgument getDirectiveArgument(String directiveName, String argumentName) {
return DirectivesUtil.directiveWithArg(directives, directiveName, argumentName).orElse(null);
}

/**
* @return the parent type information
*/
Expand Down Expand Up @@ -183,9 +148,9 @@ public boolean hasParent() {
public ExecutionStepInfo changeTypeWithPreservedNonNull(GraphQLType newType) {
assertTrue(!GraphQLTypeUtil.isNonNull(newType), "newType can't be non null");
if (isNonNullType()) {
return new ExecutionStepInfo(GraphQLNonNull.nonNull(newType), fieldDefinition, field, path, this.parent, arguments, directives);
return new ExecutionStepInfo(GraphQLNonNull.nonNull(newType), fieldDefinition, field, path, this.parent, arguments);
} else {
return new ExecutionStepInfo(newType, fieldDefinition, field, path, this.parent, arguments, directives);
return new ExecutionStepInfo(newType, fieldDefinition, field, path, this.parent, arguments);
}
}

Expand Down Expand Up @@ -222,7 +187,6 @@ public static class Builder {
Field field;
ExecutionPath executionPath;
Map<String, Object> arguments = new LinkedHashMap<>();
Map<String, GraphQLDirective> directives = new LinkedHashMap<>();

/**
* @see ExecutionStepInfo#newExecutionStepInfo()
Expand Down Expand Up @@ -260,13 +224,8 @@ public Builder arguments(Map<String, Object> arguments) {
return this;
}

public Builder directives(Map<String, GraphQLDirective> directives) {
this.directives = new LinkedHashMap<>(directives == null ? Collections.emptyMap() : directives);
return this;
}

public ExecutionStepInfo build() {
return new ExecutionStepInfo(type, fieldDefinition, field, executionPath, parentInfo, arguments, directives);
return new ExecutionStepInfo(type, fieldDefinition, field, executionPath, parentInfo, arguments);
}
}
}
21 changes: 3 additions & 18 deletions src/main/java/graphql/execution/ExecutionStrategy.java
Expand Up @@ -10,7 +10,6 @@
import graphql.TypeMismatchError;
import graphql.TypeResolutionEnvironment;
import graphql.UnresolvedTypeError;
import graphql.VisibleForTesting;
import graphql.execution.instrumentation.Instrumentation;
import graphql.execution.instrumentation.InstrumentationContext;
import graphql.execution.instrumentation.parameters.InstrumentationFieldCompleteParameters;
Expand All @@ -24,7 +23,6 @@
import graphql.schema.DataFetchingEnvironment;
import graphql.schema.DataFetchingFieldSelectionSet;
import graphql.schema.DataFetchingFieldSelectionSetImpl;
import graphql.schema.GraphQLDirective;
import graphql.schema.GraphQLEnumType;
import graphql.schema.GraphQLFieldDefinition;
import graphql.schema.GraphQLInterfaceType;
Expand Down Expand Up @@ -123,12 +121,8 @@ public abstract class ExecutionStrategy {

private static final Logger log = LoggerFactory.getLogger(ExecutionStrategy.class);

@VisibleForTesting
protected ValuesResolver valuesResolver = new ValuesResolver();
@VisibleForTesting
protected FieldCollector fieldCollector = new FieldCollector();
@VisibleForTesting
protected DirectivesResolver directivesResolver = new DirectivesResolver(valuesResolver);
protected final ValuesResolver valuesResolver = new ValuesResolver();
protected final FieldCollector fieldCollector = new FieldCollector();

protected final DataFetcherExceptionHandler dataFetcherExceptionHandler;

Expand Down Expand Up @@ -237,19 +231,15 @@ protected CompletableFuture<Object> fetchField(ExecutionContext executionContext
GraphQLFieldDefinition fieldDef = getFieldDef(executionContext.getGraphQLSchema(), parentType, field);

GraphqlFieldVisibility fieldVisibility = executionContext.getGraphQLSchema().getFieldVisibility();

Map<String, Object> argumentValues = valuesResolver.getArgumentValues(fieldVisibility, fieldDef.getArguments(), field.getArguments(), executionContext.getVariables());

Map<String, GraphQLDirective> directivesMap = directivesResolver.getFieldDirectives(field, executionContext.getGraphQLSchema(), executionContext.getVariables());

GraphQLOutputType fieldType = fieldDef.getType();
DataFetchingFieldSelectionSet fieldCollector = DataFetchingFieldSelectionSetImpl.newCollector(executionContext, fieldType, parameters.getField());
ExecutionStepInfo executionStepInfo = createExecutionStepInfo(executionContext, parameters, fieldDef);

DataFetchingEnvironment environment = newDataFetchingEnvironment(executionContext)
.source(parameters.getSource())
.arguments(argumentValues)
.directives(directivesMap)
.fieldDefinition(fieldDef)
.fields(parameters.getField())
.fieldType(fieldType)
Expand Down Expand Up @@ -905,20 +895,15 @@ protected ExecutionStepInfo createExecutionStepInfo(ExecutionContext executionCo
GraphqlFieldVisibility fieldVisibility = executionContext.getGraphQLSchema().getFieldVisibility();
Map<String, Object> argumentValues = valuesResolver.getArgumentValues(fieldVisibility, fieldDefinition.getArguments(), fieldArgs, executionContext.getVariables());

Map<String, GraphQLDirective> directivesMap = Collections.emptyMap();
if (field != null) {
directivesMap = directivesResolver.getFieldDirectives(field, executionContext.getGraphQLSchema(), executionContext.getVariables());
}

return newExecutionStepInfo()
.type(fieldType)
.fieldDefinition(fieldDefinition)
.field(field)
.path(parameters.getPath())
.parentInfo(parameters.getExecutionStepInfo())
.arguments(argumentValues)
.directives(directivesMap)
.build();

}


Expand Down
Expand Up @@ -8,7 +8,6 @@
import graphql.execution.Async;
import graphql.execution.DataFetcherExceptionHandler;
import graphql.execution.DataFetcherExceptionHandlerParameters;
import graphql.execution.DirectivesResolver;
import graphql.execution.ExecutionContext;
import graphql.execution.ExecutionPath;
import graphql.execution.ExecutionStepInfo;
Expand All @@ -28,7 +27,6 @@
import graphql.schema.DataFetchingEnvironment;
import graphql.schema.DataFetchingFieldSelectionSet;
import graphql.schema.DataFetchingFieldSelectionSetImpl;
import graphql.schema.GraphQLDirective;
import graphql.schema.GraphQLEnumType;
import graphql.schema.GraphQLFieldDefinition;
import graphql.schema.GraphQLInterfaceType;
Expand Down Expand Up @@ -239,23 +237,19 @@ private CompletableFuture<FetchedValues> fetchData(ExecutionContext executionCon
GraphQLFieldDefinition fieldDef) {
GraphQLObjectType parentType = node.getType();
List<Field> fields = node.getFields().get(fieldName);
Field field = fields.get(0);
List<MapOrList> parentResults = node.getParentResults();

GraphqlFieldVisibility fieldVisibility = executionContext.getGraphQLSchema().getFieldVisibility();
Map<String, Object> argumentValues = valuesResolver.getArgumentValues(
fieldVisibility,
fieldDef.getArguments(), fields.get(0).getArguments(), executionContext.getVariables());

Map<String, GraphQLDirective> directivesMap = directivesResolver.getFieldDirectives(field, executionContext.getGraphQLSchema(), executionContext.getVariables());

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

DataFetchingEnvironment environment = newDataFetchingEnvironment(executionContext)
.source(node.getSources())
.arguments(argumentValues)
.directives(directivesMap)
.fieldDefinition(fieldDef)
.fields(fields)
.fieldType(fieldDef.getType())
Expand Down
26 changes: 0 additions & 26 deletions src/main/java/graphql/schema/DataFetchingEnvironment.java
Expand Up @@ -56,32 +56,6 @@ public interface DataFetchingEnvironment {
*/
<T> T getArgument(String name);

/**
* Returns a map of the directives that were present on the field
*
* @return a map of the directives that were present on the field
*/
Map<String, GraphQLDirective> getDirectives();

/**
* Returns a named directive that might present on the field
*
* @param directiveName the name of the directive to retrieve
*
* @return a named directive that might present on the field or null if not present
*/
GraphQLDirective getDirective(String directiveName);

/**
* Returns a named argument of a named directive that might present on the field
*
* @param directiveName the name of the directive to retrieve
* @param argumentName the name of the directive argument
*
* @return a named argument that might present on a directive on the field or null if not present
*/
GraphQLArgument getDirectiveArgument(String directiveName, String argumentName);

/**
* Returns a context argument that is set up when the {@link graphql.GraphQL#execute} method
* is invoked.
Expand Down
Expand Up @@ -29,7 +29,6 @@ public static DataFetchingEnvironmentBuilder newDataFetchingEnvironment(DataFetc
return new DataFetchingEnvironmentBuilder()
.source(environment.getSource())
.arguments(environment.getArguments())
.directives(environment.getDirectives())
.context(environment.getContext())
.root(environment.getRoot())
.fieldDefinition(environment.getFieldDefinition())
Expand Down Expand Up @@ -59,7 +58,6 @@ public static DataFetchingEnvironmentBuilder newDataFetchingEnvironment(Executio

private Object source;
private Map<String, Object> arguments = Collections.emptyMap();
private Map<String, GraphQLDirective> directives = Collections.emptyMap();
private Object context;
private Object root;
private GraphQLFieldDefinition fieldDefinition;
Expand All @@ -83,11 +81,6 @@ public DataFetchingEnvironmentBuilder arguments(Map<String, Object> arguments) {
return this;
}

public DataFetchingEnvironmentBuilder directives(Map<String, GraphQLDirective> directives) {
this.directives = directives;
return this;
}

public DataFetchingEnvironmentBuilder context(Object context) {
this.context = context;
return this;
Expand Down Expand Up @@ -149,7 +142,7 @@ public DataFetchingEnvironmentBuilder executionContext(ExecutionContext executio
}

public DataFetchingEnvironment build() {
return new DataFetchingEnvironmentImpl(source, arguments, directives, context, root,
return new DataFetchingEnvironmentImpl(source, arguments, context, root,
fieldDefinition, fields, fieldType, parentType, graphQLSchema, fragmentsByName, executionId, selectionSet,
executionStepInfo,
executionContext);
Expand Down

0 comments on commit b808a72

Please sign in to comment.