Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions app/Models/BuildError.php
Original file line number Diff line number Diff line change
Expand Up @@ -85,4 +85,12 @@ protected function command(): Attribute
get: fn (mixed $value, array $attributes): ?string => $this->arguments->isEmpty() ? null : $this->arguments->sortBy('pivot.place')->pluck('argument')->implode(' '),
);
}

/**
* @return BelongsToMany<Label, $this>
*/
public function labels(): BelongsToMany
{
return $this->belongsToMany(Label::class, 'label2buildfailure', 'buildfailureid', 'labelid');
}
}
4 changes: 4 additions & 0 deletions graphql/schema.graphql
Original file line number Diff line number Diff line change
Expand Up @@ -997,6 +997,10 @@ type BuildError {
sourceLine: Int @rename(attribute: "sourceline") @filterable

command: String @with(relation: "arguments")

labels(
filters: _ @filter
): [Label!]! @belongsToMany(type: CONNECTION) @orderBy(column: "id")
}


Expand Down
74 changes: 74 additions & 0 deletions tests/Feature/GraphQL/BuildErrorTypeTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use App\Models\Build;
use App\Models\BuildError;
use App\Models\BuildFailureArgument;
use App\Models\Label;
use Illuminate\Foundation\Testing\DatabaseTransactions;
use Illuminate\Support\Str;
use PHPUnit\Framework\Attributes\DataProvider;
Expand Down Expand Up @@ -193,4 +194,77 @@ public function testCommandField(): void
],
]);
}

public function testLabelsRelationship(): void
{
$project = $this->makePublicProject();

/** @var Build $build */
$build = $project->builds()->create([
'name' => Str::uuid()->toString(),
'uuid' => Str::uuid()->toString(),
]);

$label1 = Label::create([
'text' => Str::uuid()->toString(),
]);
$label2 = Label::create([
'text' => Str::uuid()->toString(),
]);

/** @var BuildError $buildError */
$buildError = $build->buildErrors()->save(BuildError::factory()->make());

$buildError->labels()->attach([$label1->id, $label2->id]);

// Test with no arguments
$this->graphQL('
query build($id: ID) {
build(id: $id) {
buildErrors {
edges {
node {
labels {
edges {
node {
text
}
}
}
}
}
}
}
}
', [
'id' => $build->id,
])->assertExactJson([
'data' => [
'build' => [
'buildErrors' => [
'edges' => [
[
'node' => [
'labels' => [
'edges' => [
[
'node' => [
'text' => $label1->text,
],
],
[
'node' => [
'text' => $label2->text,
],
],
],
],
],
],
],
],
],
],
]);
}
}