- Add DISCOVERY_LOG_LEVEL=debug - Add DISCOVERY_SHOW_PROGRESS=true - Temporary changes for debugging InitializerProcessor fixes on production
108 lines
2.6 KiB
PHP
108 lines
2.6 KiB
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Framework\GraphQL;
|
|
|
|
/**
|
|
* Represents a GraphQL schema with queries and mutations
|
|
*/
|
|
final class GraphQLSchema
|
|
{
|
|
/** @var array<string, GraphQLField> */
|
|
public private(set) array $queries = [];
|
|
|
|
/** @var array<string, GraphQLField> */
|
|
public private(set) array $mutations = [];
|
|
|
|
/** @var array<string, GraphQLType> */
|
|
public private(set) array $types = [];
|
|
|
|
public string $schemaDefinition {
|
|
get {
|
|
$schema = [];
|
|
|
|
// Add type definitions
|
|
foreach ($this->types as $name => $type) {
|
|
$schema[] = $type->toDefinition();
|
|
}
|
|
|
|
// Add Query type
|
|
if (! empty($this->queries)) {
|
|
$queryFields = [];
|
|
foreach ($this->queries as $name => $field) {
|
|
$queryFields[] = " " . $field->toDefinition($name);
|
|
}
|
|
$schema[] = "type Query {\n" . implode("\n", $queryFields) . "\n}";
|
|
}
|
|
|
|
// Add Mutation type
|
|
if (! empty($this->mutations)) {
|
|
$mutationFields = [];
|
|
foreach ($this->mutations as $name => $field) {
|
|
$mutationFields[] = " " . $field->toDefinition($name);
|
|
}
|
|
$schema[] = "type Mutation {\n" . implode("\n", $mutationFields) . "\n}";
|
|
}
|
|
|
|
return implode("\n\n", $schema);
|
|
}
|
|
}
|
|
|
|
public int $queryCount {
|
|
get => count($this->queries);
|
|
}
|
|
|
|
public int $mutationCount {
|
|
get => count($this->mutations);
|
|
}
|
|
|
|
public int $typeCount {
|
|
get => count($this->types);
|
|
}
|
|
|
|
public bool $hasQueries {
|
|
get => ! empty($this->queries);
|
|
}
|
|
|
|
public bool $hasMutations {
|
|
get => ! empty($this->mutations);
|
|
}
|
|
|
|
public function addQuery(string $name, GraphQLField $field): self
|
|
{
|
|
$this->queries[$name] = $field;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function addMutation(string $name, GraphQLField $field): self
|
|
{
|
|
$this->mutations[$name] = $field;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function addType(string $name, GraphQLType $type): self
|
|
{
|
|
$this->types[$name] = $type;
|
|
|
|
return $this;
|
|
}
|
|
|
|
public function getQuery(string $name): ?GraphQLField
|
|
{
|
|
return $this->queries[$name] ?? null;
|
|
}
|
|
|
|
public function getMutation(string $name): ?GraphQLField
|
|
{
|
|
return $this->mutations[$name] ?? null;
|
|
}
|
|
|
|
public function getType(string $name): ?GraphQLType
|
|
{
|
|
return $this->types[$name] ?? null;
|
|
}
|
|
}
|