Skip to content

Commit

Permalink
Remove dead code from GraphQLEntityProjectionMaker.java (#1977)
Browse files Browse the repository at this point in the history
* Fix for GraphQLEntityProjectionMaker.java

* Fix for GraphQLEntityProjectionMaker.java
  • Loading branch information
moizarafat committed Mar 31, 2021
1 parent e51178e commit e72169c
Showing 1 changed file with 9 additions and 50 deletions.
Expand Up @@ -358,7 +358,15 @@ private void addArgument(Argument argument, EntityProjectionBuilder projectionBu
&& !(ModelBuilder.ARGUMENT_IDS.equals(argumentName))
&& !(ModelBuilder.ARGUMENT_DATA.equals(argumentName))
&& !isEntityArgument(argumentName, entityDictionary, projectionBuilder.getType())) {
addAttributeArgument(argument, projectionBuilder);
Type<?> entityType = projectionBuilder.getType();
Type<?> attributeType = entityDictionary.getType(entityType, argumentName);
if (attributeType == null) {
throw new InvalidEntityBodyException(
String.format("Invalid attribute field/alias for argument: {%s}.{%s}",
entityType,
argumentName)
);
}
}
}

Expand Down Expand Up @@ -532,55 +540,6 @@ private FilterExpression buildFilter(EntityProjectionBuilder builder, String typ
}
}

/**
* Add argument for a field/relationship of an entity.
*
* @param argument an argument which name should match a field name/alias
* @param projectionBuilder projection that is being built
*/
private void addAttributeArgument(Argument argument, EntityProjectionBuilder projectionBuilder) {
String argumentName = argument.getName();
Type<?> entityType = projectionBuilder.getType();

Attribute existingAttribute = projectionBuilder.getAttributeByAlias(argumentName);

com.yahoo.elide.core.request.Argument elideArgument = com.yahoo.elide.core.request.Argument.builder()
.name(argumentName)
.value(variableResolver.resolveValue(argument.getValue()))
.build();

if (existingAttribute != null) {
// add a new argument to the existing attribute
Attribute toAdd = Attribute.builder()
.type(existingAttribute.getType())
.name(existingAttribute.getName())
.alias(existingAttribute.getAlias())
.argument(elideArgument)
.build();

projectionBuilder.attribute(toAdd);
} else {
Type<?> attributeType = entityDictionary.getType(entityType, argumentName);
if (attributeType == null) {
throw new InvalidEntityBodyException(
String.format("Invalid attribute field/alias for argument: {%s}.{%s}",
entityType,
argumentName)
);
}

// create a new attribute if this attribute doesn't exist in the projection
Attribute toAdd = Attribute.builder()
.type(attributeType)
.name(argumentName)
.alias(argumentName)
.argument(elideArgument)
.build();

projectionBuilder.attribute(toAdd);
}
}

private List<com.yahoo.elide.core.request.Argument> getArguments(Field attributeField,
Set<ArgumentType> availableArguments) {
List<com.yahoo.elide.core.request.Argument> arguments = new ArrayList<>();
Expand Down

0 comments on commit e72169c

Please sign in to comment.