Skip to content

Commit

Permalink
fix schema validation - resolve not allowed in input fields
Browse files Browse the repository at this point in the history
  • Loading branch information
Christian Nielsen committed Jul 24, 2023
1 parent 3be3cc6 commit cf1a319
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/Support/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ protected function getFieldResolver(string $name, array $field): ?callable
};
}

if (isset($field['alias']) && \is_string($field['alias'])) {
if (isset($field['alias']) && \is_string($field['alias']) && !($this instanceof InputType)) {
$alias = $field['alias'];

return function ($type) use ($alias) {
Expand Down
27 changes: 27 additions & 0 deletions tests/Unit/GraphQLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,9 @@
use Rebing\GraphQL\Tests\Support\Objects\ExampleType;
use Rebing\GraphQL\Tests\Support\Objects\UpdateExampleMutation;
use Rebing\GraphQL\Tests\TestCase;
use Rebing\GraphQL\Tests\Unit\AliasArguments\Stubs\ExampleNestedValidationInputObject;
use Rebing\GraphQL\Tests\Unit\AliasArguments\Stubs\ExampleType as ExampleAliasType;
use Rebing\GraphQL\Tests\Unit\AliasArguments\Stubs\ExampleValidationInputObject;

class GraphQLTest extends TestCase
{
Expand All @@ -44,6 +47,30 @@ public function testSchemaWithName(): void
self::assertArrayHasKey('Example', $schema->getTypeMap());
}

/**
* @doesNotPerformAssertions
*/
public function testSchemaIsValidWithInputFieldAliases(): void
{
$schema = GraphQL::buildSchemaFromConfig([
'mutation' => [
'examplesCustom' => \Rebing\GraphQL\Tests\Unit\AliasArguments\Stubs\UpdateExampleMutation::class,
],
'query' => [
'examplesCustom' => ExamplesQuery::class,
],

'types' => [
CustomExampleType::class,
ExampleAliasType::class,
ExampleValidationInputObject::class,
ExampleNestedValidationInputObject::class,
],
]);

$schema->assertValid();
}

public function testSchemaWithNameReferencingClass(): void
{
$schema = GraphQL::schema('class_based');
Expand Down

0 comments on commit cf1a319

Please sign in to comment.