andrey-mokhov /
graphql-php-spiral
| 1 | <?php |
||
| 2 | |||
| 3 | declare(strict_types=1); |
||
| 4 | |||
| 5 | namespace Andi\GraphQL\Spiral\Config; |
||
| 6 | |||
| 7 | use Andi\GraphQL\ArgumentResolver\ArgumentResolverInterface; |
||
| 8 | use Andi\GraphQL\ArgumentResolver\Middleware as Argument; |
||
| 9 | use Andi\GraphQL\InputObjectFieldResolver\InputObjectFieldResolverInterface; |
||
| 10 | use Andi\GraphQL\InputObjectFieldResolver\Middleware as Inputs; |
||
| 11 | use Andi\GraphQL\ObjectFieldResolver\Middleware as Objects; |
||
| 12 | use Andi\GraphQL\ObjectFieldResolver\ObjectFieldResolverInterface; |
||
| 13 | use Andi\GraphQL\TypeResolver\Middleware as Types; |
||
| 14 | use Andi\GraphQL\TypeResolver\TypeResolverInterface; |
||
| 15 | use GraphQL\Error\DebugFlag; |
||
| 16 | use Spiral\Core\InjectableConfig; |
||
| 17 | |||
| 18 | final class GraphQLConfig extends InjectableConfig |
||
| 19 | { |
||
| 20 | public const CONFIG = 'graphql'; |
||
| 21 | |||
| 22 | public const DEFAULT_QUERY_TYPE = 'Query'; |
||
| 23 | public const DEFAULT_MUTATION_TYPE = 'Mutation'; |
||
| 24 | |||
| 25 | protected array $config = [ |
||
| 26 | 'url' => '/api/graphql', |
||
| 27 | 'queryType' => self::DEFAULT_QUERY_TYPE, |
||
| 28 | 'mutationType' => null, |
||
| 29 | 'rootValue'=> null, |
||
| 30 | 'context' => null, |
||
| 31 | 'debugFlag' => null, |
||
| 32 | |||
| 33 | 'typeResolverMiddlewares' => [ |
||
| 34 | Types\EnumTypeMiddleware::class => Types\EnumTypeMiddleware::PRIORITY, |
||
| 35 | Types\WebonyxGraphQLTypeMiddleware::class => Types\WebonyxGraphQLTypeMiddleware::PRIORITY, |
||
| 36 | Types\GraphQLTypeMiddleware::class => Types\GraphQLTypeMiddleware::PRIORITY, |
||
| 37 | Types\AttributedGraphQLTypeMiddleware::class => Types\AttributedGraphQLTypeMiddleware::PRIORITY, |
||
| 38 | ], |
||
| 39 | |||
| 40 | 'objectFieldResolverMiddlewares' => [ |
||
| 41 | Objects\QueryFieldByReflectionMethodMiddleware::class => Objects\QueryFieldByReflectionMethodMiddleware::PRIORITY, |
||
| 42 | Objects\MutationFieldByReflectionMethodMiddleware::class => Objects\MutationFieldByReflectionMethodMiddleware::PRIORITY, |
||
| 43 | Objects\AdditionalFieldByReflectionMethodMiddleware::class => Objects\AdditionalFieldByReflectionMethodMiddleware::PRIORITY, |
||
| 44 | Objects\InterfaceFieldByReflectionMethodMiddleware::class => Objects\InterfaceFieldByReflectionMethodMiddleware::PRIORITY, |
||
| 45 | Objects\ObjectFieldByReflectionMethodMiddleware::class => Objects\ObjectFieldByReflectionMethodMiddleware::PRIORITY, |
||
| 46 | Objects\ObjectFieldByReflectionPropertyMiddleware::class => Objects\ObjectFieldByReflectionPropertyMiddleware::PRIORITY, |
||
| 47 | Objects\ObjectFieldMiddleware::class => Objects\ObjectFieldMiddleware::PRIORITY, |
||
| 48 | Objects\WebonyxObjectFieldMiddleware::class => Objects\WebonyxObjectFieldMiddleware::PRIORITY, |
||
| 49 | ], |
||
| 50 | |||
| 51 | 'inputObjectFieldResolverMiddlewares' => [ |
||
| 52 | Inputs\ReflectionPropertyMiddleware::class => Inputs\ReflectionPropertyMiddleware::PRIORITY, |
||
| 53 | Inputs\ReflectionMethodMiddleware::class => Inputs\ReflectionMethodMiddleware::PRIORITY, |
||
| 54 | Inputs\InputObjectFieldMiddleware::class => Inputs\InputObjectFieldMiddleware::PRIORITY, |
||
| 55 | Inputs\WebonyxInputObjectFieldMiddleware::class => Inputs\WebonyxInputObjectFieldMiddleware::PRIORITY, |
||
| 56 | ], |
||
| 57 | |||
| 58 | 'argumentResolverMiddlewares' => [ |
||
| 59 | Argument\ReflectionParameterMiddleware::class => Argument\ReflectionParameterMiddleware::PRIORITY, |
||
| 60 | Argument\ArgumentMiddleware::class => Argument\ArgumentMiddleware::PRIORITY, |
||
| 61 | Argument\ArgumentConfigurationMiddleware::class => Argument\ArgumentConfigurationMiddleware::PRIORITY, |
||
| 62 | ], |
||
| 63 | |||
| 64 | 'additionalTypes' => [ |
||
| 65 | ], |
||
| 66 | ]; |
||
| 67 | |||
| 68 | 3 | public function getUrl(): string |
|
| 69 | { |
||
| 70 | 3 | return $this->config['url']; |
|
| 71 | } |
||
| 72 | |||
| 73 | 2 | public function getQueryType(): string |
|
| 74 | { |
||
| 75 | 2 | return $this->config['queryType']; |
|
| 76 | } |
||
| 77 | |||
| 78 | 2 | public function getMutationType(): ?string |
|
| 79 | { |
||
| 80 | 2 | return $this->config['mutationType']; |
|
| 81 | } |
||
| 82 | |||
| 83 | /** |
||
| 84 | * @return class-string|null |
||
|
0 ignored issues
–
show
Documentation
Bug
introduced
by
Loading history...
|
|||
| 85 | */ |
||
| 86 | 2 | public function getRootValue(): ?string |
|
| 87 | { |
||
| 88 | 2 | return $this->config['rootValue']; |
|
| 89 | } |
||
| 90 | |||
| 91 | /** |
||
| 92 | * @return class-string|null |
||
|
0 ignored issues
–
show
|
|||
| 93 | */ |
||
| 94 | 2 | public function getContext(): ?string |
|
| 95 | { |
||
| 96 | 2 | return $this->config['context'] ?? null; |
|
| 97 | } |
||
| 98 | |||
| 99 | 2 | public function getDebugFlag(): int |
|
| 100 | { |
||
| 101 | 2 | return $this->config['debugFlag'] ?? DebugFlag::INCLUDE_DEBUG_MESSAGE; |
|
| 102 | } |
||
| 103 | |||
| 104 | /** |
||
| 105 | * @return array<class-string<TypeResolverInterface>,int> |
||
|
0 ignored issues
–
show
|
|||
| 106 | */ |
||
| 107 | 2 | public function getTypeResolverMiddlewares(): array |
|
| 108 | { |
||
| 109 | 2 | return $this->config['typeResolverMiddlewares']; |
|
| 110 | } |
||
| 111 | |||
| 112 | /** |
||
| 113 | * @return array<class-string<ObjectFieldResolverInterface>,int> |
||
|
0 ignored issues
–
show
|
|||
| 114 | */ |
||
| 115 | 2 | public function getObjectFieldResolverMiddlewares(): array |
|
| 116 | { |
||
| 117 | 2 | return $this->config['objectFieldResolverMiddlewares']; |
|
| 118 | } |
||
| 119 | |||
| 120 | /** |
||
| 121 | * @return array<class-string<InputObjectFieldResolverInterface>,int> |
||
|
0 ignored issues
–
show
|
|||
| 122 | */ |
||
| 123 | 2 | public function getInputObjectFieldResolverMiddlewares(): array |
|
| 124 | { |
||
| 125 | 2 | return $this->config['inputObjectFieldResolverMiddlewares']; |
|
| 126 | } |
||
| 127 | |||
| 128 | /** |
||
| 129 | * @return array<class-string<ArgumentResolverInterface>,int> |
||
|
0 ignored issues
–
show
|
|||
| 130 | */ |
||
| 131 | 2 | public function getArgumentResolverMiddlewares(): array |
|
| 132 | { |
||
| 133 | 2 | return $this->config['argumentResolverMiddlewares']; |
|
| 134 | } |
||
| 135 | |||
| 136 | /** |
||
| 137 | * @return array<class-string, string[]> |
||
|
0 ignored issues
–
show
|
|||
| 138 | */ |
||
| 139 | 2 | public function getAdditionalTypes(): array |
|
| 140 | { |
||
| 141 | 2 | return $this->config['additionalTypes']; |
|
| 142 | } |
||
| 143 | } |
||
| 144 |