graphql-php/tests/Executor/NonNullTest.php

805 lines
23 KiB
PHP
Raw Normal View History

2015-07-15 20:05:46 +03:00
<?php
2016-11-26 22:48:01 +03:00
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;
use GraphQL\Error\FormattedError;
2015-07-15 20:05:46 +03:00
use GraphQL\Language\Parser;
use GraphQL\Language\SourceLocation;
use GraphQL\Type\Schema;
2015-07-15 20:05:46 +03:00
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
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 NonNullTest extends TestCase
2015-07-15 20:05:46 +03:00
{
/** @var \Exception */
2015-07-15 20:05:46 +03:00
public $syncError;
/** @var \Exception */
public $syncNonNullError;
2016-11-26 22:48:01 +03:00
/** @var \Exception */
public $promiseError;
/** @var \Exception */
public $promiseNonNullError;
2016-11-26 22:48:01 +03:00
2015-07-15 20:05:46 +03:00
public $throwingData;
public $nullingData;
public $schema;
public function setUp()
{
$this->syncError = new UserError('sync');
$this->syncNonNullError = new UserError('syncNonNull');
$this->promiseError = new UserError('promise');
$this->promiseNonNullError = new UserError('promiseNonNull');
2015-07-15 20:05:46 +03:00
$this->throwingData = [
'sync' => function () {
throw $this->syncError;
},
'syncNonNull' => function () {
throw $this->syncNonNullError;
2015-07-15 20:05:46 +03:00
},
2016-11-26 22:48:01 +03:00
'promise' => function () {
2016-12-03 00:11:14 +03:00
return new Deferred(function () {
2016-11-26 22:48:01 +03:00
throw $this->promiseError;
});
},
'promiseNonNull' => function () {
2016-12-03 00:11:14 +03:00
return new Deferred(function () {
throw $this->promiseNonNullError;
2016-11-26 22:48:01 +03:00
});
},
'syncNest' => function () {
2015-07-15 20:05:46 +03:00
return $this->throwingData;
},
'syncNonNullNest' => function () {
2015-07-15 20:05:46 +03:00
return $this->throwingData;
},
2016-11-26 22:48:01 +03:00
'promiseNest' => function () {
2016-12-03 00:11:14 +03:00
return new Deferred(function () {
return $this->throwingData;
2016-11-26 22:48:01 +03:00
});
},
'promiseNonNullNest' => function () {
2016-12-03 00:11:14 +03:00
return new Deferred(function () {
return $this->throwingData;
2016-11-26 22:48:01 +03:00
});
},
2015-07-15 20:05:46 +03:00
];
$this->nullingData = [
'sync' => function () {
return null;
},
'syncNonNull' => function () {
2015-07-15 20:05:46 +03:00
return null;
},
2016-11-26 22:48:01 +03:00
'promise' => function () {
2016-12-03 00:11:14 +03:00
return new Deferred(function () {
return null;
2016-11-26 22:48:01 +03:00
});
},
'promiseNonNull' => function () {
2016-12-03 00:11:14 +03:00
return new Deferred(function () {
return null;
2016-11-26 22:48:01 +03:00
});
},
'syncNest' => function () {
2015-07-15 20:05:46 +03:00
return $this->nullingData;
},
'syncNonNullNest' => function () {
2015-07-15 20:05:46 +03:00
return $this->nullingData;
},
2016-11-26 22:48:01 +03:00
'promiseNest' => function () {
2016-12-03 00:11:14 +03:00
return new Deferred(function () {
return $this->nullingData;
2016-11-26 22:48:01 +03:00
});
},
'promiseNonNullNest' => function () {
2016-12-03 00:11:14 +03:00
return new Deferred(function () {
return $this->nullingData;
2016-11-26 22:48:01 +03:00
});
},
2015-07-15 20:05:46 +03:00
];
$dataType = new ObjectType([
'name' => 'DataType',
'fields' => function() use (&$dataType) {
return [
'sync' => ['type' => Type::string()],
'syncNonNull' => ['type' => Type::nonNull(Type::string())],
2016-11-26 22:48:01 +03:00
'promise' => Type::string(),
'promiseNonNull' => Type::nonNull(Type::string()),
'syncNest' => $dataType,
'syncNonNullNest' => Type::nonNull($dataType),
2016-11-26 22:48:01 +03:00
'promiseNest' => $dataType,
'promiseNonNullNest' => Type::nonNull($dataType),
];
}
2015-07-15 20:05:46 +03:00
]);
$this->schema = new Schema(['query' => $dataType]);
2015-07-15 20:05:46 +03:00
}
// Execute: handles non-nullable types
/**
* @see it('nulls a nullable field that throws synchronously')
*/
public function testNullsANullableFieldThatThrowsSynchronously() : void
2015-07-15 20:05:46 +03:00
{
$doc = '
query Q {
sync
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => [
'sync' => null,
],
'errors' => [
FormattedError::create(
$this->syncError->getMessage(),
2015-07-15 20:05:46 +03:00
[new SourceLocation(3, 9)]
)
]
];
$this->assertArraySubset($expected, Executor::execute($this->schema, $ast, $this->throwingData, null, [], 'Q')->toArray());
2015-07-15 20:05:46 +03:00
}
public function testNullsANullableFieldThatThrowsInAPromise() : void
2016-11-26 22:48:01 +03:00
{
$doc = '
query Q {
promise
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => [
'promise' => null,
],
'errors' => [
FormattedError::create(
$this->promiseError->getMessage(),
[new SourceLocation(3, 9)]
)
]
];
2016-12-03 00:11:14 +03:00
$this->assertArraySubset($expected, Executor::execute($this->schema, $ast, $this->throwingData, null, [], 'Q')->toArray());
2016-11-26 22:48:01 +03:00
}
public function testNullsASynchronouslyReturnedObjectThatContainsANonNullableFieldThatThrowsSynchronously() : void
2015-07-15 20:05:46 +03:00
{
// nulls a synchronously returned object that contains a non-nullable field that throws synchronously
$doc = '
query Q {
syncNest {
syncNonNull,
2015-07-15 20:05:46 +03:00
}
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => [
'syncNest' => null
2015-07-15 20:05:46 +03:00
],
'errors' => [
FormattedError::create($this->syncNonNullError->getMessage(), [new SourceLocation(4, 11)])
2015-07-15 20:05:46 +03:00
]
];
$this->assertArraySubset($expected, Executor::execute($this->schema, $ast, $this->throwingData, null, [], 'Q')->toArray());
2015-07-15 20:05:46 +03:00
}
public function testNullsAsynchronouslyReturnedObjectThatContainsANonNullableFieldThatThrowsInAPromise() : void
2016-11-26 22:48:01 +03:00
{
$doc = '
query Q {
syncNest {
promiseNonNull,
2016-11-26 22:48:01 +03:00
}
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => [
'syncNest' => null
2016-11-26 22:48:01 +03:00
],
'errors' => [
FormattedError::create($this->promiseNonNullError->getMessage(), [new SourceLocation(4, 11)])
2016-11-26 22:48:01 +03:00
]
];
2016-12-03 00:11:14 +03:00
$this->assertArraySubset($expected, Executor::execute($this->schema, $ast, $this->throwingData, null, [], 'Q')->toArray());
2016-11-26 22:48:01 +03:00
}
public function testNullsAnObjectReturnedInAPromiseThatContainsANonNullableFieldThatThrowsSynchronously() : void
2016-11-26 22:48:01 +03:00
{
$doc = '
query Q {
promiseNest {
syncNonNull,
2016-11-26 22:48:01 +03:00
}
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => [
'promiseNest' => null
],
'errors' => [
FormattedError::create($this->syncNonNullError->getMessage(), [new SourceLocation(4, 11)])
2016-11-26 22:48:01 +03:00
]
];
2016-12-03 00:11:14 +03:00
$this->assertArraySubset($expected, Executor::execute($this->schema, $ast, $this->throwingData, null, [], 'Q')->toArray());
2016-11-26 22:48:01 +03:00
}
public function testNullsAnObjectReturnedInAPromiseThatContainsANonNullableFieldThatThrowsInAPromise() : void
2016-11-26 22:48:01 +03:00
{
$doc = '
query Q {
promiseNest {
promiseNonNull,
2016-11-26 22:48:01 +03:00
}
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => [
'promiseNest' => null
],
'errors' => [
FormattedError::create($this->promiseNonNullError->getMessage(), [new SourceLocation(4, 11)])
2016-11-26 22:48:01 +03:00
]
];
2016-12-03 00:11:14 +03:00
$this->assertArraySubset($expected, Executor::execute($this->schema, $ast, $this->throwingData, null, [], 'Q')->toArray());
2016-11-26 22:48:01 +03:00
}
2016-12-03 00:11:14 +03:00
/**
* @see it('nulls a complex tree of nullable fields that throw')
2016-12-03 00:11:14 +03:00
*/
public function testNullsAComplexTreeOfNullableFieldsThatThrow() : void
2015-07-15 20:05:46 +03:00
{
$doc = '
query Q {
syncNest {
2015-07-15 20:05:46 +03:00
sync
2016-11-26 22:48:01 +03:00
promise
syncNest {
2016-11-26 22:48:01 +03:00
sync
promise
}
promiseNest {
sync
promise
}
}
promiseNest {
sync
promise
syncNest {
2015-07-15 20:05:46 +03:00
sync
2016-11-26 22:48:01 +03:00
promise
}
promiseNest {
sync
promise
2015-07-15 20:05:46 +03:00
}
}
}
2016-11-26 22:48:01 +03:00
';
2015-07-15 20:05:46 +03:00
$ast = Parser::parse($doc);
$expected = [
'data' => [
'syncNest' => [
2015-07-15 20:05:46 +03:00
'sync' => null,
2016-11-26 22:48:01 +03:00
'promise' => null,
'syncNest' => [
2015-07-15 20:05:46 +03:00
'sync' => null,
2016-11-26 22:48:01 +03:00
'promise' => null,
],
'promiseNest' => [
'sync' => null,
'promise' => null,
],
],
'promiseNest' => [
'sync' => null,
'promise' => null,
'syncNest' => [
2016-11-26 22:48:01 +03:00
'sync' => null,
'promise' => null,
],
'promiseNest' => [
'sync' => null,
'promise' => null,
],
],
2015-07-15 20:05:46 +03:00
],
'errors' => [
FormattedError::create($this->syncError->getMessage(), [new SourceLocation(4, 11)]),
2016-11-26 22:48:01 +03:00
FormattedError::create($this->syncError->getMessage(), [new SourceLocation(7, 13)]),
FormattedError::create($this->syncError->getMessage(), [new SourceLocation(11, 13)]),
FormattedError::create($this->syncError->getMessage(), [new SourceLocation(16, 11)]),
FormattedError::create($this->syncError->getMessage(), [new SourceLocation(19, 13)]),
2016-12-03 00:11:14 +03:00
FormattedError::create($this->promiseError->getMessage(), [new SourceLocation(5, 11)]),
FormattedError::create($this->promiseError->getMessage(), [new SourceLocation(8, 13)]),
FormattedError::create($this->syncError->getMessage(), [new SourceLocation(23, 13)]),
2016-12-03 00:11:14 +03:00
FormattedError::create($this->promiseError->getMessage(), [new SourceLocation(12, 13)]),
FormattedError::create($this->promiseError->getMessage(), [new SourceLocation(17, 11)]),
FormattedError::create($this->promiseError->getMessage(), [new SourceLocation(20, 13)]),
2016-11-26 22:48:01 +03:00
FormattedError::create($this->promiseError->getMessage(), [new SourceLocation(24, 13)]),
2015-07-15 20:05:46 +03:00
]
];
2016-11-26 22:48:01 +03:00
2016-12-03 00:11:14 +03:00
$this->assertArraySubset($expected, Executor::execute($this->schema, $ast, $this->throwingData, null, [], 'Q')->toArray());
2016-11-26 22:48:01 +03:00
}
public function testNullsTheFirstNullableObjectAfterAFieldThrowsInALongChainOfFieldsThatAreNonNull() : void
2016-11-26 22:48:01 +03:00
{
$doc = '
query Q {
syncNest {
syncNonNullNest {
promiseNonNullNest {
syncNonNullNest {
promiseNonNullNest {
syncNonNull
2016-11-26 22:48:01 +03:00
}
}
}
}
}
promiseNest {
syncNonNullNest {
promiseNonNullNest {
syncNonNullNest {
promiseNonNullNest {
syncNonNull
2016-11-26 22:48:01 +03:00
}
}
}
}
}
anotherNest: syncNest {
syncNonNullNest {
promiseNonNullNest {
syncNonNullNest {
promiseNonNullNest {
promiseNonNull
2016-11-26 22:48:01 +03:00
}
}
}
}
}
anotherPromiseNest: promiseNest {
syncNonNullNest {
promiseNonNullNest {
syncNonNullNest {
promiseNonNullNest {
promiseNonNull
2016-11-26 22:48:01 +03:00
}
}
}
}
}
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => [
'syncNest' => null,
2016-11-26 22:48:01 +03:00
'promiseNest' => null,
'anotherNest' => null,
'anotherPromiseNest' => null,
],
'errors' => [
FormattedError::create($this->syncNonNullError->getMessage(), [new SourceLocation(8, 19)]),
FormattedError::create($this->syncNonNullError->getMessage(), [new SourceLocation(19, 19)]),
FormattedError::create($this->promiseNonNullError->getMessage(), [new SourceLocation(30, 19)]),
FormattedError::create($this->promiseNonNullError->getMessage(), [new SourceLocation(41, 19)]),
2016-11-26 22:48:01 +03:00
]
];
2016-12-03 00:11:14 +03:00
$this->assertArraySubset($expected, Executor::execute($this->schema, $ast, $this->throwingData, null, [], 'Q')->toArray());
2015-07-15 20:05:46 +03:00
}
public function testNullsANullableFieldThatSynchronouslyReturnsNull() : void
2015-07-15 20:05:46 +03:00
{
$doc = '
query Q {
sync
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => [
'sync' => null,
]
];
$this->assertEquals($expected, Executor::execute($this->schema, $ast, $this->nullingData, null, [], 'Q')->toArray());
2015-07-15 20:05:46 +03:00
}
public function testNullsANullableFieldThatReturnsNullInAPromise() : void
2016-11-26 22:48:01 +03:00
{
$doc = '
query Q {
promise
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => [
'promise' => null,
]
];
2016-12-03 00:11:14 +03:00
$this->assertArraySubset($expected, Executor::execute($this->schema, $ast, $this->nullingData, null, [], 'Q')->toArray());
2016-11-26 22:48:01 +03:00
}
public function testNullsASynchronouslyReturnedObjectThatContainsANonNullableFieldThatReturnsNullSynchronously() : void
2015-07-15 20:05:46 +03:00
{
$doc = '
query Q {
syncNest {
syncNonNull,
2015-07-15 20:05:46 +03:00
}
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => [
'syncNest' => null
2015-07-15 20:05:46 +03:00
],
'errors' => [
[
'debugMessage' => 'Cannot return null for non-nullable field DataType.syncNonNull.',
'locations' => [['line' => 4, 'column' => 11]]
]
2015-07-15 20:05:46 +03:00
]
];
$this->assertArraySubset($expected, Executor::execute($this->schema, $ast, $this->nullingData, null, [], 'Q')->toArray(true));
2015-07-15 20:05:46 +03:00
}
public function testNullsASynchronouslyReturnedObjectThatContainsANonNullableFieldThatReturnsNullInAPromise() : void
2015-07-15 20:05:46 +03:00
{
2016-11-26 22:48:01 +03:00
$doc = '
query Q {
syncNest {
promiseNonNull,
2016-11-26 22:48:01 +03:00
}
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => [
'syncNest' => null,
2016-11-26 22:48:01 +03:00
],
'errors' => [
[
'debugMessage' => 'Cannot return null for non-nullable field DataType.promiseNonNull.',
'locations' => [['line' => 4, 'column' => 11]]
],
2016-11-26 22:48:01 +03:00
]
];
2015-07-15 20:05:46 +03:00
$this->assertArraySubset(
$expected,
Executor::execute($this->schema, $ast, $this->nullingData, null, [], 'Q')->toArray(true)
);
2016-11-26 22:48:01 +03:00
}
public function testNullsAnObjectReturnedInAPromiseThatContainsANonNullableFieldThatReturnsNullSynchronously() : void
2016-11-26 22:48:01 +03:00
{
$doc = '
query Q {
promiseNest {
syncNonNull,
2016-11-26 22:48:01 +03:00
}
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => [
'promiseNest' => null,
],
'errors' => [
[
'debugMessage' => 'Cannot return null for non-nullable field DataType.syncNonNull.',
'locations' => [['line' => 4, 'column' => 11]]
],
2016-11-26 22:48:01 +03:00
]
];
$this->assertArraySubset(
$expected,
Executor::execute($this->schema, $ast, $this->nullingData, null, [], 'Q')->toArray(true)
);
2016-11-26 22:48:01 +03:00
}
public function testNullsAnObjectReturnedInAPromiseThatContainsANonNullableFieldThatReturnsNullInaAPromise() : void
2016-11-26 22:48:01 +03:00
{
$doc = '
query Q {
promiseNest {
promiseNonNull,
2016-11-26 22:48:01 +03:00
}
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => [
'promiseNest' => null,
],
'errors' => [
[
'debugMessage' => 'Cannot return null for non-nullable field DataType.promiseNonNull.',
'locations' => [['line' => 4, 'column' => 11]]
],
2016-11-26 22:48:01 +03:00
]
];
$this->assertArraySubset(
$expected,
Executor::execute($this->schema, $ast, $this->nullingData, null, [], 'Q')->toArray(true)
);
2016-11-26 22:48:01 +03:00
}
public function testNullsAComplexTreeOfNullableFieldsThatReturnNull() : void
2016-11-26 22:48:01 +03:00
{
2015-07-15 20:05:46 +03:00
$doc = '
query Q {
syncNest {
2015-07-15 20:05:46 +03:00
sync
2016-11-26 22:48:01 +03:00
promise
syncNest {
2015-07-15 20:05:46 +03:00
sync
2016-11-26 22:48:01 +03:00
promise
}
promiseNest {
sync
promise
}
}
promiseNest {
sync
promise
syncNest {
2016-11-26 22:48:01 +03:00
sync
promise
}
promiseNest {
sync
promise
2015-07-15 20:05:46 +03:00
}
}
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => [
'syncNest' => [
2015-07-15 20:05:46 +03:00
'sync' => null,
2016-11-26 22:48:01 +03:00
'promise' => null,
'syncNest' => [
2015-07-15 20:05:46 +03:00
'sync' => null,
2016-11-26 22:48:01 +03:00
'promise' => null,
2015-07-15 20:05:46 +03:00
],
2016-11-26 22:48:01 +03:00
'promiseNest' => [
'sync' => null,
'promise' => null,
]
2015-07-15 20:05:46 +03:00
],
2016-11-26 22:48:01 +03:00
'promiseNest' => [
'sync' => null,
'promise' => null,
'syncNest' => [
2016-11-26 22:48:01 +03:00
'sync' => null,
'promise' => null,
],
'promiseNest' => [
'sync' => null,
'promise' => null,
]
]
2015-07-15 20:05:46 +03:00
]
];
2016-11-26 22:48:01 +03:00
2016-12-03 00:11:14 +03:00
$actual = Executor::execute($this->schema, $ast, $this->nullingData, null, [], 'Q')->toArray();
$this->assertEquals($expected, $actual);
2016-11-26 22:48:01 +03:00
}
public function testNullsTheFirstNullableObjectAfterAFieldReturnsNullInALongChainOfFieldsThatAreNonNull() : void
2016-11-26 22:48:01 +03:00
{
$doc = '
query Q {
syncNest {
syncNonNullNest {
promiseNonNullNest {
syncNonNullNest {
promiseNonNullNest {
syncNonNull
2016-11-26 22:48:01 +03:00
}
}
}
}
}
promiseNest {
syncNonNullNest {
promiseNonNullNest {
syncNonNullNest {
promiseNonNullNest {
syncNonNull
2016-11-26 22:48:01 +03:00
}
}
}
}
}
anotherNest: syncNest {
syncNonNullNest {
promiseNonNullNest {
syncNonNullNest {
promiseNonNullNest {
promiseNonNull
2016-11-26 22:48:01 +03:00
}
}
}
}
}
anotherPromiseNest: promiseNest {
syncNonNullNest {
promiseNonNullNest {
syncNonNullNest {
promiseNonNullNest {
promiseNonNull
2016-11-26 22:48:01 +03:00
}
}
}
}
}
}
';
$ast = Parser::parse($doc);
$expected = [
'data' => [
'syncNest' => null,
2016-11-26 22:48:01 +03:00
'promiseNest' => null,
'anotherNest' => null,
'anotherPromiseNest' => null,
],
'errors' => [
['debugMessage' => 'Cannot return null for non-nullable field DataType.syncNonNull.', 'locations' => [ ['line' => 8, 'column' => 19]]],
['debugMessage' => 'Cannot return null for non-nullable field DataType.syncNonNull.', 'locations' => [ ['line' => 19, 'column' => 19]]],
['debugMessage' => 'Cannot return null for non-nullable field DataType.promiseNonNull.', 'locations' => [ ['line' => 30, 'column' => 19]]],
['debugMessage' => 'Cannot return null for non-nullable field DataType.promiseNonNull.', 'locations' => [ ['line' => 41, 'column' => 19]]],
2016-11-26 22:48:01 +03:00
]
];
$this->assertArraySubset(
$expected,
Executor::execute($this->schema, $ast, $this->nullingData, null, [], 'Q')->toArray(true)
);
2015-07-15 20:05:46 +03:00
}
2016-12-03 00:11:14 +03:00
/**
* @see it('nulls the top level if sync non-nullable field throws')
2016-12-03 00:11:14 +03:00
*/
public function testNullsTheTopLevelIfSyncNonNullableFieldThrows() : void
2015-07-15 20:05:46 +03:00
{
$doc = '
query Q { syncNonNull }
2015-07-15 20:05:46 +03:00
';
$expected = [
'errors' => [
FormattedError::create($this->syncNonNullError->getMessage(), [new SourceLocation(2, 17)])
2015-07-15 20:05:46 +03:00
]
];
2016-11-26 22:48:01 +03:00
$actual = Executor::execute($this->schema, Parser::parse($doc), $this->throwingData)->toArray();
$this->assertArraySubset($expected, $actual);
}
public function testNullsTheTopLevelIfAsyncNonNullableFieldErrors() : void
2016-11-26 22:48:01 +03:00
{
$doc = '
query Q { promiseNonNull }
2016-11-26 22:48:01 +03:00
';
$ast = Parser::parse($doc);
$expected = [
'errors' => [
FormattedError::create($this->promiseNonNullError->getMessage(), [new SourceLocation(2, 17)]),
2016-11-26 22:48:01 +03:00
]
];
2016-12-03 00:11:14 +03:00
$this->assertArraySubset($expected, Executor::execute($this->schema, $ast, $this->throwingData, null, [], 'Q')->toArray());
2015-07-15 20:05:46 +03:00
}
public function testNullsTheTopLevelIfSyncNonNullableFieldReturnsNull() : void
2015-07-15 20:05:46 +03:00
{
// nulls the top level if sync non-nullable field returns null
$doc = '
query Q { syncNonNull }
2015-07-15 20:05:46 +03:00
';
$expected = [
'errors' => [
[
'debugMessage' => 'Cannot return null for non-nullable field DataType.syncNonNull.',
'locations' => [['line' => 2, 'column' => 17]]
],
2015-07-15 20:05:46 +03:00
]
];
$this->assertArraySubset(
$expected,
Executor::execute($this->schema, Parser::parse($doc), $this->nullingData)->toArray(true)
);
2015-07-15 20:05:46 +03:00
}
2016-11-26 22:48:01 +03:00
public function testNullsTheTopLevelIfAsyncNonNullableFieldResolvesNull() : void
2016-11-26 22:48:01 +03:00
{
$doc = '
query Q { promiseNonNull }
2016-11-26 22:48:01 +03:00
';
$ast = Parser::parse($doc);
$expected = [
'errors' => [
[
'debugMessage' => 'Cannot return null for non-nullable field DataType.promiseNonNull.',
'locations' => [['line' => 2, 'column' => 17]]
],
2016-11-26 22:48:01 +03:00
]
];
$this->assertArraySubset(
$expected,
Executor::execute($this->schema, $ast, $this->nullingData, null, [], 'Q')->toArray(true)
);
2016-11-26 22:48:01 +03:00
}
2015-07-15 20:05:46 +03:00
}