Skip to content

Commit e201632

Browse files
authored
Add test to show that relations can be queried with conditions (#1560)
Former-commit-id: 3a3e686
1 parent d97c5af commit e201632

File tree

2 files changed

+41
-5
lines changed

2 files changed

+41
-5
lines changed

src/Schema/Types/Scalars/Upload.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ class Upload extends ScalarType
1313
/**
1414
* This always throws, as the Upload scalar can only be used as an argument.
1515
*
16-
*
1716
* @throws \GraphQL\Error\InvariantViolation
1817
*/
1918
public function serialize($value): void
@@ -26,7 +25,6 @@ public function serialize($value): void
2625
/**
2726
* Parse a externally provided variable value into a Carbon instance.
2827
*
29-
*
3028
* @throws \GraphQL\Error\Error
3129
*/
3230
public function parseValue($value): UploadedFile

tests/Integration/Schema/Directives/HasManyDirectiveTest.php

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,9 +32,9 @@ protected function setUp(): void
3232
parent::setUp();
3333

3434
$this->user = factory(User::class)->create();
35-
$this->tasks = factory(Task::class, 3)->create([
36-
'user_id' => $this->user->getKey(),
37-
]);
35+
$this->tasks = factory(Task::class, 3)->make();
36+
$this->user->tasks()->saveMany($this->tasks);
37+
3838
factory(Task::class)->create([
3939
'user_id' => $this->user->getKey(),
4040
// This task should be ignored via global scope on the Task model
@@ -79,6 +79,44 @@ public function testCanQueryHasManyRelationship(): void
7979
')->assertJsonCount(3, 'data.user.tasks');
8080
}
8181

82+
public function testCanQueryHasManyWithCondition(): void
83+
{
84+
$this->schema = /** @lang GraphQL */ '
85+
type User {
86+
tasks(
87+
id: ID @eq
88+
): [Task!]! @hasMany
89+
}
90+
91+
type Task {
92+
id: Int
93+
foo: String
94+
}
95+
96+
type Query {
97+
user: User @auth
98+
}
99+
';
100+
101+
/** @var Task $firstTask */
102+
$firstTask = $this->user->tasks->first();
103+
104+
// Ensure global scopes are respected here
105+
$this
106+
->graphQL(/** @lang GraphQL */ '
107+
query ($id: ID){
108+
user {
109+
tasks(id: $id) {
110+
id
111+
}
112+
}
113+
}
114+
', [
115+
'id' => $firstTask->id,
116+
])
117+
->assertJsonCount(1, 'data.user.tasks');
118+
}
119+
82120
public function testCallsScopeWithResolverArgs(): void
83121
{
84122
$this->assertCount(3, $this->user->tasks);

0 commit comments

Comments
 (0)