This repository was archived by the owner on Mar 29, 2020. It is now read-only.
File tree 1 file changed +16
-2
lines changed 1 file changed +16
-2
lines changed Original file line number Diff line number Diff line change 11
11
use GraphQL \Type \Definition \ResolveInfo ;
12
12
use Illuminate \Contracts \Pagination \LengthAwarePaginator ;
13
13
use Illuminate \Pagination \LengthAwarePaginator as Paginator ;
14
+ use Illuminate \Database \Eloquent \Model ;
15
+ use Illuminate \Support \Collection ;
14
16
use Nuwave \Relay \GlobalIdTrait ;
15
17
16
18
abstract class RelayType extends GraphQLType
@@ -86,7 +88,15 @@ public function getConnections()
86
88
]
87
89
],
88
90
'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
+ }
90
100
91
101
if (isset ($ args ['first ' ])) {
92
102
$ total = $ items ->count ();
@@ -102,7 +112,11 @@ public function getConnections()
102
112
);
103
113
}
104
114
105
- return $ items ;
115
+ return new Paginator (
116
+ $ items ,
117
+ count ($ items ),
118
+ count ($ items )
119
+ );
106
120
}
107
121
];
108
122
}
You can’t perform that action at this time.
0 commit comments