-
-
Notifications
You must be signed in to change notification settings - Fork 575
Expand file tree
/
Copy pathSchemaTest.php
More file actions
123 lines (103 loc) · 3.71 KB
/
Copy pathSchemaTest.php
File metadata and controls
123 lines (103 loc) · 3.71 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
<?php declare(strict_types=1);
namespace GraphQL\Tests\Type;
use GraphQL\Error\InvariantViolation;
use GraphQL\Type\Definition\Directive;
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\InterfaceType;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Definition\Type;
use GraphQL\Type\Schema;
use PHPUnit\Framework\TestCase;
final class SchemaTest extends TestCase
{
private InterfaceType $interfaceType;
private ObjectType $implementingType;
private InputObjectType $directiveInputType;
private InputObjectType $wrappedDirectiveInputType;
private Directive $directive;
private Schema $schema;
protected function setUp(): void
{
$this->interfaceType = new InterfaceType([
'name' => 'Interface',
'fields' => ['fieldName' => ['type' => Type::string()]],
]);
$this->implementingType = new ObjectType([
'name' => 'Object',
'interfaces' => [$this->interfaceType],
'fields' => [
'fieldName' => [
'type' => Type::string(),
'resolve' => static fn (): string => '',
],
],
]);
$this->directiveInputType = new InputObjectType([
'name' => 'DirInput',
'fields' => [
'field' => [
'type' => Type::string(),
],
],
]);
$this->wrappedDirectiveInputType = new InputObjectType([
'name' => 'WrappedDirInput',
'fields' => [
'field' => [
'type' => Type::string(),
],
],
]);
$this->directive = new Directive([
'name' => 'dir',
'locations' => ['OBJECT'],
'args' => [
'arg' => [
'type' => $this->directiveInputType,
],
'argList' => [
'type' => Type::listOf($this->wrappedDirectiveInputType),
],
],
]);
$this->schema = new Schema([
'query' => new ObjectType([
'name' => 'Query',
'fields' => [
'getObject' => [
'type' => $this->interfaceType,
'resolve' => static fn (): array => [],
],
],
]),
'directives' => [$this->directive],
]);
}
// Type System: Schema
// Getting possible types
/** @see it('throws human-reable error if schema.types is not defined') */
public function testThrowsHumanReableErrorIfSchemaTypesIsNotDefined(): void
{
self::markTestSkipped("Can't check interface implementations without full schema scan");
$this->expectException(InvariantViolation::class);
$this->expectExceptionMessage(
'Could not find possible implementing types for Interface in schema. '
. 'Check that schema.types is defined and is an array of all possible '
. 'types in the schema.'
);
$this->schema->isSubType($this->interfaceType, $this->implementingType);
}
// Type Map
/** @see it('includes input types only used in directives') */
public function testIncludesInputTypesOnlyUsedInDirectives(): void
{
$typeMap = $this->schema->getTypeMap();
self::assertArrayHasKey('DirInput', $typeMap);
self::assertArrayHasKey('WrappedDirInput', $typeMap);
}
/** @see https://github.com/webonyx/graphql-php/issues/997 */
public function testSchemaReturnsNullForNonexistentType(): void
{
self::assertNull($this->schema->getType('UnknownType'));
}
}