fix: avatarurl needs prefixes too

This commit is contained in:
MiniDigger | Martin 2023-10-28 20:58:31 +02:00
parent 562ff1f0cb
commit d7afcc211c
2 changed files with 9 additions and 7 deletions

View File

@ -24,7 +24,7 @@ public class QueryBuilder {
return STR."""
SELECT
\{this.fields.stream().reduce((a, b) -> a + ",\n" + b).orElse("")}
\{this.fields.stream().sorted(Comparator.comparing(String::length)).reduce((a, b) -> a + ",\n" + b).orElse("")}
\{this.from}
@ -46,7 +46,7 @@ public class QueryBuilder {
// then run the resolvers
for (final var entry : this.resolver.entrySet()) {
outputMap.put(entry.getKey(), entry.getValue().apply(inputMap));
inputMap.put(entry.getKey(), entry.getValue().apply(inputMap));
}
// then clean it up into a tree

View File

@ -106,12 +106,14 @@ public class TestController {
@SchemaMapping(typeName = "Project", field = "avatarUrl")
public Object projectAvatarUrl(final DataFetchingEnvironment environment) {
final QueryBuilder queryBuilder = environment.getGraphQlContext().get("queryBuilder");
final String parentTable = PrefixUtil.getParentTable(environment.getExecutionStepInfo(), queryBuilder);
final String parentAlias = PrefixUtil.getParentAlias(environment.getExecutionStepInfo(), queryBuilder);
queryBuilder.fields.add("avatar.version AS ext_avatarversion");
queryBuilder.fields.add("project.id AS ext_projectid");
// TODO needs prefixes
queryBuilder.joins.add("JOIN avatars avatar ON avatar.type = 'project' AND avatar.subject = project.id::varchar");
queryBuilder.resolver.put(parentAlias + "avatarUrl", (r) -> this.fileService.getAvatarUrl(AvatarService.PROJECT, String.valueOf(r.get("ext_projectid")), (Integer) r.get("ext_avatarversion")));
final String avatarVersion = STR."ext_\{parentAlias.replace("_", "")}avatarversion";
final String projectId = STR."ext_\{parentAlias.replace("_", "")}projectid";
queryBuilder.fields.add(STR."\{parentAlias}avatar.version AS \{avatarVersion}");
queryBuilder.fields.add(STR."\{parentTable}id AS \{projectId}");
queryBuilder.joins.add(STR."JOIN avatars \{parentAlias}avatar ON \{parentAlias}avatar.type = 'project' AND \{parentAlias}avatar.subject = \{parentTable}id::varchar");
queryBuilder.resolver.put(parentAlias + "avatarUrl", (r) -> this.fileService.getAvatarUrl(AvatarService.PROJECT, String.valueOf(r.get(projectId)), (Integer) r.get(avatarVersion)));
return EMPTY;
}