11<?php
22
3- namespace Drupal \Tests \graphql \Kernel \ Framework ;
3+ namespace Drupal \Tests \graphql \Kernel ;
44
55use Drupal \graphql \GraphQL \ResolverRegistry ;
66use Drupal \graphql \Plugin \GraphQL \SchemaExtension \SdlSchemaExtensionPluginBase ;
77use Drupal \graphql \Plugin \SchemaExtensionPluginManager ;
8- use Drupal \Tests \graphql \Kernel \GraphQLTestBase ;
98use Drupal \Tests \graphql \Kernel \Schema \AlterableComposableTestSchema ;
109
1110/**
@@ -104,6 +103,40 @@ public function testSchemaExtensionAlteredQueryResultPropertyToNonNull(): void {
104103 ], json_decode ($ result ->getContent (), TRUE ));
105104 }
106105
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+
107140 /**
108141 * {@inheritdoc}
109142 */
@@ -124,15 +157,24 @@ protected function mockSchema($id, $schema, array $extensions = []): void {
124157 ->method ('getBaseDefinition ' )
125158 ->willReturn ('' );
126159
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
131168 extend type Result {
132169 position: Int
133170 }
134- GQL
135- );
171+ GQL ;
172+ break ;
173+ }
174+
175+ $ extensions ['graphql_alterable_schema_test ' ]->expects (static ::any ())
176+ ->method ('getExtensionDefinition ' )
177+ ->willReturn ($ extensionDefinition );
136178
137179 $ extensionManager ->expects (static ::any ())
138180 ->method ('getExtensions ' )
0 commit comments