10
10
use Rebing \GraphQL \Tests \Support \Queries \PostQuery ;
11
11
use Rebing \GraphQL \Tests \Support \Types \PostWithModelType ;
12
12
use Rebing \GraphQL \Tests \Support \Traits \SqlAssertionTrait ;
13
+ use Rebing \GraphQL \Tests \Support \Types \PostWithModelAndAliasType ;
13
14
use Rebing \GraphQL \Tests \Support \Queries \PostWithSelectFieldsAndModelQuery ;
14
15
use Rebing \GraphQL \Tests \Support \Queries \PostWithSelectFieldsNoModelQuery ;
16
+ use Rebing \GraphQL \Tests \Support \Queries \PostWithSelectFieldsAndModelAndAliasQuery ;
15
17
16
18
class SelectFieldsTest extends TestCaseDatabase
17
19
{
@@ -95,6 +97,40 @@ public function testWithSelectFieldsAndModel(): void
95
97
$ this ->assertEquals ($ expectedResult , $ response ->json ());
96
98
}
97
99
100
+ public function testWithSelectFieldsAndModelAndAlias (): void
101
+ {
102
+ $ post = factory (Post::class)->create ([
103
+ 'title ' => 'Description of the post ' ,
104
+ ]);
105
+
106
+ $ graphql = <<<GRAQPHQL
107
+ {
108
+ postWithSelectFieldsAndModelAndAlias(id: $ post ->id ) {
109
+ id
110
+ description
111
+ }
112
+ }
113
+ GRAQPHQL ;
114
+
115
+ $ this ->sqlCounterReset ();
116
+
117
+ $ response = $ this ->call ('GET ' , '/graphql ' , [
118
+ 'query ' => $ graphql ,
119
+ ]);
120
+
121
+ $ this ->assertSqlQueries (<<<'SQL'
122
+ select "posts"."id", "posts"."title" from "posts" where "posts"."id" = ? limit 1;
123
+ SQL
124
+ );
125
+
126
+ $ this ->assertEquals ($ response ->getStatusCode (), 200 );
127
+
128
+ $ result = $ response ->json ();
129
+
130
+ $ this ->assertNull ($ result ['data ' ]['postWithSelectFieldsAndModelAndAlias ' ]);
131
+ $ this ->assertSame ('Cannot return null for non-nullable field PostWithModelAndAlias.description. ' , $ result ['errors ' ][0 ]['debugMessage ' ]);
132
+ }
133
+
98
134
public function testWithSelectFieldsNoModel (): void
99
135
{
100
136
$ post = factory (Post::class)->create ([
@@ -142,6 +178,7 @@ protected function getEnvironmentSetUp($app)
142
178
'query ' => [
143
179
PostQuery::class,
144
180
PostWithSelectFieldsAndModelQuery::class,
181
+ PostWithSelectFieldsAndModelAndAliasQuery::class,
145
182
PostWithSelectFieldsNoModelQuery::class,
146
183
],
147
184
]);
@@ -151,6 +188,7 @@ protected function getEnvironmentSetUp($app)
151
188
$ app ['config ' ]->set ('graphql.types ' , [
152
189
PostType::class,
153
190
PostWithModelType::class,
191
+ PostWithModelAndAliasType::class,
154
192
]);
155
193
156
194
$ app ['config ' ]->set ('app.debug ' , true );
0 commit comments