Skip to content

Commit c7808e9

Browse files
committed
Merge branch 'main' into nurguly/update-webonyx-graphql-php
2 parents 395c9b5 + 003d1e4 commit c7808e9

File tree

5 files changed

+83
-3
lines changed

5 files changed

+83
-3
lines changed

Changelog.md

+14
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,17 @@
1+
## [1.4.2](https://github.com/dadish/ProcessGraphQL/compare/v1.4.1...v1.4.2) (2023-05-14)
2+
3+
4+
### Bug Fixes
5+
6+
* **FeildtypeOptions:** fix error for empty values when it's a single option ([7a02e9d](https://github.com/dadish/ProcessGraphQL/commit/7a02e9d1af24dda78fd40ebb4a96710a55fe67e4))
7+
8+
## [1.4.2-rc.1](https://github.com/dadish/ProcessGraphQL/compare/v1.4.1...v1.4.2-rc.1) (2023-05-14)
9+
10+
11+
### Bug Fixes
12+
13+
* **FeildtypeOptions:** fix error for empty values when it's a single option ([7a02e9d](https://github.com/dadish/ProcessGraphQL/commit/7a02e9d1af24dda78fd40ebb4a96710a55fe67e4))
14+
115
## [1.4.1](https://github.com/dadish/ProcessGraphQL/compare/v1.4.0...v1.4.1) (2022-07-30)
216

317

ProcessGraphQL.module

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ class ProcessGraphQL extends Process implements Module {
1515
{
1616
return array(
1717
'title' => 'GraphQL',
18-
'version' => '1.4.1',
18+
'version' => '1.4.2',
1919
'summary' => 'GraphQL for ProcessWire.',
2020
'href' => 'https://github.com/dadish/ProcessGraphql',
2121
'singular' => true,

package.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "processgraphql",
3-
"version": "1.4.1",
3+
"version": "1.4.2",
44
"description": "GraphQL for ProcessWire",
55
"main": "index.js",
66
"directories": {

src/Type/Fieldtype/FieldtypeOptions.php

+30-1
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@
99
use ProcessWire\GraphQL\Utils;
1010
use ProcessWire\GraphQL\Type\Fieldtype\Traits\SetValueTrait;
1111
use ProcessWire\GraphQL\Type\Fieldtype\Traits\FieldTrait;
12+
use ProcessWire\Page;
1213

1314
class FieldtypeOptions
14-
{
15+
{
1516
use FieldTrait;
1617
use SetValueTrait;
1718

@@ -63,6 +64,34 @@ public static function type($field)
6364
return $type;
6465
}
6566

67+
public static function field($field)
68+
{
69+
return Cache::field($field->name, function () use ($field) {
70+
// description
71+
$desc = $field->description;
72+
if (!$desc) {
73+
$desc = "Field with the type of {$field->type}";
74+
}
75+
76+
return [
77+
'name' => $field->name,
78+
'description' => $desc,
79+
'type' => self::type($field),
80+
'resolve' => function (Page $page, array $args) use ($field) {
81+
$fieldName = $field->name;
82+
83+
// If a single option field does not have an id, then it means it's empty.
84+
if (!self::isMultiple($field) && !$page->$fieldName->id) {
85+
return null;
86+
}
87+
88+
return $page->$fieldName;
89+
}
90+
];
91+
});
92+
}
93+
94+
6695
public static function inputType($field)
6796
{
6897
return Cache::type(self::getName($field), function () use ($field) {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
<?php
2+
3+
/**
4+
* Empty options field should return null.
5+
*/
6+
7+
namespace ProcessWire\GraphQL\Test\FieldtypeOptions;
8+
9+
use ProcessWire\GraphQL\Utils;
10+
use ProcessWire\GraphQL\Test\GraphQLTestCase;
11+
12+
class CaseFiveTest extends GraphQLTestCase
13+
{
14+
const settings = [
15+
"login" => "admin",
16+
"legalTemplates" => ["city"],
17+
"legalFields" => ["options_single"],
18+
];
19+
20+
public function testValue()
21+
{
22+
$city = Utils::pages()->get("template=city, options_single=''");
23+
$query = "{
24+
city (s: \"id=$city->id\") {
25+
list {
26+
options_single {
27+
title
28+
value
29+
id
30+
}
31+
}
32+
}
33+
}";
34+
$res = self::execute($query);
35+
self::assertNull($res->data->city->list[0]->options_single, "Empty option field should return null.");
36+
}
37+
}

0 commit comments

Comments
 (0)