forked from nuwave/lighthouse
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathFederationSchemaTest.php
More file actions
101 lines (79 loc) · 2.27 KB
/
FederationSchemaTest.php
File metadata and controls
101 lines (79 loc) · 2.27 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
<?php
namespace Tests\Integration\Federation;
use GraphQL\Type\Definition\UnionType;
use Nuwave\Lighthouse\Federation\FederationServiceProvider;
use Tests\TestCase;
class FederationSchemaTest extends TestCase
{
protected function getPackageProviders($app): array
{
return array_merge(
parent::getPackageProviders($app),
[FederationServiceProvider::class]
);
}
public function testServiceQueryShouldReturnValidSdl(): void
{
$foo = /** @lang GraphQL */ <<<'GRAPHQL'
type Foo @key(fields: "id") {
id: ID! @external
foo: String!
}
GRAPHQL;
$query = /** @lang GraphQL */ <<<'GRAPHQL'
type Query {
foo: Int!
}
GRAPHQL;
$this->schema = $foo.$query;
$sdl = $this->_serviceSdl();
$this->assertStringContainsString($foo, $sdl);
$this->assertStringContainsString($query, $sdl);
}
public function testServiceQueryShouldReturnValidSdlWithoutQuery(): void
{
$foo = /** @lang GraphQL */ <<<'GRAPHQL'
type Foo @key(fields: "id") {
id: ID! @external
foo: String!
}
GRAPHQL;
$this->schema = $foo;
$sdl = $this->_serviceSdl();
$this->assertStringContainsString($foo, $sdl);
$this->assertStringNotContainsString(/** @lang GraphQL */ 'type Query', $sdl);
}
public function testFederatedSchemaShouldContainCorrectEntityUnion(): void
{
$schema = $this->buildSchema(/** @lang GraphQL */ '
type Foo @key(fields: "id") {
id: ID! @external
foo: String!
}
type Bar @key(fields: "id") {
id: ID! @external
bar: String!
}
type Query {
foo: Int!
}
');
/** @var \GraphQL\Type\Definition\UnionType|null $_Entity */
$_Entity = $schema->getType('_Entity');
$this->assertInstanceOf(UnionType::class, $_Entity);
$types = $_Entity->getTypes();
$this->assertSame('Foo', $types[0]->name);
$this->assertSame('Bar', $types[1]->name);
}
protected function _serviceSdl(): string
{
$response = $this->graphQL(/** @lang GraphQL */ '
{
_service {
sdl
}
}
');
return $response->json('data._service.sdl');
}
}