@@ -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