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 d683f06
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 13 deletions.
7 changes: 4 additions & 3 deletions src/Support/Type.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,11 @@
declare(strict_types = 1);
namespace Rebing\GraphQL\Support;

use GraphQL\Type\Definition\FieldDefinition;
use Illuminate\Support\Str;
use Rebing\GraphQL\Support\InputType;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\FieldDefinition;
use GraphQL\Type\Definition\Type as GraphqlType;
use Illuminate\Support\Str;
use Rebing\GraphQL\Support\Contracts\TypeConvertible;

/**
Expand Down Expand Up @@ -59,7 +60,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
50 changes: 40 additions & 10 deletions tests/Unit/GraphQLTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,26 @@
namespace Rebing\GraphQL\Tests\Unit;

use GraphQL\Error\Error;
use GraphQL\Type\Definition\ListOfType;
use GraphQL\Type\Schema;
use GraphQL\Type\Definition\Type;
use Rebing\GraphQL\Tests\TestCase;
use GraphQL\Type\Definition\NonNull;
use GraphQL\Type\Definition\ListOfType;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Schema;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Support\Facades\Validator;
use Rebing\GraphQL\Error\ValidationError;
use Rebing\GraphQL\Exception\SchemaNotFound;
use Rebing\GraphQL\Exception\TypeNotFound;
use Rebing\GraphQL\Support\Facades\GraphQL;
use Rebing\GraphQL\Tests\Support\Directives\ExampleDirective;
use Rebing\GraphQL\Tests\Support\Objects\CustomExampleType;
use Rebing\GraphQL\Tests\Support\Objects\ExamplesQuery;
use Rebing\GraphQL\Exception\SchemaNotFound;
use Rebing\GraphQL\Tests\Support\Objects\ExampleType;
use Rebing\GraphQL\Tests\Support\Objects\ExamplesQuery;
use Rebing\GraphQL\Tests\Support\Objects\CustomExampleType;
use Rebing\GraphQL\Tests\Support\Directives\ExampleDirective;
use Rebing\GraphQL\Tests\Support\Objects\UpdateExampleMutation;
use Rebing\GraphQL\Tests\TestCase;
use Rebing\GraphQL\Tests\Unit\AliasArguments\Stubs\ExampleValidationInputObject;
use Rebing\GraphQL\Tests\Unit\AliasArguments\Stubs\ExampleType as ExampleAliasType;
use Rebing\GraphQL\Tests\Unit\AliasArguments\Stubs\ExampleNestedValidationInputObject;

class GraphQLTest extends TestCase
{
Expand All @@ -32,6 +35,8 @@ public function testDefaultSchema(): void
$this->assertGraphQLSchemaHasQuery($schema, 'examples');
$this->assertGraphQLSchemaHasMutation($schema, 'updateExample');
self::assertArrayHasKey('Example', $schema->getTypeMap());

$schema->assertValid();
}

public function testSchemaWithName(): void
Expand All @@ -40,10 +45,35 @@ public function testSchemaWithName(): void

$this->assertGraphQLSchema($schema);
$this->assertGraphQLSchemaHasQuery($schema, 'examplesCustom');
$this->assertGraphQLSchemaHasMutation($schema, 'updateExampleCustom');
$this->assertGraphQLSchemaHasMutation($schema, 'updateExampleCustom');
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 d683f06

Please sign in to comment.