Skip to content

Commit 17db28b

Browse files
committed
Fix single page reference value.
1 parent 1d248c0 commit 17db28b

File tree

4 files changed

+48
-4
lines changed

4 files changed

+48
-4
lines changed

src/PagesBuffer.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ public static function add($group, $_ids)
5555
self::$pageIDs[$group] = [];
5656
}
5757
self::$pageIDs[$group] = array_merge(self::$pageIDs[$group], $ids);
58+
return $ids;
5859
}
5960

6061
public static function get($group)

src/Type/Fieldtype/FieldtypePage.php

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,19 +38,21 @@ public static function field($field)
3838
'description' => $desc,
3939
'type' => self::type($field),
4040
'resolve' => function ($value, $args, $context, $info) use ($field) {
41-
$field->derefAsPage = PWFieldtypePage::derefAsPageArray;
4241
$data = $value->getArray();
4342
if (isset($data[$field->name])) {
4443
$data = $data[$field->name];
4544
if (!empty($data)) {
46-
PagesBuffer::add($field->name, $data);
45+
$pageIDs = PagesBuffer::add($field->name, $data);
46+
if (count($pageIDs)) {
47+
$value->data($field->name, $pageIDs);
48+
}
4749
}
4850
}
4951
return new Deferred(function () use ($value, $field, $info) {
5052
$finderOptions = PageArrayType::getFinderOptions($info);
5153
PagesBuffer::loadPages($field->name, $finderOptions);
5254
$fieldName = $field->name;
53-
$field = \ProcessWire\wire('fields')->get($fieldName);
55+
$field->derefAsPage = PWFieldtypePage::derefAsPageArray;
5456
$value = $value->$fieldName;
5557
if (!$value instanceof PageArray) {
5658
return new PageArray();
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
<?php
2+
3+
namespace ProcessWire\GraphQL\Test\Field\Page\Fieldtype;
4+
5+
/**
6+
* Returns multiple values as expected.
7+
*/
8+
use \ProcessWire\GraphQL\Test\GraphQLTestCase;
9+
10+
class FieldtypePageCaseFourTest extends GraphQLTestCase {
11+
12+
const settings = [
13+
'login' => 'admin',
14+
'legalTemplates' => ['skyscraper', 'architect'],
15+
'legalFields' => ['architects'],
16+
];
17+
18+
public function testValue()
19+
{
20+
$query = 'query getSkyscrapers($s: Selector!){
21+
skyscraper (s: $s) {
22+
list {
23+
architects {
24+
list {
25+
id,
26+
}
27+
}
28+
}
29+
}
30+
}';
31+
$variables = [
32+
's' => "architects.count>4, limit=5"
33+
];
34+
$res = self::execute($query, $variables);
35+
assertGreaterThan(
36+
1,
37+
count($res->data->skyscraper->list[0]->architects->list),
38+
'Returns empty list.'
39+
);
40+
}
41+
}

test/Performance/DBQueryCount.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ public static function getSettings()
2626
*
2727
* @var integer
2828
*/
29-
public static $bestQueryCount = 28;
29+
public static $bestQueryCount = 29;
3030

3131
/**
3232
* The query we use to test the performance of the module by counting

0 commit comments

Comments
 (0)