Skip to content

Commit

Permalink
Merge branch 'master' into master
Browse files Browse the repository at this point in the history
  • Loading branch information
phillip-kruger authored Jan 29, 2021
2 parents 5a299b1 + 2eb2e1f commit 9c2fc6f
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,8 @@ String build() {
request.append(method.valueParameters().map(this::declare).collect(joining(", ", "(", ")")));
request.append(" { ");
request.append(method.getName());
if (method.hasValueParameters())
request.append(method.valueParameters()
.filter(ParameterInfo::isNotNestedValueParameter)
if (method.hasRootParameters())
request.append(method.rootParameters()
.map(this::bind)
.collect(joining(", ", "(", ")")));
request.append(fields(method.getReturnType()));
Expand Down Expand Up @@ -75,9 +74,8 @@ private String field(FieldInfo field) {
StringBuilder expression = new StringBuilder(field.getName());
if (!type.isScalar() && (!type.isCollection() || !type.getItemType().isScalar())) {
String path = nestedExpressionPrefix() + field.getName();
if (method.valueParameters().anyMatch(ParameterInfo::isNestedParameter))
expression.append(method.valueParameters()
.filter(ParameterInfo::isNestedParameter)
if (method.hasNestedParameters())
expression.append(method.nestedParameters()
.filter(parameterInfo -> parameterInfo.getNestedParameterName().equals(path))
.map(this::bind)
.collect(joining(", ", "(", ")")));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,33 @@ public TypeInfo getReturnType() {
}

public boolean hasValueParameters() {
return valueParameters().count() > 0;
return valueParameters().findAny().isPresent();
}

public Stream<ParameterInfo> valueParameters() {
return parameters().filter(ParameterInfo::isValueParameter);
public boolean hasRootParameters() {
return rootParameters().findAny().isPresent();
}

public boolean hasNestedParameters() {
return nestedParameters().findAny().isPresent();
}

public Stream<ParameterInfo> headerParameters() {
return parameters().filter(ParameterInfo::isHeaderParameter);
}

public Stream<ParameterInfo> valueParameters() {
return parameters().filter(ParameterInfo::isValueParameter);
}

public Stream<ParameterInfo> rootParameters() {
return parameters().filter(ParameterInfo::isRootParameter);
}

public Stream<ParameterInfo> nestedParameters() {
return parameters().filter(ParameterInfo::isNestedParameter);
}

private Stream<ParameterInfo> parameters() {
Parameter[] parameters = method.getParameters();
return IntStream.range(0, parameters.length)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,11 +117,11 @@ public boolean isHeaderParameter() {
}

public boolean isValueParameter() {
return !isHeaderParameter();
return isRootParameter() || isNestedParameter();
}

public boolean isNotNestedValueParameter() {
return !isNestedParameter();
public boolean isRootParameter() {
return !isHeaderParameter() && !isNestedParameter();
}

public boolean isNestedParameter() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ void shouldCallDeeplyNestedParameterQuery() {
Universe universe = api.universeWithTeam("endgame", 32, 3);

then(fixture.query())
.isEqualTo("query universeWithTeam($teamName: String, $offset: Int, $limit: Int) { universeWithTeam() " +
.isEqualTo("query universeWithTeam($teamName: String, $offset: Int, $limit: Int) { universeWithTeam " +
"{name teams(teamName: $teamName) {headQuarter members(offset: $offset, limit: $limit) {name}}} }");
then(fixture.variables()).isEqualTo("{'teamName':'endgame','offset':32,'limit':3}");
then(universe.name).isEqualTo("Marvel");
Expand Down

0 comments on commit 9c2fc6f

Please sign in to comment.