1
1
<?php
2
2
3
- namespace Drupal \Tests \graphql \Kernel \ Framework ;
3
+ namespace Drupal \Tests \graphql \Kernel ;
4
4
5
5
use Drupal \graphql \GraphQL \ResolverRegistry ;
6
6
use Drupal \graphql \Plugin \GraphQL \SchemaExtension \SdlSchemaExtensionPluginBase ;
7
7
use Drupal \graphql \Plugin \SchemaExtensionPluginManager ;
8
- use Drupal \Tests \graphql \Kernel \GraphQLTestBase ;
9
8
use Drupal \Tests \graphql \Kernel \Schema \AlterableComposableTestSchema ;
10
9
11
10
/**
@@ -104,6 +103,40 @@ public function testSchemaExtensionAlteredQueryResultPropertyToNonNull(): void {
104
103
], json_decode ($ result ->getContent (), TRUE ));
105
104
}
106
105
106
+ /**
107
+ * Test if schema extension altering is working with empty extensions.
108
+ */
109
+ public function testEmptySchemaExtensionAlteredQueryResultPropertyAdded (): void {
110
+ $ result = $ this ->query ('query { alterableQuery(id: 1) { id, empty } } ' );
111
+ $ this ->assertSame (200 , $ result ->getStatusCode ());
112
+ // Here should be error that query result empty variable cannot be null.
113
+ // This leads to the internal server error with reference to the variable.
114
+ $ this ->assertSame ([
115
+ 'errors ' => [
116
+ 0 => [
117
+ 'message ' => 'Internal server error ' ,
118
+ 'extensions ' => [
119
+ 'category ' => 'internal ' ,
120
+ ],
121
+ 'locations ' => [
122
+ 0 => [
123
+ 'line ' => 1 ,
124
+ 'column ' => 37 ,
125
+ ],
126
+ ],
127
+ 'path ' => [
128
+ 'alterableQuery ' ,
129
+ // Reference to our variable in the error.
130
+ 'empty ' ,
131
+ ],
132
+ ],
133
+ ],
134
+ 'data ' => [
135
+ 'alterableQuery ' => NULL ,
136
+ ],
137
+ ], json_decode ($ result ->getContent (), TRUE ));
138
+ }
139
+
107
140
/**
108
141
* {@inheritdoc}
109
142
*/
@@ -124,15 +157,24 @@ protected function mockSchema($id, $schema, array $extensions = []): void {
124
157
->method ('getBaseDefinition ' )
125
158
->willReturn ('' );
126
159
127
- $ extensions ['graphql_alterable_schema_test ' ]->expects (static ::any ())
128
- ->method ('getExtensionDefinition ' )
129
- ->willReturn (
130
- <<<GQL
160
+ // Different extension definition for different tests.
161
+ switch ($ this ->getName ()) {
162
+ case 'testEmptySchemaExtensionAlteredQueryResultPropertyAdded ' :
163
+ $ extensionDefinition = '' ;
164
+ break ;
165
+
166
+ default :
167
+ $ extensionDefinition = <<<GQL
131
168
extend type Result {
132
169
position: Int
133
170
}
134
- GQL
135
- );
171
+ GQL ;
172
+ break ;
173
+ }
174
+
175
+ $ extensions ['graphql_alterable_schema_test ' ]->expects (static ::any ())
176
+ ->method ('getExtensionDefinition ' )
177
+ ->willReturn ($ extensionDefinition );
136
178
137
179
$ extensionManager ->expects (static ::any ())
138
180
->method ('getExtensions ' )
0 commit comments