Skip to content

Commit

Permalink
throw errors properly
Browse files Browse the repository at this point in the history
  • Loading branch information
matsudamper committed May 12, 2023
1 parent 45f0afd commit 2542b8f
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,14 @@ public String wrapApiReturnTypeIfRequired(MappingContext mappingContext,
// in case it is query/mutation, return type is list and apiReturnListType is set
if (mappingContext.getApiReturnListType().contains(MappingConfigConstants.API_RETURN_NAME_PLACEHOLDER)) {
Matcher matcher = JAVA_UTIL_LIST_ELEMENT_REGEX.matcher(computedTypeName);
matcher.find();
String listElement = matcher.group(1);
return mappingContext.getApiReturnListType().replace(
MappingConfigConstants.API_RETURN_NAME_PLACEHOLDER,
listElement);
if (matcher.find()) {
String listElement = matcher.group(1);
return mappingContext.getApiReturnListType().replace(
MappingConfigConstants.API_RETURN_NAME_PLACEHOLDER,
listElement);
} else {
throw new IllegalStateException();
}
} else {
return computedTypeName.replace(JAVA_UTIL_LIST, mappingContext.getApiReturnListType());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,18 @@ public String wrapApiReturnTypeIfRequired(MappingContext mappingContext,
boolean isNullable = computedTypeName.endsWith(KOTLIN_UTIL_NULLABLE);

Matcher matcher = KOTLIN_UTIL_LIST_ELEMENT_REGEX.matcher(computedTypeName);
matcher.find();
String listElement = matcher.group(1);
computedTypeName = mappingContext.getApiReturnListType()
.replace(MappingConfigConstants.API_RETURN_NAME_PLACEHOLDER, listElement);

if (isNullable) {
return computedTypeName + "?";
if (matcher.find()) {
String listElement = matcher.group(1);
computedTypeName = mappingContext.getApiReturnListType()
.replace(MappingConfigConstants.API_RETURN_NAME_PLACEHOLDER, listElement);

if (isNullable) {
return computedTypeName + "?";
} else {
return computedTypeName;
}
} else {
return computedTypeName;
throw new IllegalStateException();
}
} else {
return computedTypeName.replace(KOTLIN_UTIL_LIST, mappingContext.getApiReturnListType());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,11 +78,14 @@ public String wrapApiReturnTypeIfRequired(MappingContext mappingContext,
// in case it is query/mutation, return type is list and apiReturnListType is set
if (mappingContext.getApiReturnListType().contains(MappingConfigConstants.API_RETURN_NAME_PLACEHOLDER)) {
Matcher matcher = SCALA_UTIL_LIST_ELEMENT_REGEX.matcher(computedTypeName);
matcher.find();
String listElement = matcher.group(1);
return mappingContext.getApiReturnListType().replace(
MappingConfigConstants.API_RETURN_NAME_PLACEHOLDER,
listElement);
if (matcher.find()) {
String listElement = matcher.group(1);
return mappingContext.getApiReturnListType().replace(
MappingConfigConstants.API_RETURN_NAME_PLACEHOLDER,
listElement);
} else {
throw new IllegalStateException();
}
} else {
return computedTypeName.replace(SCALA_UTIL_LIST, mappingContext.getApiReturnListType());
}
Expand Down

0 comments on commit 2542b8f

Please sign in to comment.