Array in variables in place of object shouldn't cause fatal error (fixes #467)

This commit is contained in:
Vladimir Razuvaev 2019-06-19 19:29:03 +07:00
parent ed1746e800
commit 93ccd7351d
2 changed files with 46 additions and 1 deletions

View File

@ -199,7 +199,7 @@ class Value
}
$suggestions = Utils::suggestionList(
$fieldName,
(string) $fieldName,
array_keys($fields)
);
$didYouMean = $suggestions

View File

@ -0,0 +1,45 @@
<?php
declare(strict_types=1);
namespace GraphQL\Tests\Regression;
use GraphQL\GraphQL;
use GraphQL\Utils\BuildSchema;
use PHPUnit\Framework\TestCase;
/**
* @see https://github.com/webonyx/graphql-php/issues/467
*/
class Issue467Test extends TestCase
{
public function testInputObjectValidation()
{
$schemaStr = '
input MsgInput {
msg: String
}
type Query {
echo(msg: MsgInput): String
}
schema {
query: Query
}
';
$query = '
query echo ($msg: MsgInput) {
echo (msg: $msg)
}';
$variables = ['msg' => ['my message']];
$schema = BuildSchema::build($schemaStr);
$result = GraphQL::executeQuery($schema, $query, null, null, $variables);
$expectedError = 'Variable "$msg" got invalid value ["my message"]; Field "0" is not defined by type MsgInput.';
self::assertCount(1, $result->errors);
self::assertEquals($expectedError, $result->errors[0]->getMessage());
}
}