forked from rebing/graphql-laravel
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTypeMakeCommand.php
44 lines (35 loc) · 1.07 KB
/
TypeMakeCommand.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
<?php
declare(strict_types = 1);
namespace Rebing\GraphQL\Console;
use Illuminate\Console\GeneratorCommand;
use Symfony\Component\Console\Attribute\AsCommand;
#[AsCommand('make:graphql:type')]
class TypeMakeCommand extends GeneratorCommand
{
protected $signature = 'make:graphql:type {name}';
protected $description = 'Create a new GraphQL type class';
protected $type = 'Type';
protected function getStub(): string
{
return __DIR__ . '/stubs/type.stub';
}
protected function getDefaultNamespace($rootNamespace): string
{
return $rootNamespace . '\GraphQL\Types';
}
protected function buildClass($name): string
{
$stub = parent::buildClass($name);
return $this->replaceGraphqlName($stub);
}
protected function replaceGraphqlName(string $stub): string
{
$graphqlName = $this->getNameInput();
$graphqlName = \Safe\preg_replace('/Type$/', '', $graphqlName);
return str_replace(
'DummyGraphqlName',
$graphqlName,
$stub
);
}
}