Skip to content

Commit

Permalink
Remove Node from child nodes (arg and field)
Browse files Browse the repository at this point in the history
These nodes do not behave the same as the root nodes and have different
use of Type. Therefore, remove the direct link.
  • Loading branch information
jerowork committed Jan 6, 2025
1 parent f8057e8 commit 967bd93
Show file tree
Hide file tree
Showing 8 changed files with 10 additions and 22 deletions.
8 changes: 1 addition & 7 deletions src/Parser/Node/Child/ArgNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

namespace Jerowork\GraphqlAttributeSchema\Parser\Node\Child;

use Jerowork\GraphqlAttributeSchema\Parser\Node\Node;
use Jerowork\GraphqlAttributeSchema\Parser\Node\Type;

final readonly class ArgNode implements Node
final readonly class ArgNode
{
public function __construct(
public Type $type,
Expand All @@ -16,9 +15,4 @@ public function __construct(
public bool $isRequired,
public string $propertyName,
) {}

public function getType(): Type
{
return $this->type;
}
}
8 changes: 1 addition & 7 deletions src/Parser/Node/Child/FieldNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@

namespace Jerowork\GraphqlAttributeSchema\Parser\Node\Child;

use Jerowork\GraphqlAttributeSchema\Parser\Node\Node;
use Jerowork\GraphqlAttributeSchema\Parser\Node\Type;

final readonly class FieldNode implements Node
final readonly class FieldNode
{
/**
* @param list<ArgNode> $argNodes
Expand All @@ -22,9 +21,4 @@ public function __construct(
public ?string $methodName,
public ?string $propertyName,
) {}

public function getType(): Type
{
return $this->type;
}
}
2 changes: 1 addition & 1 deletion src/TypeBuilder/Object/BuildArgsTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ public function buildArgs(FieldNode $fieldNode, TypeBuilder $typeBuilder, Ast $a
$args[] = [
'name' => $argNode->name,
'type' => $typeBuilder->build(
$argNode->getType(),
$argNode->type,
$argNode->isRequired,
$ast,
),
Expand Down
2 changes: 1 addition & 1 deletion src/TypeBuilder/Object/InputTypeObjectTypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ private function buildFields(InputTypeNode $node, TypeBuilder $typeBuilder, Ast
$fields = [];

foreach ($node->fieldNodes as $fieldNode) {
$type = $typeBuilder->build($fieldNode->getType(), $fieldNode->isRequired, $ast);
$type = $typeBuilder->build($fieldNode->type, $fieldNode->isRequired, $ast);

if (!$type instanceof InputType) {
throw BuildException::invalidTypeForField($fieldNode->name, $type::class);
Expand Down
2 changes: 1 addition & 1 deletion src/TypeBuilder/Object/TypeObjectTypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ private function buildFields(TypeNode $node, TypeBuilder $typeBuilder, Ast $ast)
foreach ($node->fieldNodes as $fieldNode) {
$fields[] = [
'name' => $fieldNode->name,
'type' => $typeBuilder->build($fieldNode->getType(), $fieldNode->isRequired, $ast),
'type' => $typeBuilder->build($fieldNode->type, $fieldNode->isRequired, $ast),
'description' => $fieldNode->description,
'args' => $this->buildArgs($fieldNode, $typeBuilder, $ast),
'resolve' => $this->typeResolver->resolve($fieldNode, $ast),
Expand Down
2 changes: 1 addition & 1 deletion src/TypeBuilder/RootTypeBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public function build(QueryNode|MutationNode $node, Ast $ast): array
foreach ($node->argNodes as $argNode) {
$args[] = [
'name' => $argNode->name,
'type' => $this->typeBuilder->build($argNode->getType(), $argNode->isRequired, $ast),
'type' => $this->typeBuilder->build($argNode->type, $argNode->isRequired, $ast),
'description' => $argNode->description,
];
}
Expand Down
2 changes: 1 addition & 1 deletion src/TypeResolver/FieldResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ private function resolveChild(FieldNode $field, callable $fieldCallback, Ast $as
return $fieldCallback();
}

$node = $ast->getNodeByType($field->getType());
$node = $ast->getNodeByType($field->type);

if ($node instanceof EnumNode) {
/** @var BackedEnum $enum */
Expand Down
6 changes: 3 additions & 3 deletions src/TypeResolver/RootTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,10 +51,10 @@ public function resolveChild(ArgNode|FieldNode $child, array $args, Ast $ast): m
return $args[$child->name];
}

$node = $ast->getNodeByType($child->getType());
$node = $ast->getNodeByType($child->type);

if ($node === null) {
throw ResolveException::logicError(sprintf('Node not found for typeId %s', $child->getType()->id));
throw ResolveException::logicError(sprintf('Node not found for typeId %s', $child->type->id));
}

if ($node instanceof EnumNode) {
Expand All @@ -69,7 +69,7 @@ public function resolveChild(ArgNode|FieldNode $child, array $args, Ast $ast): m
if ($node instanceof InputTypeNode) {
/** @var array<string, mixed> $childArgs */
$childArgs = $args[$child->name];
$type = $child->getType()->id;
$type = $child->type->id;

return new $type(...array_map(
fn($fieldNode) => $this->resolveChild($fieldNode, $childArgs, $ast),
Expand Down

0 comments on commit 967bd93

Please sign in to comment.