forked from dagger/dagger-php-sdk
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCodegen.php
69 lines (56 loc) · 2.12 KB
/
Codegen.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
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
<?php
namespace Dagger\Codegen;
use Dagger\Codegen\Introspection\CodegenVisitor;
use Dagger\Codegen\Introspection\Helpers;
use GraphQL\Type\Definition\CustomScalarType;
use GraphQL\Type\Definition\EnumType;
use GraphQL\Type\Definition\InputObjectType;
use GraphQL\Type\Definition\ObjectType;
use GraphQL\Type\Schema;
use Symfony\Component\Console\Style\SymfonyStyle;
class Codegen
{
public function __construct(
private readonly Schema $schema,
private readonly string $writeDir,
private readonly SymfonyStyle $io)
{
}
public function generate(): void
{
$schemaVisitor = new CodegenVisitor($this->schema, $this->writeDir);
$filteredTypes = array_filter($this->schema->getTypeMap(), function ($type) {
return !str_starts_with($type->name ?? '', '__');
});
$scalarTypes = array_filter($filteredTypes, function ($type) {
return $type instanceof CustomScalarType
&& !Helpers::isVoidType($type)
&& 'DateTime' !== $type->name;
});
$inputObjectTypes = array_filter($filteredTypes, function ($type) {
return $type instanceof InputObjectType;
});
$enumObjectTypes = array_filter($filteredTypes, function ($type) {
return $type instanceof EnumType;
});
$objectTypes = array_filter($filteredTypes, function ($type) {
return $type instanceof ObjectType;
});
foreach ($scalarTypes as $type) {
$this->io->info("Generating scalar '{$type->name}'");
$schemaVisitor->visitScalar($type);
}
foreach ($inputObjectTypes as $type) {
$this->io->info("Generating input object '{$type->name}'");
$schemaVisitor->visitInput($type);
}
foreach ($enumObjectTypes as $type) {
$this->io->info("Generating enum object '{$type->name}'");
$schemaVisitor->visitEnum($type);
}
foreach ($objectTypes as $type) {
$this->io->info("Generating object '{$type->name}'");
$schemaVisitor->visitObject($type);
}
}
}