Skip to content

Commit 0fc11f6

Browse files
committed
fix: schema can be printed
1 parent 503a966 commit 0fc11f6

File tree

2 files changed

+21
-9
lines changed

2 files changed

+21
-9
lines changed

src/GraphQL.php

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -365,17 +365,11 @@ public function buildSchemaFromConfig(array $schemaConfig): Schema
365365

366366
$this->addTypes($schemaTypes);
367367

368-
$query = $this->objectType($schemaQuery, [
369-
'name' => 'Query',
370-
]);
368+
$query = $this->objectType($schemaQuery, ['name' => 'Query']);
371369

372-
$mutation = $schemaMutation
373-
? $this->objectType($schemaMutation, ['name' => 'Mutation'])
374-
: null;
370+
$mutation = $this->objectType($schemaMutation, ['name' => 'Mutation']);
375371

376-
$subscription = $schemaSubscription
377-
? $this->objectType($schemaSubscription, ['name' => 'Subscription'])
378-
: null;
372+
$subscription = $this->objectType($schemaSubscription, ['name' => 'Subscription']);
379373

380374
$directives = Directive::getInternalDirectives();
381375

tests/Unit/GraphQLQueryTest.php

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
declare(strict_types = 1);
44
namespace Rebing\GraphQL\Tests\Unit;
55

6+
use GraphQL\Utils\SchemaPrinter;
67
use Rebing\GraphQL\Support\Facades\GraphQL;
78
use Rebing\GraphQL\Tests\Support\Objects\ExamplesQuery;
89
use Rebing\GraphQL\Tests\TestCase;
@@ -212,4 +213,21 @@ public function testCustomDefaultFieldResolverClosure(): void
212213
self::assertSame($expectedDataResult, $result->data);
213214
self::assertCount(0, $result->errors);
214215
}
216+
217+
public function testPrintSchema(): void
218+
{
219+
$schema = GraphQL::buildSchemaFromConfig([
220+
'query' => [
221+
'examplesCustom' => ExamplesQuery::class,
222+
],
223+
]);
224+
225+
$gql = SchemaPrinter::doPrint($schema);
226+
227+
$queryFragment = 'type Query {
228+
examplesCustom(index: Int): [Example]
229+
}';
230+
231+
self::assertStringContainsString($queryFragment, $gql);
232+
}
215233
}

0 commit comments

Comments
 (0)