From bc260f0f538d3a579a2e81d3f227bde004f12d82 Mon Sep 17 00:00:00 2001 From: William Allen Date: Thu, 25 Jun 2026 16:00:15 -0400 Subject: [PATCH] Add `build` relationship to `Test` GraphQL type Adding a `build` relationship to the `Test` type allows users to filter the list of tests added in #3808 by build attributes. --- graphql/schema.graphql | 2 + tests/Feature/GraphQL/TestTypeTest.php | 52 ++++++++++++++++++++++++++ 2 files changed, 54 insertions(+) diff --git a/graphql/schema.graphql b/graphql/schema.graphql index 9db3ef7e37..7e9909faf5 100644 --- a/graphql/schema.graphql +++ b/graphql/schema.graphql @@ -967,6 +967,8 @@ type Test { output: String @with(relation: "testOutput") + build: Build! @belongsTo + testMeasurements( filters: _ @filter ): [TestMeasurement!]! @hasMany diff --git a/tests/Feature/GraphQL/TestTypeTest.php b/tests/Feature/GraphQL/TestTypeTest.php index b4d95e4daa..3cece0eb05 100644 --- a/tests/Feature/GraphQL/TestTypeTest.php +++ b/tests/Feature/GraphQL/TestTypeTest.php @@ -133,6 +133,58 @@ public function testBasicFieldAccess(): void ]); } + public function testBuildRelationship(): void + { + $build = $this->project->builds()->create([ + 'name' => 'build1', + 'uuid' => Str::uuid()->toString(), + ]); + + $build->tests()->create([ + 'testname' => 'test1', + 'status' => 'passed', + 'outputid' => $this->test_output->id, + ]); + + $this->graphQL(' + query build($id: ID) { + build(id: $id) { + tests { + edges { + node { + name + build { + id + name + } + } + } + } + } + } + ', [ + 'id' => $build->id, + ])->assertExactJson([ + 'data' => [ + 'build' => [ + 'tests' => [ + 'edges' => [ + [ + 'node' => [ + 'name' => 'test1', + 'build' => [ + 'id' => (string) $build->id, + 'name' => 'build1', + ], + ], + ], + ], + ], + ], + ], + ]); + } + /** * @return array> */