Skip to content

Commit feb8b3e

Browse files
committed
feat: add query method to get a build by number
1 parent 81433b9 commit feb8b3e

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

src/main/java/io/papermc/fill/controller/GraphQueryController.java

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
import io.papermc.fill.database.ProjectRepository;
2424
import io.papermc.fill.database.VersionEntity;
2525
import io.papermc.fill.database.VersionRepository;
26+
import io.papermc.fill.exception.BuildNotFoundException;
2627
import io.papermc.fill.exception.FamilyNotFoundException;
2728
import io.papermc.fill.exception.ProjectNotFoundException;
2829
import io.papermc.fill.graphql.BuildFilters;
@@ -54,6 +55,7 @@
5455
import java.util.Comparator;
5556
import java.util.List;
5657
import java.util.Optional;
58+
import java.util.function.Function;
5759
import java.util.stream.Stream;
5860
import org.jspecify.annotations.NullMarked;
5961
import org.jspecify.annotations.Nullable;
@@ -266,10 +268,7 @@ public Connection<BuildWithDownloads<DownloadWithUrl>> mapVersionBuilds(
266268
builds = this.builds.findAllByVersion(version, pageable);
267269
}
268270
return BUILD_PAGINATOR.paginate(
269-
builds.map(build -> new BuildWithDownloadsImpl<>(build, Downloads.map(build.downloads(), download -> {
270-
final URI url = this.storage.getDownloadUrl(project, version, build, download);
271-
return download.withUrl(url);
272-
}))),
271+
builds.map(this.mapBuild(project, version)),
273272
orderBy != null ? orderBy.direction() : null,
274273
after,
275274
before,
@@ -278,6 +277,18 @@ public Connection<BuildWithDownloads<DownloadWithUrl>> mapVersionBuilds(
278277
);
279278
}
280279

280+
@SchemaMapping(typeName = "Version", field = "build")
281+
public @Nullable BuildWithDownloads<DownloadWithUrl> mapProjectVersion(
282+
final VersionEntity version,
283+
@Argument
284+
final int number
285+
) {
286+
final ProjectEntity project = this.projects.findById(version.project()).orElseThrow(ProjectNotFoundException::new);
287+
return this.builds.findByVersionAndNumber(version._id(), number)
288+
.map(this.mapBuild(project, version))
289+
.orElseThrow(BuildNotFoundException::new);
290+
}
291+
281292
@SchemaMapping(typeName = "Build", field = "id")
282293
public String mapBuildId(final BuildWithDownloads<DownloadWithUrl> build) {
283294
return build.id();
@@ -316,4 +327,11 @@ public Collection<DownloadWithUrl> mapBuildDownloads(final BuildWithDownloads<Do
316327
) {
317328
return build.getDownloadByKey(key);
318329
}
330+
331+
private Function<BuildEntity, BuildWithDownloads<DownloadWithUrl>> mapBuild(final Project project, final Version version) {
332+
return build -> new BuildWithDownloadsImpl<>(build, Downloads.map(build.downloads(), download -> {
333+
final URI url = this.storage.getDownloadUrl(project, version, build, download);
334+
return download.withUrl(url);
335+
}));
336+
}
319337
}

src/main/resources/graphql/schema.graphqls

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,10 @@ type Version implements Node {
145145
"""
146146
last: Int
147147
): BuildConnection
148+
149+
build(
150+
number: Int!
151+
): Build
148152
}
149153

150154
input VersionFilters {

0 commit comments

Comments
 (0)