This repository was archived by the owner on Mar 29, 2020. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +16
-2
lines changed
Expand file tree Collapse file tree 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 1111use GraphQL \Type \Definition \ResolveInfo ;
1212use Illuminate \Contracts \Pagination \LengthAwarePaginator ;
1313use Illuminate \Pagination \LengthAwarePaginator as Paginator ;
14+ use Illuminate \Database \Eloquent \Model ;
15+ use Illuminate \Support \Collection ;
1416use Nuwave \Relay \GlobalIdTrait ;
1517
1618abstract 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 }
You can’t perform that action at this time.
0 commit comments