graphql-php/tests/Executor/ListsTest.php

699 lines
20 KiB
PHP
Raw Normal View History

2015-07-15 20:05:46 +03:00
<?php
2016-11-27 00:28:46 +03:00
2018-09-01 18:07:06 +03:00
declare(strict_types=1);
2016-04-09 10:36:53 +03:00
namespace GraphQL\Tests\Executor;
2015-07-15 20:05:46 +03:00
2016-12-03 00:11:14 +03:00
use GraphQL\Deferred;
use GraphQL\Error\UserError;
2016-04-09 10:36:53 +03:00
use GraphQL\Executor\Executor;
2015-07-15 20:05:46 +03:00
use GraphQL\Language\Parser;
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;
2015-07-15 20:05:46 +03:00
2018-07-29 18:43:10 +03:00
class ListsTest extends TestCase
2015-07-15 20:05:46 +03:00
{
// Describe: Execute: Handles list nullability
/**
* [T]
*/
public function testHandlesNullableListsWithArray() : void
2015-07-15 20:05:46 +03:00
{
// Contains values
2016-11-27 00:28:46 +03:00
$this->checkHandlesNullableLists(
2018-09-01 18:07:06 +03:00
[1, 2],
['data' => ['nest' => ['test' => [1, 2]]]]
);
// Contains null
2016-11-27 00:28:46 +03:00
$this->checkHandlesNullableLists(
2018-09-01 18:07:06 +03:00
[1, null, 2],
['data' => ['nest' => ['test' => [1, null, 2]]]]
);
// Returns null
2016-11-27 00:28:46 +03:00
$this->checkHandlesNullableLists(
null,
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => null]]]
);
2015-07-15 20:05:46 +03:00
}
2018-09-01 18:07:06 +03:00
private function checkHandlesNullableLists($testData, $expected)
{
$testType = Type::listOf(Type::int());
$this->check($testType, $testData, $expected);
}
private function check($testType, $testData, $expected, $debug = false)
{
$data = ['test' => $testData];
$dataType = null;
$dataType = new ObjectType([
'name' => 'DataType',
'fields' => function () use (&$testType, &$dataType, $data) {
return [
'test' => ['type' => $testType],
'nest' => [
'type' => $dataType,
'resolve' => function () use ($data) {
return $data;
},
],
];
},
]);
$schema = new Schema(['query' => $dataType]);
$ast = Parser::parse('{ nest { test } }');
$result = Executor::execute($schema, $ast, $data);
$this->assertArraySubset($expected, $result->toArray($debug));
}
/**
* [T]
2016-11-27 00:28:46 +03:00
*/
public function testHandlesNullableListsWithPromiseArray() : void
2016-11-27 00:28:46 +03:00
{
// Contains values
$this->checkHandlesNullableLists(
2018-09-01 18:07:06 +03:00
new Deferred(function () {
return [1, 2];
2016-12-03 00:11:14 +03:00
}),
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => [1, 2]]]]
2016-11-27 00:28:46 +03:00
);
// Contains null
$this->checkHandlesNullableLists(
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return [1, null, 2];
}),
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => [1, null, 2]]]]
2016-11-27 00:28:46 +03:00
);
// Returns null
$this->checkHandlesNullableLists(
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return null;
}),
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => null]]]
2016-11-27 00:28:46 +03:00
);
// Rejected
$this->checkHandlesNullableLists(
function () {
2016-12-03 00:11:14 +03:00
return new Deferred(function () {
throw new UserError('bad');
2016-12-03 00:11:14 +03:00
});
2016-11-27 00:28:46 +03:00
},
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => ['test' => null]],
2016-11-27 00:28:46 +03:00
'errors' => [
[
2018-09-01 18:07:06 +03:00
'message' => 'bad',
2016-11-27 00:28:46 +03:00
'locations' => [['line' => 1, 'column' => 10]],
2018-09-01 18:07:06 +03:00
'path' => ['nest', 'test'],
],
],
2016-11-27 00:28:46 +03:00
]
);
}
/**
* [T]
*/
public function testHandlesNullableListsWithArrayPromise() : void
2015-07-15 20:05:46 +03:00
{
2016-11-27 00:28:46 +03:00
// Contains values
$this->checkHandlesNullableLists(
2016-12-03 00:11:14 +03:00
[
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 1;
}),
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 2;
2018-09-01 18:07:06 +03:00
}),
],
['data' => ['nest' => ['test' => [1, 2]]]]
2016-11-27 00:28:46 +03:00
);
// Contains null
$this->checkHandlesNullableLists(
2016-12-03 00:11:14 +03:00
[
2018-09-01 18:07:06 +03:00
new Deferred(function () {
return 1;
}),
new Deferred(function () {
return null;
}),
new Deferred(function () {
return 2;
}),
2016-12-03 00:11:14 +03:00
],
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => [1, null, 2]]]]
2016-11-27 00:28:46 +03:00
);
// Returns null
$this->checkHandlesNullableLists(
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:23:21 +03:00
return null;
}),
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => null]]]
2016-11-27 00:28:46 +03:00
);
// Contains reject
$this->checkHandlesNullableLists(
function () {
2016-12-03 00:11:14 +03:00
return [
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 1;
}),
2018-09-01 18:07:06 +03:00
new Deferred(function () {
throw new UserError('bad');
2016-12-03 00:11:14 +03:00
}),
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 2;
2018-09-01 18:07:06 +03:00
}),
2016-12-03 00:11:14 +03:00
];
2016-11-27 00:28:46 +03:00
},
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => ['test' => [1, null, 2]]],
2016-11-27 00:28:46 +03:00
'errors' => [
[
2018-09-01 18:07:06 +03:00
'message' => 'bad',
2016-11-27 00:28:46 +03:00
'locations' => [['line' => 1, 'column' => 10]],
2018-09-01 18:07:06 +03:00
'path' => ['nest', 'test', 1],
],
],
2016-11-27 00:28:46 +03:00
]
);
}
2016-11-27 00:28:46 +03:00
/**
* [T]!
2016-11-27 00:28:46 +03:00
*/
public function testHandlesNonNullableListsWithArray() : void
2016-11-27 00:28:46 +03:00
{
// Contains values
2016-11-27 00:28:46 +03:00
$this->checkHandlesNonNullableLists(
2018-09-01 18:07:06 +03:00
[1, 2],
['data' => ['nest' => ['test' => [1, 2]]]]
);
// Contains null
2016-11-27 00:28:46 +03:00
$this->checkHandlesNonNullableLists(
2018-09-01 18:07:06 +03:00
[1, null, 2],
['data' => ['nest' => ['test' => [1, null, 2]]]]
);
// Returns null
2016-11-27 00:28:46 +03:00
$this->checkHandlesNonNullableLists(
null,
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => null],
'errors' => [
[
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
2018-09-01 18:07:06 +03:00
'locations' => [['line' => 1, 'column' => 10]],
],
],
],
true
);
2015-07-15 20:05:46 +03:00
}
2018-09-01 18:07:06 +03:00
private function checkHandlesNonNullableLists($testData, $expected, $debug = false)
{
$testType = Type::nonNull(Type::listOf(Type::int()));
$this->check($testType, $testData, $expected, $debug);
}
/**
* [T]!
2016-11-27 00:28:46 +03:00
*/
public function testHandlesNonNullableListsWithPromiseArray() : void
2016-11-27 00:28:46 +03:00
{
// Contains values
$this->checkHandlesNonNullableLists(
2018-09-01 18:07:06 +03:00
new Deferred(function () {
return [1, 2];
2016-12-03 00:11:14 +03:00
}),
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => [1, 2]]]]
2016-11-27 00:28:46 +03:00
);
// Contains null
$this->checkHandlesNonNullableLists(
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return [1, null, 2];
}),
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => [1, null, 2]]]]
2016-11-27 00:28:46 +03:00
);
// Returns null
$this->checkHandlesNonNullableLists(
null,
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => null],
2016-11-27 00:28:46 +03:00
'errors' => [
[
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
2018-09-01 18:07:06 +03:00
'locations' => [['line' => 1, 'column' => 10]],
],
],
],
true
2016-11-27 00:28:46 +03:00
);
// Rejected
$this->checkHandlesNonNullableLists(
function () {
2018-09-01 18:07:06 +03:00
return new Deferred(function () {
throw new UserError('bad');
2016-12-03 00:11:14 +03:00
});
2016-11-27 00:28:46 +03:00
},
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => null],
2016-11-27 00:28:46 +03:00
'errors' => [
[
2018-09-01 18:07:06 +03:00
'message' => 'bad',
2016-11-27 00:28:46 +03:00
'locations' => [['line' => 1, 'column' => 10]],
2018-09-01 18:07:06 +03:00
'path' => ['nest', 'test'],
],
],
2016-11-27 00:28:46 +03:00
]
);
}
/**
* [T]!
*/
public function testHandlesNonNullableListsWithArrayPromise() : void
2015-07-15 20:05:46 +03:00
{
2016-11-27 00:28:46 +03:00
// Contains values
$this->checkHandlesNonNullableLists(
2016-12-03 00:11:14 +03:00
[
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 1;
}),
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 2;
2018-09-01 18:07:06 +03:00
}),
2016-12-03 00:11:14 +03:00
],
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => [1, 2]]]]
2016-11-27 00:28:46 +03:00
);
// Contains null
$this->checkHandlesNonNullableLists(
2016-12-03 00:11:14 +03:00
[
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 1;
}),
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return null;
}),
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 2;
2018-09-01 18:07:06 +03:00
}),
2016-12-03 00:11:14 +03:00
],
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => [1, null, 2]]]]
2016-11-27 00:28:46 +03:00
);
2016-11-27 00:28:46 +03:00
// Contains reject
$this->checkHandlesNonNullableLists(
function () {
2016-12-03 00:11:14 +03:00
return [
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 1;
}),
2018-09-01 18:07:06 +03:00
new Deferred(function () {
throw new UserError('bad');
2016-12-03 00:11:14 +03:00
}),
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 2;
2018-09-01 18:07:06 +03:00
}),
2016-12-03 00:11:14 +03:00
];
2016-11-27 00:28:46 +03:00
},
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => ['test' => [1, null, 2]]],
2016-11-27 00:28:46 +03:00
'errors' => [
[
2018-09-01 18:07:06 +03:00
'message' => 'bad',
2016-11-27 00:28:46 +03:00
'locations' => [['line' => 1, 'column' => 10]],
2018-09-01 18:07:06 +03:00
'path' => ['nest', 'test', 1],
],
],
2016-11-27 00:28:46 +03:00
]
);
}
/**
* [T!]
2016-11-27 00:28:46 +03:00
*/
public function testHandlesListOfNonNullsWithArray() : void
2016-11-27 00:28:46 +03:00
{
// Contains values
2016-11-27 00:28:46 +03:00
$this->checkHandlesListOfNonNulls(
2018-09-01 18:07:06 +03:00
[1, 2],
['data' => ['nest' => ['test' => [1, 2]]]]
);
// Contains null
2016-11-27 00:28:46 +03:00
$this->checkHandlesListOfNonNulls(
2018-09-01 18:07:06 +03:00
[1, null, 2],
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => ['test' => null]],
'errors' => [
[
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
2018-09-01 18:07:06 +03:00
'locations' => [['line' => 1, 'column' => 10]],
],
],
],
true
);
// Returns null
2016-11-27 00:28:46 +03:00
$this->checkHandlesListOfNonNulls(
null,
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => null]]]
);
2015-07-15 20:05:46 +03:00
}
2018-09-01 18:07:06 +03:00
private function checkHandlesListOfNonNulls($testData, $expected, $debug = false)
{
$testType = Type::listOf(Type::nonNull(Type::int()));
$this->check($testType, $testData, $expected, $debug);
}
/**
* [T!]
*/
public function testHandlesListOfNonNullsWithPromiseArray() : void
2015-07-15 20:05:46 +03:00
{
2016-11-27 00:28:46 +03:00
// Contains values
$this->checkHandlesListOfNonNulls(
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return [1, 2];
}),
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => [1, 2]]]]
2016-11-27 00:28:46 +03:00
);
2016-11-27 00:28:46 +03:00
// Contains null
$this->checkHandlesListOfNonNulls(
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return [1, null, 2];
}),
2016-11-27 00:28:46 +03:00
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => ['test' => null]],
2016-11-27 00:28:46 +03:00
'errors' => [
[
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
2018-09-01 18:07:06 +03:00
'locations' => [['line' => 1, 'column' => 10]],
],
],
],
true
2016-11-27 00:28:46 +03:00
);
// Returns null
$this->checkHandlesListOfNonNulls(
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:23:21 +03:00
return null;
}),
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => null]]]
2016-11-27 00:28:46 +03:00
);
// Rejected
$this->checkHandlesListOfNonNulls(
function () {
2018-09-01 18:07:06 +03:00
return new Deferred(function () {
throw new UserError('bad');
2016-12-03 00:11:14 +03:00
});
2016-11-27 00:28:46 +03:00
},
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => ['test' => null]],
2016-11-27 00:28:46 +03:00
'errors' => [
[
2018-09-01 18:07:06 +03:00
'message' => 'bad',
2016-11-27 00:28:46 +03:00
'locations' => [['line' => 1, 'column' => 10]],
2018-09-01 18:07:06 +03:00
'path' => ['nest', 'test'],
],
],
2016-11-27 00:28:46 +03:00
]
);
}
/**
* [T]!
2016-11-27 00:28:46 +03:00
*/
public function testHandlesListOfNonNullsWithArrayPromise() : void
2016-11-27 00:28:46 +03:00
{
// Contains values
$this->checkHandlesListOfNonNulls(
2016-12-03 00:11:14 +03:00
[
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 1;
}),
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 2;
2018-09-01 18:07:06 +03:00
}),
2016-12-03 00:11:14 +03:00
],
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => [1, 2]]]]
2016-11-27 00:28:46 +03:00
);
// Contains null
$this->checkHandlesListOfNonNulls(
2016-12-03 00:23:21 +03:00
[
2018-09-01 18:07:06 +03:00
new Deferred(function () {
return 1;
}),
new Deferred(function () {
return null;
}),
new Deferred(function () {
return 2;
}),
2016-12-03 00:23:21 +03:00
],
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => null]]]
2016-11-27 00:28:46 +03:00
);
// Contains reject
$this->checkHandlesListOfNonNulls(
function () {
2016-12-03 00:11:14 +03:00
return [
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 1;
}),
2018-09-01 18:07:06 +03:00
new Deferred(function () {
throw new UserError('bad');
2016-12-03 00:11:14 +03:00
}),
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 2;
2018-09-01 18:07:06 +03:00
}),
2016-12-03 00:11:14 +03:00
];
2016-11-27 00:28:46 +03:00
},
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => ['test' => null]],
2016-11-27 00:28:46 +03:00
'errors' => [
[
2018-09-01 18:07:06 +03:00
'message' => 'bad',
2016-11-27 00:28:46 +03:00
'locations' => [['line' => 1, 'column' => 10]],
2018-09-01 18:07:06 +03:00
'path' => ['nest', 'test', 1],
],
],
2016-11-27 00:28:46 +03:00
]
);
}
/**
* [T!]!
2016-11-27 00:28:46 +03:00
*/
public function testHandlesNonNullListOfNonNullsWithArray() : void
2016-11-27 00:28:46 +03:00
{
// Contains values
2016-11-27 00:28:46 +03:00
$this->checkHandlesNonNullListOfNonNulls(
2018-09-01 18:07:06 +03:00
[1, 2],
['data' => ['nest' => ['test' => [1, 2]]]]
);
// Contains null
2016-11-27 00:28:46 +03:00
$this->checkHandlesNonNullListOfNonNulls(
2018-09-01 18:07:06 +03:00
[1, null, 2],
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => null],
'errors' => [
[
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
2018-09-01 18:07:06 +03:00
'locations' => [['line' => 1, 'column' => 10]],
],
],
],
true
);
// Returns null
2016-11-27 00:28:46 +03:00
$this->checkHandlesNonNullListOfNonNulls(
null,
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => null],
'errors' => [
[
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
2018-09-01 18:07:06 +03:00
'locations' => [['line' => 1, 'column' => 10]],
],
],
],
true
);
2015-07-15 20:05:46 +03:00
}
2016-11-27 00:28:46 +03:00
2018-09-01 18:07:06 +03:00
public function checkHandlesNonNullListOfNonNulls($testData, $expected, $debug = false)
{
$testType = Type::nonNull(Type::listOf(Type::nonNull(Type::int())));
$this->check($testType, $testData, $expected, $debug);
}
2016-11-27 00:28:46 +03:00
/**
* [T!]!
2016-11-27 00:28:46 +03:00
*/
public function testHandlesNonNullListOfNonNullsWithPromiseArray() : void
2016-11-27 00:28:46 +03:00
{
// Contains values
$this->checkHandlesNonNullListOfNonNulls(
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return [1, 2];
}),
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => [1, 2]]]]
2016-11-27 00:28:46 +03:00
);
// Contains null
$this->checkHandlesNonNullListOfNonNulls(
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return [1, null, 2];
}),
2016-11-27 00:28:46 +03:00
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => null],
2016-11-27 00:28:46 +03:00
'errors' => [
[
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
2018-09-01 18:07:06 +03:00
'locations' => [['line' => 1, 'column' => 10]],
],
],
],
true
2016-11-27 00:28:46 +03:00
);
// Returns null
$this->checkHandlesNonNullListOfNonNulls(
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return null;
}),
2016-11-27 00:28:46 +03:00
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => null],
2016-11-27 00:28:46 +03:00
'errors' => [
[
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
2018-09-01 18:07:06 +03:00
'locations' => [['line' => 1, 'column' => 10]],
],
],
],
true
2016-11-27 00:28:46 +03:00
);
// Rejected
$this->checkHandlesNonNullListOfNonNulls(
function () {
2018-09-01 18:07:06 +03:00
return new Deferred(function () {
throw new UserError('bad');
2016-12-03 00:11:14 +03:00
});
2016-11-27 00:28:46 +03:00
},
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => null],
2016-11-27 00:28:46 +03:00
'errors' => [
[
2018-09-01 18:07:06 +03:00
'message' => 'bad',
2016-11-27 00:28:46 +03:00
'locations' => [['line' => 1, 'column' => 10]],
2018-09-01 18:07:06 +03:00
'path' => ['nest', 'test'],
],
],
2016-11-27 00:28:46 +03:00
]
);
}
/**
* [T!]!
2016-11-27 00:28:46 +03:00
*/
public function testHandlesNonNullListOfNonNullsWithArrayPromise() : void
2016-11-27 00:28:46 +03:00
{
// Contains values
$this->checkHandlesNonNullListOfNonNulls(
2016-12-03 00:11:14 +03:00
[
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 1;
}),
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 2;
2018-09-01 18:07:06 +03:00
}),
2016-12-03 00:11:14 +03:00
],
2018-09-01 18:07:06 +03:00
['data' => ['nest' => ['test' => [1, 2]]]]
2016-11-27 00:28:46 +03:00
);
// Contains null
$this->checkHandlesNonNullListOfNonNulls(
2016-12-03 00:11:14 +03:00
[
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 1;
}),
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return null;
}),
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 2;
2018-09-01 18:07:06 +03:00
}),
2016-12-03 00:11:14 +03:00
],
2016-11-27 00:28:46 +03:00
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => null],
2016-11-27 00:28:46 +03:00
'errors' => [
[
'debugMessage' => 'Cannot return null for non-nullable field DataType.test.',
2018-09-01 18:07:06 +03:00
'locations' => [['line' => 1, 'column' => 10]],
],
],
],
true
2016-11-27 00:28:46 +03:00
);
// Contains reject
$this->checkHandlesNonNullListOfNonNulls(
function () {
2016-12-03 00:11:14 +03:00
return [
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 1;
}),
2018-09-01 18:07:06 +03:00
new Deferred(function () {
throw new UserError('bad');
2016-12-03 00:11:14 +03:00
}),
2018-09-01 18:07:06 +03:00
new Deferred(function () {
2016-12-03 00:11:14 +03:00
return 2;
2018-09-01 18:07:06 +03:00
}),
2016-12-03 00:11:14 +03:00
];
2016-11-27 00:28:46 +03:00
},
[
2018-09-01 18:07:06 +03:00
'data' => ['nest' => null],
2016-11-27 00:28:46 +03:00
'errors' => [
[
2018-09-01 18:07:06 +03:00
'message' => 'bad',
2016-11-27 00:28:46 +03:00
'locations' => [['line' => 1, 'column' => 10]],
2018-09-01 18:07:06 +03:00
'path' => ['nest', 'test'],
],
],
2016-11-27 00:28:46 +03:00
]
);
}
2016-04-09 10:36:53 +03:00
}