-
-
Notifications
You must be signed in to change notification settings - Fork 563
/
Copy pathGraphQLTest.php
41 lines (37 loc) · 1.38 KB
/
GraphQLTest.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
<?php declare(strict_types=1);
namespace GraphQL\Tests;
use GraphQL\Executor\Promise\Adapter\SyncPromiseAdapter;
use GraphQL\Executor\Promise\Promise;
use GraphQL\GraphQL;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Schema;
use GraphQL\Type\SchemaConfig;
use PHPUnit\Framework\TestCase;
final class GraphQLTest extends TestCase
{
public function testPromiseToExecute(): void
{
$promiseAdapter = new SyncPromiseAdapter();
$schema = new Schema(
(new SchemaConfig())
->setQuery(new ObjectType([
'name' => 'Query',
'fields' => [
'sayHi' => [
'type' => Type::nonNull(Type::string()),
'args' => [
'name' => [
'type' => Type::nonNull(Type::string()),
],
],
'resolve' => static fn ($rootValue, array $args): Promise => $promiseAdapter->createFulfilled("Hi {$args['name']}!"),
],
],
]))
);
$promise = GraphQL::promiseToExecute($promiseAdapter, $schema, '{ sayHi(name: "John") }');
$result = $promiseAdapter->wait($promise);
self::assertSame(['data' => ['sayHi' => 'Hi John!']], $result->toArray());
}
}