Skip to content

Commit

Permalink
test: add test
Browse files Browse the repository at this point in the history
  • Loading branch information
jaulz committed Nov 22, 2023
1 parent e159a26 commit e421dd5
Showing 1 changed file with 67 additions and 0 deletions.
67 changes: 67 additions & 0 deletions tests/Unit/Schema/AST/ASTHelperTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Tests\Unit\Schema\AST;

use GraphQL\Language\AST\FieldDefinitionNode;
use GraphQL\Language\AST\InputObjectTypeDefinitionNode;
use GraphQL\Language\AST\InputValueDefinitionNode;
use GraphQL\Language\AST\InterfaceTypeDefinitionNode;
use GraphQL\Language\AST\NamedTypeNode;
Expand All @@ -19,6 +20,7 @@
use Nuwave\Lighthouse\Schema\RootType;
use Nuwave\Lighthouse\Support\Contracts\ArgManipulator;
use Nuwave\Lighthouse\Support\Contracts\FieldManipulator;
use Nuwave\Lighthouse\Support\Contracts\InputManipulator;
use Tests\TestCase;

final class ASTHelperTest extends TestCase
Expand Down Expand Up @@ -364,4 +366,69 @@ public function manipulateArgDefinition(

$this->assertSame($typeType->name->value, 'Int');
}

public function testDynamicallyAddedInputManipulatorDirective(): void
{
$directive = new class() extends BaseDirective implements InputManipulator {
public static function definition(): string
{
return /** @lang GraphQL */ 'directive @foo on INPUT_FIELD_DEFINITION';
}

public function manipulateInputDefinition(
DocumentAST &$documentAST,
InputValueDefinitionNode &$inputDefinition,
InputObjectTypeDefinitionNode &$parentType,
): void {
$inputDefinition->type = Parser::namedType('Int');
}
};

$directiveLocator = $this->app->make(DirectiveLocator::class);
$directiveLocator->setResolved('foo', $directive::class);

$dynamicDirective = new class() extends BaseDirective implements InputManipulator {
public static function definition(): string
{
return /** @lang GraphQL */ 'directive @dynamic on INPUT_FIELD_DEFINITION';
}

public function manipulateInputDefinition(
DocumentAST &$documentAST,
InputValueDefinitionNode &$inputDefinition,
InputObjectTypeDefinitionNode &$parentType,
): void {
$directiveInstance = ASTHelper::addDirectiveToNode('@foo', $inputDefinition);

assert($directiveInstance instanceof InputManipulator);

$directiveInstance->manipulateInputDefinition($documentAST, $inputDefinition, $parentType);
}
};

$directiveLocator->setResolved('dynamic', $dynamicDirective::class);

$this->schema = /** @lang GraphQL */ '
input Input {
name: String @dynamic
}
type Query {
foo(name: Input): String
}
';
$astBuilder = $this->app->make(ASTBuilder::class);
$documentAST = $astBuilder->documentAST();

$inputType = $documentAST->types['Input'];
assert($inputType instanceof InputObjectTypeDefinitionNode);

$fieldType = $inputType->fields[0];
assert($fieldType instanceof FieldDefinitionNode);

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.0 with Laravel ^9 and highest dependencies

Call to function assert() with false will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.0 with Laravel ^9 and highest dependencies

Instanceof between GraphQL\Language\AST\InputValueDefinitionNode and GraphQL\Language\AST\FieldDefinitionNode will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^9 and lowest dependencies

Call to function assert() with false will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^9 and lowest dependencies

Instanceof between GraphQL\Language\AST\InputValueDefinitionNode and GraphQL\Language\AST\FieldDefinitionNode will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^9 and highest dependencies

Call to function assert() with false will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^9 and highest dependencies

Instanceof between GraphQL\Language\AST\InputValueDefinitionNode and GraphQL\Language\AST\FieldDefinitionNode will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^10 and lowest dependencies

Call to function assert() with false will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^10 and lowest dependencies

Instanceof between GraphQL\Language\AST\InputValueDefinitionNode and GraphQL\Language\AST\FieldDefinitionNode will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^10 and highest dependencies

Call to function assert() with false will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.1 with Laravel ^10 and highest dependencies

Instanceof between GraphQL\Language\AST\InputValueDefinitionNode and GraphQL\Language\AST\FieldDefinitionNode will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^9 and lowest dependencies

Call to function assert() with false will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^9 and lowest dependencies

Instanceof between GraphQL\Language\AST\InputValueDefinitionNode and GraphQL\Language\AST\FieldDefinitionNode will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^9 and highest dependencies

Call to function assert() with false will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^9 and highest dependencies

Instanceof between GraphQL\Language\AST\InputValueDefinitionNode and GraphQL\Language\AST\FieldDefinitionNode will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^10 and lowest dependencies

Call to function assert() with false will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^10 and lowest dependencies

Instanceof between GraphQL\Language\AST\InputValueDefinitionNode and GraphQL\Language\AST\FieldDefinitionNode will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^10 and highest dependencies

Call to function assert() with false will always evaluate to false.

Check failure on line 427 in tests/Unit/Schema/AST/ASTHelperTest.php

View workflow job for this annotation

GitHub Actions / PHPStan on PHP 8.2 with Laravel ^10 and highest dependencies

Instanceof between GraphQL\Language\AST\InputValueDefinitionNode and GraphQL\Language\AST\FieldDefinitionNode will always evaluate to false.

$typeType = $fieldType->type;
assert($typeType instanceof NamedTypeNode);

$this->assertSame($typeType->name->value, 'Int');
}
}

0 comments on commit e421dd5

Please sign in to comment.