2015-07-15 20:05:46 +03:00
|
|
|
<?php
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
declare(strict_types=1);
|
|
|
|
|
|
|
|
namespace GraphQL\Tests\Executor;
|
2015-08-17 17:01:55 +03:00
|
|
|
|
2018-02-13 18:51:44 +03:00
|
|
|
use GraphQL\Error\Error;
|
2016-04-09 10:36:53 +03:00
|
|
|
use GraphQL\Executor\Executor;
|
2015-07-15 20:05:46 +03:00
|
|
|
use GraphQL\Language\Parser;
|
2018-09-01 18:07:06 +03:00
|
|
|
use GraphQL\Tests\Executor\TestClasses\ComplexScalar;
|
2015-07-15 20:05:46 +03:00
|
|
|
use GraphQL\Type\Definition\InputObjectType;
|
|
|
|
use GraphQL\Type\Definition\ObjectType;
|
|
|
|
use GraphQL\Type\Definition\Type;
|
2018-09-01 18:07:06 +03:00
|
|
|
use GraphQL\Type\Schema;
|
2018-07-29 18:43:10 +03:00
|
|
|
use PHPUnit\Framework\TestCase;
|
2018-09-01 18:07:06 +03:00
|
|
|
use function json_encode;
|
2015-07-15 20:05:46 +03:00
|
|
|
|
2018-08-31 12:07:29 +03:00
|
|
|
/**
|
|
|
|
* Execute: Handles inputs
|
|
|
|
* Handles objects and nullability
|
|
|
|
*/
|
2018-07-29 18:43:10 +03:00
|
|
|
class VariablesTest extends TestCase
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testUsingInlineStructs() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
|
|
|
// executes with complex input:
|
2018-08-22 14:40:15 +03:00
|
|
|
$result = $this->executeQuery('
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
|
|
|
fieldWithObjectInput(input: {a: "foo", b: ["bar"], c: "baz"})
|
|
|
|
}
|
2018-08-22 14:40:15 +03:00
|
|
|
');
|
2015-07-15 20:05:46 +03:00
|
|
|
|
|
|
|
$expected = [
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['fieldWithObjectInput' => '{"a":"foo","b":["bar"],"c":"baz"}'],
|
2015-07-15 20:05:46 +03:00
|
|
|
];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
|
2015-08-17 17:01:55 +03:00
|
|
|
// properly parses single value to list:
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery('
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
|
|
|
fieldWithObjectInput(input: {a: "foo", b: "bar", c: "baz"})
|
|
|
|
}
|
2018-08-22 14:40:15 +03:00
|
|
|
');
|
2015-07-15 20:05:46 +03:00
|
|
|
$expected = ['data' => ['fieldWithObjectInput' => '{"a":"foo","b":["bar"],"c":"baz"}']];
|
|
|
|
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2016-11-18 19:59:28 +03:00
|
|
|
|
|
|
|
// properly parses null value to null
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery('
|
2016-11-18 19:59:28 +03:00
|
|
|
{
|
|
|
|
fieldWithObjectInput(input: {a: null, b: null, c: "C", d: null})
|
|
|
|
}
|
2018-08-22 14:40:15 +03:00
|
|
|
');
|
2016-11-18 19:59:28 +03:00
|
|
|
$expected = ['data' => ['fieldWithObjectInput' => '{"a":null,"b":null,"c":"C","d":null}']];
|
|
|
|
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2016-11-18 19:59:28 +03:00
|
|
|
|
|
|
|
// properly parses null value in list
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery('
|
2016-11-18 19:59:28 +03:00
|
|
|
{
|
|
|
|
fieldWithObjectInput(input: {b: ["A",null,"C"], c: "C"})
|
|
|
|
}
|
2018-08-22 14:40:15 +03:00
|
|
|
');
|
2016-11-18 19:59:28 +03:00
|
|
|
$expected = ['data' => ['fieldWithObjectInput' => '{"b":["A",null,"C"],"c":"C"}']];
|
|
|
|
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-08-17 17:01:55 +03:00
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
// does not use incorrect value
|
2018-08-22 14:40:15 +03:00
|
|
|
$result = $this->executeQuery('
|
2015-08-17 17:01:55 +03:00
|
|
|
{
|
|
|
|
fieldWithObjectInput(input: ["foo", "bar", "baz"])
|
|
|
|
}
|
2018-08-22 14:40:15 +03:00
|
|
|
');
|
2015-08-17 17:01:55 +03:00
|
|
|
|
|
|
|
$expected = [
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['fieldWithObjectInput' => null],
|
2016-11-19 00:15:40 +03:00
|
|
|
'errors' => [[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' => 'Argument "input" has invalid value ["foo", "bar", "baz"].',
|
|
|
|
'path' => ['fieldWithObjectInput'],
|
|
|
|
'locations' => [['line' => 3, 'column' => 39]],
|
|
|
|
],
|
|
|
|
],
|
2015-08-17 17:01:55 +03:00
|
|
|
];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertArraySubset($expected, $result->toArray());
|
2016-05-02 00:42:05 +03:00
|
|
|
|
|
|
|
// properly runs parseLiteral on complex scalar types
|
2018-08-22 14:40:15 +03:00
|
|
|
$result = $this->executeQuery('
|
2016-05-02 00:42:05 +03:00
|
|
|
{
|
2016-11-19 00:15:40 +03:00
|
|
|
fieldWithObjectInput(input: {c: "foo", d: "SerializedValue"})
|
2016-05-02 00:42:05 +03:00
|
|
|
}
|
2018-08-22 14:40:15 +03:00
|
|
|
');
|
2016-05-02 00:42:05 +03:00
|
|
|
$this->assertEquals(
|
2016-11-19 00:15:40 +03:00
|
|
|
['data' => ['fieldWithObjectInput' => '{"c":"foo","d":"DeserializedValue"}']],
|
2018-08-22 14:40:15 +03:00
|
|
|
$result->toArray()
|
2016-05-02 00:42:05 +03:00
|
|
|
);
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
private function executeQuery($query, $variableValues = null)
|
|
|
|
{
|
|
|
|
$document = Parser::parse($query);
|
|
|
|
|
|
|
|
return Executor::execute($this->schema(), $document, null, null, $variableValues);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Describe: Handles nullable scalars
|
|
|
|
*/
|
|
|
|
public function schema() : Schema
|
|
|
|
{
|
|
|
|
$ComplexScalarType = ComplexScalar::create();
|
|
|
|
|
|
|
|
$TestInputObject = new InputObjectType([
|
|
|
|
'name' => 'TestInputObject',
|
|
|
|
'fields' => [
|
|
|
|
'a' => ['type' => Type::string()],
|
|
|
|
'b' => ['type' => Type::listOf(Type::string())],
|
|
|
|
'c' => ['type' => Type::nonNull(Type::string())],
|
|
|
|
'd' => ['type' => $ComplexScalarType],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$TestNestedInputObject = new InputObjectType([
|
|
|
|
'name' => 'TestNestedInputObject',
|
|
|
|
'fields' => [
|
|
|
|
'na' => ['type' => Type::nonNull($TestInputObject)],
|
|
|
|
'nb' => ['type' => Type::nonNull(Type::string())],
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
$TestType = new ObjectType([
|
|
|
|
'name' => 'TestType',
|
|
|
|
'fields' => [
|
|
|
|
'fieldWithObjectInput' => $this->fieldWithInputArg(['type' => $TestInputObject]),
|
|
|
|
'fieldWithNullableStringInput' => $this->fieldWithInputArg(['type' => Type::string()]),
|
|
|
|
'fieldWithNonNullableStringInput' => $this->fieldWithInputArg(['type' => Type::nonNull(Type::string())]),
|
|
|
|
'fieldWithDefaultArgumentValue' => $this->fieldWithInputArg([
|
|
|
|
'type' => Type::string(),
|
|
|
|
'defaultValue' => 'Hello World',
|
|
|
|
]),
|
|
|
|
'fieldWithNestedInputObject' => $this->fieldWithInputArg([
|
|
|
|
'type' => $TestNestedInputObject,
|
|
|
|
'defaultValue' => 'Hello World',
|
|
|
|
]),
|
|
|
|
'list' => $this->fieldWithInputArg(['type' => Type::listOf(Type::string())]),
|
|
|
|
'nnList' => $this->fieldWithInputArg(['type' => Type::nonNull(Type::listOf(Type::string()))]),
|
|
|
|
'listNN' => $this->fieldWithInputArg(['type' => Type::listOf(Type::nonNull(Type::string()))]),
|
|
|
|
'nnListNN' => $this->fieldWithInputArg(['type' => Type::nonNull(Type::listOf(Type::nonNull(Type::string())))]),
|
|
|
|
],
|
|
|
|
]);
|
|
|
|
|
|
|
|
return new Schema(['query' => $TestType]);
|
|
|
|
}
|
|
|
|
|
|
|
|
private function fieldWithInputArg($inputArg)
|
|
|
|
{
|
|
|
|
return [
|
|
|
|
'type' => Type::string(),
|
|
|
|
'args' => ['input' => $inputArg],
|
|
|
|
'resolve' => function ($_, $args) {
|
|
|
|
if (isset($args['input'])) {
|
|
|
|
return json_encode($args['input']);
|
|
|
|
}
|
|
|
|
|
|
|
|
return null;
|
|
|
|
},
|
|
|
|
];
|
|
|
|
}
|
|
|
|
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testUsingVariables() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
|
|
|
$doc = '
|
2018-08-22 14:40:15 +03:00
|
|
|
query q($input:TestInputObject) {
|
|
|
|
fieldWithObjectInput(input: $input)
|
|
|
|
}
|
2015-07-15 20:05:46 +03:00
|
|
|
';
|
2018-08-22 14:40:15 +03:00
|
|
|
|
|
|
|
// executes with complex input:
|
2015-07-15 20:05:46 +03:00
|
|
|
$params = ['input' => ['a' => 'foo', 'b' => ['bar'], 'c' => 'baz']];
|
2018-08-22 14:40:15 +03:00
|
|
|
$result = $this->executeQuery($doc, $params);
|
2015-07-15 20:05:46 +03:00
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
['data' => ['fieldWithObjectInput' => '{"a":"foo","b":["bar"],"c":"baz"}']],
|
2018-08-22 14:40:15 +03:00
|
|
|
$result->toArray()
|
2015-07-15 20:05:46 +03:00
|
|
|
);
|
|
|
|
|
2015-08-17 17:01:55 +03:00
|
|
|
// uses default value when not provided:
|
2018-08-22 14:40:15 +03:00
|
|
|
$result = $this->executeQuery('
|
|
|
|
query ($input: TestInputObject = {a: "foo", b: ["bar"], c: "baz"}) {
|
2015-08-17 17:01:55 +03:00
|
|
|
fieldWithObjectInput(input: $input)
|
|
|
|
}
|
|
|
|
');
|
|
|
|
|
|
|
|
$expected = [
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['fieldWithObjectInput' => '{"a":"foo","b":["bar"],"c":"baz"}'],
|
2015-08-17 17:01:55 +03:00
|
|
|
];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-08-17 17:01:55 +03:00
|
|
|
|
2018-02-13 18:51:44 +03:00
|
|
|
// properly parses single value to list:
|
2015-07-15 20:05:46 +03:00
|
|
|
$params = ['input' => ['a' => 'foo', 'b' => 'bar', 'c' => 'baz']];
|
2018-08-22 14:40:15 +03:00
|
|
|
$result = $this->executeQuery($doc, $params);
|
2015-07-15 20:05:46 +03:00
|
|
|
$this->assertEquals(
|
|
|
|
['data' => ['fieldWithObjectInput' => '{"a":"foo","b":["bar"],"c":"baz"}']],
|
2018-08-22 14:40:15 +03:00
|
|
|
$result->toArray()
|
2015-07-15 20:05:46 +03:00
|
|
|
);
|
|
|
|
|
2015-08-17 17:01:55 +03:00
|
|
|
// executes with complex scalar input:
|
2018-09-01 18:07:06 +03:00
|
|
|
$params = ['input' => ['c' => 'foo', 'd' => 'SerializedValue']];
|
|
|
|
$result = $this->executeQuery($doc, $params);
|
2015-07-15 20:05:46 +03:00
|
|
|
$expected = [
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['fieldWithObjectInput' => '{"c":"foo","d":"DeserializedValue"}'],
|
2015-07-15 20:05:46 +03:00
|
|
|
];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-08-17 17:01:55 +03:00
|
|
|
|
|
|
|
// errors on null for nested non-null:
|
2018-09-01 18:07:06 +03:00
|
|
|
$params = ['input' => ['a' => 'foo', 'b' => 'bar', 'c' => null]];
|
|
|
|
$result = $this->executeQuery($doc, $params);
|
2017-07-05 13:31:35 +03:00
|
|
|
$expected = [
|
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' =>
|
2018-02-13 18:51:44 +03:00
|
|
|
'Variable "$input" got invalid value ' .
|
|
|
|
'{"a":"foo","b":"bar","c":null}; ' .
|
2018-02-16 18:19:25 +03:00
|
|
|
'Expected non-nullable type String! not to be null at value.c.',
|
2018-08-22 14:40:15 +03:00
|
|
|
'locations' => [['line' => 2, 'column' => 21]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'category' => 'graphql',
|
|
|
|
],
|
|
|
|
],
|
2017-07-05 13:31:35 +03:00
|
|
|
];
|
2018-02-13 18:51:44 +03:00
|
|
|
|
2017-07-05 13:31:35 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-08-17 17:01:55 +03:00
|
|
|
|
|
|
|
// errors on incorrect type:
|
2018-09-01 18:07:06 +03:00
|
|
|
$params = ['input' => 'foo bar'];
|
|
|
|
$result = $this->executeQuery($doc, $params);
|
2017-07-05 13:31:35 +03:00
|
|
|
$expected = [
|
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' =>
|
2018-02-13 18:51:44 +03:00
|
|
|
'Variable "$input" got invalid value "foo bar"; ' .
|
2018-02-16 18:19:25 +03:00
|
|
|
'Expected type TestInputObject to be an object.',
|
2018-09-01 18:07:06 +03:00
|
|
|
'locations' => [['line' => 2, 'column' => 21]],
|
|
|
|
'category' => 'graphql',
|
|
|
|
],
|
|
|
|
],
|
2017-07-05 13:31:35 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
|
|
|
|
// errors on omission of nested non-null:
|
|
|
|
$params = ['input' => ['a' => 'foo', 'b' => 'bar']];
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, $params);
|
2017-07-05 13:31:35 +03:00
|
|
|
$expected = [
|
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' =>
|
|
|
|
'Variable "$input" got invalid value {"a":"foo","b":"bar"}; ' .
|
2018-02-13 18:51:44 +03:00
|
|
|
'Field value.c of required type String! was not provided.',
|
2018-08-22 14:40:15 +03:00
|
|
|
'locations' => [['line' => 2, 'column' => 21]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'category' => 'graphql',
|
|
|
|
],
|
|
|
|
],
|
2017-07-05 13:31:35 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-08-17 17:01:55 +03:00
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
// errors on deep nested errors and with many errors
|
|
|
|
$nestedDoc = '
|
|
|
|
query q($input: TestNestedInputObject) {
|
|
|
|
fieldWithNestedObjectInput(input: $input)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$params = ['input' => ['na' => ['a' => 'foo']]];
|
2016-05-02 00:42:05 +03:00
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($nestedDoc, $params);
|
2017-07-05 13:31:35 +03:00
|
|
|
$expected = [
|
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' =>
|
2018-02-13 18:51:44 +03:00
|
|
|
'Variable "$input" got invalid value {"na":{"a":"foo"}}; ' .
|
|
|
|
'Field value.na.c of required type String! was not provided.',
|
|
|
|
'locations' => [['line' => 2, 'column' => 19]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'category' => 'graphql',
|
2018-02-13 18:51:44 +03:00
|
|
|
],
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' =>
|
2018-02-13 18:51:44 +03:00
|
|
|
'Variable "$input" got invalid value {"na":{"a":"foo"}}; ' .
|
|
|
|
'Field value.nb of required type String! was not provided.',
|
2017-08-07 22:00:17 +03:00
|
|
|
'locations' => [['line' => 2, 'column' => 19]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'category' => 'graphql',
|
|
|
|
],
|
|
|
|
],
|
2017-07-05 13:31:35 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($expected, $result->toArray());
|
|
|
|
|
2015-08-17 17:01:55 +03:00
|
|
|
// errors on addition of unknown input field
|
2018-09-01 18:07:06 +03:00
|
|
|
$params = ['input' => ['a' => 'foo', 'b' => 'bar', 'c' => 'baz', 'extra' => 'dog']];
|
|
|
|
$result = $this->executeQuery($doc, $params);
|
2017-07-05 13:31:35 +03:00
|
|
|
$expected = [
|
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' =>
|
2018-02-13 18:51:44 +03:00
|
|
|
'Variable "$input" got invalid value ' .
|
|
|
|
'{"a":"foo","b":"bar","c":"baz","extra":"dog"}; ' .
|
|
|
|
'Field "extra" is not defined by type TestInputObject.',
|
2018-08-22 14:40:15 +03:00
|
|
|
'locations' => [['line' => 2, 'column' => 21]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'category' => 'graphql',
|
|
|
|
],
|
|
|
|
],
|
2017-07-05 13:31:35 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows nullable inputs to be omitted')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsNullableInputsToBeOmitted() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery('
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
|
|
|
fieldWithNullableStringInput
|
|
|
|
}
|
2018-08-22 14:40:15 +03:00
|
|
|
');
|
2015-07-15 20:05:46 +03:00
|
|
|
$expected = [
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['fieldWithNullableStringInput' => null],
|
2015-07-15 20:05:46 +03:00
|
|
|
];
|
|
|
|
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows nullable inputs to be omitted in a variable')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsNullableInputsToBeOmittedInAVariable() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery('
|
2015-07-15 20:05:46 +03:00
|
|
|
query SetsNullable($value: String) {
|
|
|
|
fieldWithNullableStringInput(input: $value)
|
|
|
|
}
|
2018-08-22 14:40:15 +03:00
|
|
|
');
|
2015-08-17 17:01:55 +03:00
|
|
|
$expected = ['data' => ['fieldWithNullableStringInput' => null]];
|
2015-07-15 20:05:46 +03:00
|
|
|
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows nullable inputs to be omitted in an unlisted variable')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsNullableInputsToBeOmittedInAnUnlistedVariable() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery('
|
2015-07-15 20:05:46 +03:00
|
|
|
query SetsNullable {
|
|
|
|
fieldWithNullableStringInput(input: $value)
|
|
|
|
}
|
2018-08-22 14:40:15 +03:00
|
|
|
');
|
2015-08-17 17:01:55 +03:00
|
|
|
$expected = ['data' => ['fieldWithNullableStringInput' => null]];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
|
|
|
|
// Describe: Handles non-nullable scalars
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows nullable inputs to be set to null in a variable')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsNullableInputsToBeSetToNullInAVariable() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery('
|
2015-07-15 20:05:46 +03:00
|
|
|
query SetsNullable($value: String) {
|
|
|
|
fieldWithNullableStringInput(input: $value)
|
|
|
|
}
|
2018-08-22 14:40:15 +03:00
|
|
|
');
|
2015-08-17 17:01:55 +03:00
|
|
|
$expected = ['data' => ['fieldWithNullableStringInput' => null]];
|
2015-07-15 20:05:46 +03:00
|
|
|
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows nullable inputs to be set to a value in a variable')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsNullableInputsToBeSetToAValueInAVariable() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2015-07-15 20:05:46 +03:00
|
|
|
query SetsNullable($value: String) {
|
|
|
|
fieldWithNullableStringInput(input: $value)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, ['value' => 'a']);
|
2015-07-15 20:05:46 +03:00
|
|
|
$expected = ['data' => ['fieldWithNullableStringInput' => '"a"']];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows nullable inputs to be set to a value directly')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsNullableInputsToBeSetToAValueDirectly() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery('
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
|
|
|
fieldWithNullableStringInput(input: "a")
|
|
|
|
}
|
2018-08-22 14:40:15 +03:00
|
|
|
');
|
2015-07-15 20:05:46 +03:00
|
|
|
$expected = ['data' => ['fieldWithNullableStringInput' => '"a"']];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-11-19 00:15:40 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows non-nullable inputs to be omitted given a default')
|
2016-11-19 00:15:40 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsNonNullableInputsToBeOmittedGivenADefault() : void
|
2016-11-19 00:15:40 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery('
|
2016-11-19 00:15:40 +03:00
|
|
|
query SetsNonNullable($value: String = "default") {
|
|
|
|
fieldWithNonNullableStringInput(input: $value)
|
|
|
|
}
|
2018-08-22 14:40:15 +03:00
|
|
|
');
|
2016-11-19 00:15:40 +03:00
|
|
|
$expected = [
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['fieldWithNonNullableStringInput' => '"default"'],
|
2016-11-19 00:15:40 +03:00
|
|
|
];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2016-11-19 00:15:40 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('does not allow non-nullable inputs to be omitted in a variable')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testDoesntAllowNonNullableInputsToBeOmittedInAVariable() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-08-22 14:40:15 +03:00
|
|
|
$result = $this->executeQuery('
|
2015-07-15 20:05:46 +03:00
|
|
|
query SetsNonNullable($value: String!) {
|
|
|
|
fieldWithNonNullableStringInput(input: $value)
|
|
|
|
}
|
2018-08-22 14:40:15 +03:00
|
|
|
');
|
2017-07-05 13:31:35 +03:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' => 'Variable "$value" of required type "String!" was not provided.',
|
2017-08-07 22:00:17 +03:00
|
|
|
'locations' => [['line' => 2, 'column' => 31]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'category' => 'graphql',
|
|
|
|
],
|
|
|
|
],
|
2017-07-05 13:31:35 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('does not allow non-nullable inputs to be set to null in a variable')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testDoesNotAllowNonNullableInputsToBeSetToNullInAVariable() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2015-07-15 20:05:46 +03:00
|
|
|
query SetsNonNullable($value: String!) {
|
|
|
|
fieldWithNonNullableStringInput(input: $value)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, ['value' => null]);
|
2017-07-05 13:31:35 +03:00
|
|
|
$expected = [
|
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' =>
|
2018-02-13 18:51:44 +03:00
|
|
|
'Variable "$value" got invalid value null; ' .
|
2018-02-16 18:19:25 +03:00
|
|
|
'Expected non-nullable type String! not to be null.',
|
2017-08-07 22:00:17 +03:00
|
|
|
'locations' => [['line' => 2, 'column' => 31]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'category' => 'graphql',
|
|
|
|
],
|
|
|
|
],
|
2017-07-05 13:31:35 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows non-nullable inputs to be set to a value in a variable')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsNonNullableInputsToBeSetToAValueInAVariable() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2015-07-15 20:05:46 +03:00
|
|
|
query SetsNonNullable($value: String!) {
|
|
|
|
fieldWithNonNullableStringInput(input: $value)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, ['value' => 'a']);
|
2015-07-15 20:05:46 +03:00
|
|
|
$expected = ['data' => ['fieldWithNonNullableStringInput' => '"a"']];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows non-nullable inputs to be set to a value directly')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsNonNullableInputsToBeSetToAValueDirectly() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery('
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
|
|
|
fieldWithNonNullableStringInput(input: "a")
|
|
|
|
}
|
2018-08-22 14:40:15 +03:00
|
|
|
');
|
2015-07-15 20:05:46 +03:00
|
|
|
$expected = ['data' => ['fieldWithNonNullableStringInput' => '"a"']];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('reports error for missing non-nullable inputs')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testReportsErrorForMissingNonNullableInputs() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery('
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
|
|
|
fieldWithNonNullableStringInput
|
|
|
|
}
|
2018-08-22 14:40:15 +03:00
|
|
|
');
|
2016-11-19 00:15:40 +03:00
|
|
|
$expected = [
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['fieldWithNonNullableStringInput' => null],
|
2016-11-19 00:15:40 +03:00
|
|
|
'errors' => [[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' => 'Argument "input" of required type "String!" was not provided.',
|
|
|
|
'locations' => [['line' => 3, 'column' => 9]],
|
|
|
|
'path' => ['fieldWithNonNullableStringInput'],
|
|
|
|
'category' => 'graphql',
|
|
|
|
],
|
|
|
|
],
|
2016-11-19 00:15:40 +03:00
|
|
|
];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2016-11-19 00:15:40 +03:00
|
|
|
}
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
// Describe: Handles lists and nullability
|
|
|
|
|
2017-09-20 14:40:45 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('reports error for array passed into string input')
|
2017-09-20 14:40:45 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testReportsErrorForArrayPassedIntoStringInput() : void
|
2017-09-20 14:40:45 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2017-09-20 14:40:45 +03:00
|
|
|
query SetsNonNullable($value: String!) {
|
|
|
|
fieldWithNonNullableStringInput(input: $value)
|
|
|
|
}
|
|
|
|
';
|
|
|
|
$variables = ['value' => [1, 2, 3]];
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, $variables);
|
2017-09-20 14:40:45 +03:00
|
|
|
|
|
|
|
$expected = [
|
|
|
|
'errors' => [[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' =>
|
2018-02-13 18:51:44 +03:00
|
|
|
'Variable "$value" got invalid value [1,2,3]; Expected type ' .
|
|
|
|
'String; String cannot represent an array value: [1,2,3]',
|
2018-09-01 18:07:06 +03:00
|
|
|
'category' => 'graphql',
|
2017-09-20 14:40:45 +03:00
|
|
|
'locations' => [
|
2018-09-01 18:07:06 +03:00
|
|
|
['line' => 2, 'column' => 31],
|
|
|
|
],
|
|
|
|
],
|
|
|
|
],
|
2017-09-20 14:40:45 +03:00
|
|
|
];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2017-09-20 14:40:45 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('serializing an array via GraphQLString throws TypeError')
|
2017-09-20 14:40:45 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testSerializingAnArrayViaGraphQLStringThrowsTypeError() : void
|
2017-09-20 14:40:45 +03:00
|
|
|
{
|
2018-07-29 18:43:10 +03:00
|
|
|
$this->expectException(Error::class);
|
|
|
|
$this->expectExceptionMessage('String cannot represent non scalar value: [1,2,3]');
|
2017-09-20 14:40:45 +03:00
|
|
|
Type::string()->serialize([1, 2, 3]);
|
|
|
|
}
|
|
|
|
|
2016-11-19 00:15:40 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('reports error for non-provided variables for non-nullable inputs')
|
2016-11-19 00:15:40 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testReportsErrorForNonProvidedVariablesForNonNullableInputs() : void
|
2016-11-19 00:15:40 +03:00
|
|
|
{
|
|
|
|
// Note: this test would typically fail validation before encountering
|
|
|
|
// this execution error, however for queries which previously validated
|
|
|
|
// and are being run against a new schema which have introduced a breaking
|
|
|
|
// change to make a formerly non-required argument required, this asserts
|
|
|
|
// failure before allowing the underlying code to receive a non-null value.
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery('
|
2016-11-19 00:15:40 +03:00
|
|
|
{
|
|
|
|
fieldWithNonNullableStringInput(input: $foo)
|
|
|
|
}
|
2018-08-22 14:40:15 +03:00
|
|
|
');
|
2016-11-19 00:15:40 +03:00
|
|
|
$expected = [
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['fieldWithNonNullableStringInput' => null],
|
2016-11-19 00:15:40 +03:00
|
|
|
'errors' => [[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' =>
|
2016-11-19 00:15:40 +03:00
|
|
|
'Argument "input" of required type "String!" was provided the ' .
|
|
|
|
'variable "$foo" which was not provided a runtime value.',
|
|
|
|
'locations' => [['line' => 3, 'column' => 48]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'path' => ['fieldWithNonNullableStringInput'],
|
|
|
|
'category' => 'graphql',
|
|
|
|
],
|
|
|
|
],
|
2016-11-19 00:15:40 +03:00
|
|
|
];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows lists to be null')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsListsToBeNull() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2015-07-15 20:05:46 +03:00
|
|
|
query q($input:[String]) {
|
|
|
|
list(input: $input)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, ['input' => null]);
|
2015-08-17 17:01:55 +03:00
|
|
|
$expected = ['data' => ['list' => null]];
|
2015-07-15 20:05:46 +03:00
|
|
|
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows lists to contain values')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsListsToContainValues() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2015-07-15 20:05:46 +03:00
|
|
|
query q($input:[String]) {
|
|
|
|
list(input: $input)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, ['input' => ['A']]);
|
2015-07-15 20:05:46 +03:00
|
|
|
$expected = ['data' => ['list' => '["A"]']];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows lists to contain null')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsListsToContainNull() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2015-07-15 20:05:46 +03:00
|
|
|
query q($input:[String]) {
|
|
|
|
list(input: $input)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, ['input' => ['A', null, 'B']]);
|
2015-07-15 20:05:46 +03:00
|
|
|
$expected = ['data' => ['list' => '["A",null,"B"]']];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('does not allow non-null lists to be null')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testDoesNotAllowNonNullListsToBeNull() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2015-07-15 20:05:46 +03:00
|
|
|
query q($input:[String]!) {
|
|
|
|
nnList(input: $input)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, ['input' => null]);
|
2017-07-05 13:31:35 +03:00
|
|
|
$expected = [
|
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' =>
|
2018-02-13 18:51:44 +03:00
|
|
|
'Variable "$input" got invalid value null; ' .
|
2018-02-16 18:19:25 +03:00
|
|
|
'Expected non-nullable type [String]! not to be null.',
|
2017-08-07 22:00:17 +03:00
|
|
|
'locations' => [['line' => 2, 'column' => 17]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'category' => 'graphql',
|
|
|
|
],
|
|
|
|
],
|
2017-07-05 13:31:35 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows non-null lists to contain values')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsNonNullListsToContainValues() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2015-07-15 20:05:46 +03:00
|
|
|
query q($input:[String]!) {
|
|
|
|
nnList(input: $input)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, ['input' => ['A']]);
|
2015-07-15 20:05:46 +03:00
|
|
|
$expected = ['data' => ['nnList' => '["A"]']];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows non-null lists to contain null')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsNonNullListsToContainNull() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2015-07-15 20:05:46 +03:00
|
|
|
query q($input:[String]!) {
|
|
|
|
nnList(input: $input)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, ['input' => ['A', null, 'B']]);
|
2015-07-15 20:05:46 +03:00
|
|
|
$expected = ['data' => ['nnList' => '["A",null,"B"]']];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows lists of non-nulls to be null')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsListsOfNonNullsToBeNull() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2015-07-15 20:05:46 +03:00
|
|
|
query q($input:[String!]) {
|
|
|
|
listNN(input: $input)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, ['input' => null]);
|
2015-08-17 17:01:55 +03:00
|
|
|
$expected = ['data' => ['listNN' => null]];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows lists of non-nulls to contain values')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsListsOfNonNullsToContainValues() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2015-07-15 20:05:46 +03:00
|
|
|
query q($input:[String!]) {
|
|
|
|
listNN(input: $input)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, ['input' => ['A']]);
|
2015-07-15 20:05:46 +03:00
|
|
|
$expected = ['data' => ['listNN' => '["A"]']];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('does not allow lists of non-nulls to contain null')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testDoesNotAllowListsOfNonNullsToContainNull() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2015-07-15 20:05:46 +03:00
|
|
|
query q($input:[String!]) {
|
|
|
|
listNN(input: $input)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, ['input' => ['A', null, 'B']]);
|
2017-07-05 13:31:35 +03:00
|
|
|
$expected = [
|
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' =>
|
2018-02-13 18:51:44 +03:00
|
|
|
'Variable "$input" got invalid value ["A",null,"B"]; ' .
|
2018-02-16 18:19:25 +03:00
|
|
|
'Expected non-nullable type String! not to be null at value[1].',
|
2018-09-01 18:07:06 +03:00
|
|
|
'locations' => [['line' => 2, 'column' => 17]],
|
|
|
|
'category' => 'graphql',
|
|
|
|
],
|
|
|
|
],
|
2017-07-05 13:31:35 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('does not allow non-null lists of non-nulls to be null')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testDoesNotAllowNonNullListsOfNonNullsToBeNull() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2015-07-15 20:05:46 +03:00
|
|
|
query q($input:[String!]!) {
|
|
|
|
nnListNN(input: $input)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, ['input' => null]);
|
2017-07-05 13:31:35 +03:00
|
|
|
$expected = [
|
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' =>
|
2018-02-13 18:51:44 +03:00
|
|
|
'Variable "$input" got invalid value null; ' .
|
2018-02-16 18:19:25 +03:00
|
|
|
'Expected non-nullable type [String!]! not to be null.',
|
2018-09-01 18:07:06 +03:00
|
|
|
'locations' => [['line' => 2, 'column' => 17]],
|
|
|
|
'category' => 'graphql',
|
|
|
|
],
|
|
|
|
],
|
2017-07-05 13:31:35 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('allows non-null lists of non-nulls to contain values')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testAllowsNonNullListsOfNonNullsToContainValues() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2015-07-15 20:05:46 +03:00
|
|
|
query q($input:[String!]!) {
|
|
|
|
nnListNN(input: $input)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, ['input' => ['A']]);
|
2015-07-15 20:05:46 +03:00
|
|
|
$expected = ['data' => ['nnListNN' => '["A"]']];
|
2018-08-22 14:40:15 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
// Describe: Execute: Uses argument default values
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('does not allow non-null lists of non-nulls to contain null')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testDoesNotAllowNonNullListsOfNonNullsToContainNull() : void
|
2015-07-15 20:05:46 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2015-07-15 20:05:46 +03:00
|
|
|
query q($input:[String!]!) {
|
|
|
|
nnListNN(input: $input)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, ['input' => ['A', null, 'B']]);
|
2017-07-05 13:31:35 +03:00
|
|
|
$expected = [
|
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' =>
|
2018-02-13 18:51:44 +03:00
|
|
|
'Variable "$input" got invalid value ["A",null,"B"]; ' .
|
2018-02-16 18:19:25 +03:00
|
|
|
'Expected non-nullable type String! not to be null at value[1].',
|
2018-09-01 18:07:06 +03:00
|
|
|
'locations' => [['line' => 2, 'column' => 17]],
|
|
|
|
'category' => 'graphql',
|
|
|
|
],
|
|
|
|
],
|
2017-07-05 13:31:35 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|
|
|
|
|
2016-05-02 00:42:05 +03:00
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('does not allow invalid types to be used as values')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testDoesNotAllowInvalidTypesToBeUsedAsValues() : void
|
2016-05-02 00:42:05 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2016-05-02 00:42:05 +03:00
|
|
|
query q($input: TestType!) {
|
|
|
|
fieldWithObjectInput(input: $input)
|
|
|
|
}
|
|
|
|
';
|
2018-09-01 18:07:06 +03:00
|
|
|
$vars = ['input' => ['list' => ['A', 'B']]];
|
|
|
|
$result = $this->executeQuery($doc, $vars);
|
2017-07-05 13:31:35 +03:00
|
|
|
$expected = [
|
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' =>
|
2017-07-05 13:31:35 +03:00
|
|
|
'Variable "$input" expected value of type "TestType!" which cannot ' .
|
|
|
|
'be used as an input type.',
|
2017-08-07 22:00:17 +03:00
|
|
|
'locations' => [['line' => 2, 'column' => 25]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'category' => 'graphql',
|
|
|
|
],
|
|
|
|
],
|
2017-07-05 13:31:35 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2016-05-02 00:42:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('does not allow unknown types to be used as values')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testDoesNotAllowUnknownTypesToBeUsedAsValues() : void
|
2016-05-02 00:42:05 +03:00
|
|
|
{
|
2018-09-01 18:07:06 +03:00
|
|
|
$doc = '
|
2016-05-02 00:42:05 +03:00
|
|
|
query q($input: UnknownType!) {
|
|
|
|
fieldWithObjectInput(input: $input)
|
|
|
|
}
|
|
|
|
';
|
|
|
|
$vars = ['input' => 'whoknows'];
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
$result = $this->executeQuery($doc, $vars);
|
2017-07-05 13:31:35 +03:00
|
|
|
$expected = [
|
|
|
|
'errors' => [
|
|
|
|
[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' =>
|
2017-07-05 13:31:35 +03:00
|
|
|
'Variable "$input" expected value of type "UnknownType!" which ' .
|
|
|
|
'cannot be used as an input type.',
|
2017-08-07 22:00:17 +03:00
|
|
|
'locations' => [['line' => 2, 'column' => 25]],
|
2018-09-01 18:07:06 +03:00
|
|
|
'category' => 'graphql',
|
|
|
|
],
|
|
|
|
],
|
2017-07-05 13:31:35 +03:00
|
|
|
];
|
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2016-05-02 00:42:05 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('when no argument provided')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testWhenNoArgumentProvided() : void
|
2016-05-02 00:42:05 +03:00
|
|
|
{
|
2018-08-22 14:40:15 +03:00
|
|
|
$result = $this->executeQuery('{
|
2016-05-02 00:42:05 +03:00
|
|
|
fieldWithDefaultArgumentValue
|
|
|
|
}');
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
['data' => ['fieldWithDefaultArgumentValue' => '"Hello World"']],
|
2018-08-22 14:40:15 +03:00
|
|
|
$result->toArray()
|
2016-05-02 00:42:05 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('when omitted variable provided')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testWhenOmittedVariableProvided() : void
|
2016-05-02 00:42:05 +03:00
|
|
|
{
|
2018-08-22 14:40:15 +03:00
|
|
|
$result = $this->executeQuery('query optionalVariable($optional: String) {
|
2016-05-02 00:42:05 +03:00
|
|
|
fieldWithDefaultArgumentValue(input: $optional)
|
|
|
|
}');
|
|
|
|
|
|
|
|
$this->assertEquals(
|
|
|
|
['data' => ['fieldWithDefaultArgumentValue' => '"Hello World"']],
|
2018-08-22 14:40:15 +03:00
|
|
|
$result->toArray()
|
2016-05-02 00:42:05 +03:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
2018-08-31 11:55:14 +03:00
|
|
|
* @see it('not when argument cannot be coerced')
|
2016-05-02 00:42:05 +03:00
|
|
|
*/
|
2018-08-31 12:07:29 +03:00
|
|
|
public function testNotWhenArgumentCannotBeCoerced() : void
|
2016-05-02 00:42:05 +03:00
|
|
|
{
|
2018-08-22 14:40:15 +03:00
|
|
|
$result = $this->executeQuery('{
|
2016-05-02 00:42:05 +03:00
|
|
|
fieldWithDefaultArgumentValue(input: WRONG_TYPE)
|
|
|
|
}');
|
|
|
|
|
2016-11-19 00:15:40 +03:00
|
|
|
$expected = [
|
2018-09-01 18:07:06 +03:00
|
|
|
'data' => ['fieldWithDefaultArgumentValue' => null],
|
2016-11-19 00:15:40 +03:00
|
|
|
'errors' => [[
|
2018-09-01 18:07:06 +03:00
|
|
|
'message' =>
|
2018-02-15 23:29:14 +03:00
|
|
|
'Argument "input" has invalid value WRONG_TYPE.',
|
2018-09-01 18:07:06 +03:00
|
|
|
'locations' => [['line' => 2, 'column' => 50]],
|
|
|
|
'path' => ['fieldWithDefaultArgumentValue'],
|
|
|
|
'category' => 'graphql',
|
|
|
|
],
|
2016-05-02 00:42:05 +03:00
|
|
|
],
|
2018-08-22 14:40:15 +03:00
|
|
|
];
|
|
|
|
|
2018-09-01 18:07:06 +03:00
|
|
|
$this->assertEquals($expected, $result->toArray());
|
2018-08-22 14:40:15 +03:00
|
|
|
}
|
2015-07-15 20:05:46 +03:00
|
|
|
}
|