mirror of
https://github.com/retailcrm/graphql-php.git
synced 2024-11-24 05:46:05 +03:00
Array in variables in place of object shouldn't cause fatal error (fixes #467)
This commit is contained in:
parent
ed1746e800
commit
93ccd7351d
@ -199,7 +199,7 @@ class Value
|
||||
}
|
||||
|
||||
$suggestions = Utils::suggestionList(
|
||||
$fieldName,
|
||||
(string) $fieldName,
|
||||
array_keys($fields)
|
||||
);
|
||||
$didYouMean = $suggestions
|
||||
|
45
tests/Regression/Issue467Test.php
Normal file
45
tests/Regression/Issue467Test.php
Normal 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());
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user