Skip to content

Commit 6956cf1

Browse files
committed
Make the field NonNull if required.
1 parent 4d2cbd3 commit 6956cf1

14 files changed

+24
-16
lines changed

src/Field/Page/Fieldtype/AbstractFieldtype.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
namespace ProcessWire\GraphQL\Field\Page\Fieldtype;
44

55
use Youshido\GraphQL\Field\AbstractField;
6+
use Youshido\GraphQL\Type\NonNullType;
67
use Youshido\GraphQL\Execution\ResolveInfo;
78
use ProcessWire\Field;
89

@@ -16,6 +17,12 @@ public function __construct(Field $field)
1617
parent::__construct([]);
1718
}
1819

20+
public function getType()
21+
{
22+
if ($this->field->required) return new NonNullType($this->getDefaultType());
23+
return $this->getDefaultType();
24+
}
25+
1926
public function getName()
2027
{
2128
return $this->field->name;

src/Field/Page/Fieldtype/FieldtypeCheckbox.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class FieldtypeCheckbox extends AbstractFieldtype {
99

10-
public function getType()
10+
public function getDefaultType()
1111
{
1212
return new BooleanType();
1313
}

src/Field/Page/Fieldtype/FieldtypeDatetime.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class FieldtypeDatetime extends AbstractFieldtype {
99

10-
public function getType()
10+
public function getDefaultType()
1111
{
1212
return new DatetimeType();
1313
}

src/Field/Page/Fieldtype/FieldtypeEmail.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class FieldtypeEmail extends AbstractFieldtype {
99

10-
public function getType()
10+
public function getDefaultType()
1111
{
1212
return new StringType();
1313
}

src/Field/Page/Fieldtype/FieldtypeFile.php

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,17 @@
22

33
namespace ProcessWire\GraphQL\Field\Page\Fieldtype;
44

5-
use Youshido\GraphQL\Type\Scalar\StringType;
65
use Youshido\GraphQL\Execution\ResolveInfo;
7-
use ProcessWire\GraphQL\Field\Page\Fieldtype\AbstractFieldtype;
6+
use Youshido\GraphQL\Type\ListType\ListType;
87
use ProcessWire\FieldtypeFile as PWFieldtypeFile;
8+
use ProcessWire\GraphQL\Field\Page\Fieldtype\AbstractFieldtype;
9+
use ProcessWire\GraphQL\Type\Object\PageFileType;
910

1011
class FieldtypeFile extends AbstractFieldtype {
1112

12-
public function getType()
13+
public function getDefaultType()
1314
{
14-
return new StringType();
15+
return new ListType(new PageFileType());
1516
}
1617

1718
public function resolve($value, array $args, ResolveInfo $info)

src/Field/Page/Fieldtype/FieldtypeFloat.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class FieldtypeFloat extends AbstractFieldtype {
1010

11-
public function getType()
11+
public function getDefaultType()
1212
{
1313
return new FloatType();
1414
}

src/Field/Page/Fieldtype/FieldtypeImage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class FieldtypeImage extends FieldtypeFile {
1010

11-
public function getType()
11+
public function getDefaultType()
1212
{
1313
return new ListType(new PageImageType());
1414
}

src/Field/Page/Fieldtype/FieldtypeInteger.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88

99
class FieldtypeInteger extends AbstractFieldtype {
1010

11-
public function getType()
11+
public function getDefaultType()
1212
{
1313
return new IntType();
1414
}

src/Field/Page/Fieldtype/FieldtypePage.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class FieldtypePage extends AbstractFieldtype {
1414

15-
public function getType()
15+
public function getDefaultType()
1616
{
1717
// if template is chosen for the FieldtypePage
1818
// then we resolve to TemplatedPageArrayType

src/Field/Page/Fieldtype/FieldtypePageTitle.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77

88
class FieldtypePageTitle extends AbstractFieldtype {
99

10-
public function getType()
10+
public function getDefaultType()
1111
{
1212
return new StringType();
1313
}

0 commit comments

Comments
 (0)