Skip to content

Commit

Permalink
allow non-nullable field argument (#6)
Browse files Browse the repository at this point in the history
  • Loading branch information
calvera committed Feb 28, 2024
1 parent 0df1d1a commit 03d298f
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 0 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Changelog

## [Unreleased]
### Added
- Allow non-nullable field argument

## [0.2.2] - 2024-01-26
### Added
Expand Down
19 changes: 19 additions & 0 deletions src/Schema/Definition/Arguments/FieldArgument.php
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ class FieldArgument
protected bool $isDefaultValueSet = false;

protected bool $multi = false;

protected bool $nullable = true;

public function __construct(string $name, Type $type)
{
Expand Down Expand Up @@ -92,4 +94,21 @@ public function setMulti(bool $multi = true): self
$this->multi = $multi;
return $this;
}

public function isNullable(): bool
{
return $this->nullable;
}

public function setNullable(bool $nullable = true): FieldArgument
{
$this->nullable = $nullable;
return $this;
}

public function setNonNullable(bool $nonNullable = true): FieldArgument
{
$this->nullable = !$nonNullable;
return $this;
}
}
4 changes: 4 additions & 0 deletions src/Schema/Transformers/WebonyxSchemaTransformer.php
Original file line number Diff line number Diff line change
Expand Up @@ -190,6 +190,10 @@ private function transformFieldArgument(FieldArgument $fieldArgument): array
$argumentType = WebonyxType::listOf($argumentType);
}

if (!$fieldArgument->isNullable()) {
$argumentType = WebonyxType::nonNull($argumentType);
}

$argumentResult = [
'name' => $fieldArgument->getName(),
'type' => $argumentType,
Expand Down

0 comments on commit 03d298f

Please sign in to comment.