forked from dagger/dagger-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSchemaGenerator.php
42 lines (33 loc) · 964 Bytes
/
SchemaGenerator.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
42
<?php
namespace Dagger\Codegen;
use GraphQL\Client;
use GraphQL\Type\Schema;
use GraphQL\Utils\BuildClientSchema;
class SchemaGenerator
{
private array $schemaArray;
private Schema $schema;
public function __construct(private readonly Client $client)
{
$this->update();
}
public function getSchema(): Schema
{
return $this->schema;
}
public function getJson(): string
{
return json_encode($this->schemaArray, JSON_PRETTY_PRINT);
}
public function update(): void
{
$introspectionQueryFilePath = implode(DIRECTORY_SEPARATOR, [
__DIR__,
'Resources',
'introspection.graphql',
]);
$introspectionQuery = file_get_contents($introspectionQueryFilePath);
$this->schemaArray = $this->client->runRawQuery($introspectionQuery, true)->getData();
$this->schema = BuildClientSchema::build($this->schemaArray);
}
}