Skip to content

Commit

Permalink
Add test for multiple schema's with custom int type
Browse files Browse the repository at this point in the history
  • Loading branch information
ruudk committed Aug 14, 2023
1 parent 5340872 commit b6c20b7
Showing 1 changed file with 53 additions and 0 deletions.
53 changes: 53 additions & 0 deletions tests/MultipleSchemaTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
<?php declare(strict_types=1);

namespace GraphQL\Tests;

use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter;
use GraphQL\Executor\Promise\Promise;
use GraphQL\GraphQL;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Registry\DefaultStandardTypeRegistry;
use GraphQL\Type\Schema;
use GraphQL\Type\SchemaConfig;
use PHPUnit\Framework\TestCase;

final class MultipleSchemaTest extends TestCase
{
public function testMultipleSchemasWithCustomIntType(): void
{
$schema1 = $this->createSchema();
$result1 = GraphQL::executeQuery($schema1, '{ count }');
self::assertSame(['data' => ['count' => 1]], $result1->toArray());

$schema2 = $this->createSchema();
$result2 = GraphQL::executeQuery($schema2, '{ count }');
self::assertSame(['data' => ['count' => 1]], $result2->toArray());

self::assertNotSame($schema1->getType('Int'), $schema2->getType('Int'));
}

private function createSchema() : Schema
{
$typeRegistry = new DefaultStandardTypeRegistry(
CustomIntType::class
);

$query = new ObjectType([
'name' => 'Query',
'fields' => [
'count' => [
'type' => Type::nonNull($typeRegistry->int()),
'resolve' => fn() => 1,
],
],
]);

$config = SchemaConfig::create([
'typeRegistry' => $typeRegistry,
'query' => $query,
]);

return new Schema($config) ;
}
}

0 comments on commit b6c20b7

Please sign in to comment.