Skip to content

Commit

Permalink
fix: schema can be printed
Browse files Browse the repository at this point in the history
  • Loading branch information
sforward committed Mar 1, 2023
1 parent 503a966 commit 0fc11f6
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
12 changes: 3 additions & 9 deletions src/GraphQL.php
Original file line number Diff line number Diff line change
Expand Up @@ -365,17 +365,11 @@ public function buildSchemaFromConfig(array $schemaConfig): Schema

$this->addTypes($schemaTypes);

$query = $this->objectType($schemaQuery, [
'name' => 'Query',
]);
$query = $this->objectType($schemaQuery, ['name' => 'Query']);

$mutation = $schemaMutation
? $this->objectType($schemaMutation, ['name' => 'Mutation'])
: null;
$mutation = $this->objectType($schemaMutation, ['name' => 'Mutation']);

$subscription = $schemaSubscription
? $this->objectType($schemaSubscription, ['name' => 'Subscription'])
: null;
$subscription = $this->objectType($schemaSubscription, ['name' => 'Subscription']);

$directives = Directive::getInternalDirectives();

Expand Down
18 changes: 18 additions & 0 deletions tests/Unit/GraphQLQueryTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
declare(strict_types = 1);
namespace Rebing\GraphQL\Tests\Unit;

use GraphQL\Utils\SchemaPrinter;
use Rebing\GraphQL\Support\Facades\GraphQL;
use Rebing\GraphQL\Tests\Support\Objects\ExamplesQuery;
use Rebing\GraphQL\Tests\TestCase;
Expand Down Expand Up @@ -212,4 +213,21 @@ public function testCustomDefaultFieldResolverClosure(): void
self::assertSame($expectedDataResult, $result->data);
self::assertCount(0, $result->errors);
}

public function testPrintSchema(): void
{
$schema = GraphQL::buildSchemaFromConfig([
'query' => [
'examplesCustom' => ExamplesQuery::class,
],
]);

$gql = SchemaPrinter::doPrint($schema);

$queryFragment = 'type Query {
examplesCustom(index: Int): [Example]
}';

self::assertStringContainsString($queryFragment, $gql);
}
}

0 comments on commit 0fc11f6

Please sign in to comment.