Skip to content

Commit

Permalink
feat: apply input manipulators
Browse files Browse the repository at this point in the history
  • Loading branch information
jaulz committed Nov 22, 2023
1 parent 149d683 commit e159a26
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/Schema/AST/ASTBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
use Nuwave\Lighthouse\Schema\Source\SchemaSourceProvider;
use Nuwave\Lighthouse\Support\Contracts\ArgManipulator;
use Nuwave\Lighthouse\Support\Contracts\FieldManipulator;
use Nuwave\Lighthouse\Support\Contracts\InputManipulator;
use Nuwave\Lighthouse\Support\Contracts\TypeExtensionManipulator;
use Nuwave\Lighthouse\Support\Contracts\TypeManipulator;

Expand Down Expand Up @@ -73,6 +74,7 @@ public function build(): DocumentAST
$this->applyTypeExtensionManipulators();
$this->applyFieldManipulators();
$this->applyArgManipulators();
$this->applyInputManipulators();

// Listeners may manipulate the DocumentAST that is passed by reference
// into the ManipulateAST event. This can be useful for extensions
Expand Down Expand Up @@ -222,5 +224,25 @@ protected function applyArgManipulators(): void
}
}
}
}

/** Apply directives on input that can manipulate the AST. */
protected function applyInputManipulators(): void
{
foreach ($this->documentAST->types as $typeDefinition) {
if ($typeDefinition instanceof InputObjectTypeDefinitionNode) {
foreach ($typeDefinition->fields as $fieldDefinition) {
foreach (
$this->directiveLocator->associatedOfType($fieldDefinition, InputManipulator::class) as $inputManipulator
) {
$inputManipulator->manipulateInputDefinition(
$this->documentAST,
$fieldDefinition,
$typeDefinition,
);
}
}
}
}
}
}

0 comments on commit e159a26

Please sign in to comment.