Skip to content
This repository was archived by the owner on Mar 29, 2020. It is now read-only.

Commit 8a85d59

Browse files
committed
always return paginator for relay type connections
1 parent 31f8a40 commit 8a85d59

File tree

1 file changed

+16
-2
lines changed

1 file changed

+16
-2
lines changed

src/Types/RelayType.php

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,8 @@
1111
use GraphQL\Type\Definition\ResolveInfo;
1212
use Illuminate\Contracts\Pagination\LengthAwarePaginator;
1313
use Illuminate\Pagination\LengthAwarePaginator as Paginator;
14+
use Illuminate\Database\Eloquent\Model;
15+
use Illuminate\Support\Collection;
1416
use Nuwave\Relay\GlobalIdTrait;
1517

1618
abstract class RelayType extends GraphQLType
@@ -86,7 +88,15 @@ public function getConnections()
8688
]
8789
],
8890
'resolve' => isset($edge['resolve']) ? $edge['resolve'] : function ($collection, array $args, ResolveInfo $info) use ($name) {
89-
$items = $collection->getAttribute($name);
91+
$items = [];
92+
93+
if ($collection instanceof Model) {
94+
$items = $collection->getAttribute($name);
95+
} else if (is_object($collection) && method_exists($collection, 'get')) {
96+
$items = $collection->get($name);
97+
} else if (is_array($collection) && isset($collection[$name])) {
98+
$items = new Collection($collection[$name]);
99+
}
90100

91101
if (isset($args['first'])) {
92102
$total = $items->count();
@@ -102,7 +112,11 @@ public function getConnections()
102112
);
103113
}
104114

105-
return $items;
115+
return new Paginator(
116+
$items,
117+
count($items),
118+
count($items)
119+
);
106120
}
107121
];
108122
}

0 commit comments

Comments
 (0)