You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/helpers/relay-paginator.md
+50Lines changed: 50 additions & 0 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -261,3 +261,53 @@ public function resolveList($args)
261
261
return $pagination->forward($args);
262
262
}
263
263
```
264
+
265
+
266
+
#### Customize the way the connection & edges are built
267
+
268
+
Sometimes, you want to add fields to your Connection or Edges. In order to do so, you'll have to pass a custom instance of `ConnectionBuilder` to your Paginator as follow:
269
+
270
+
```php
271
+
use Overblog\GraphQLBundle\Relay\Connection\ConnectionBuilder;
$paginator = new Paginator(function ($offset, $limit) use ($backend) {
289
+
return $backend->getData($offset);
290
+
}, true, $connectionBuilder);
291
+
}
292
+
```
293
+
294
+
The `ConnectionBuilder` constructor accepts two parameters. The first one is a callback to build the Connection object, and the second one is a callback to build an Edge object.
295
+
296
+
The connection callback will be call with the following parameters :
297
+
298
+
-`edges` An array of edges object implementing `Overblog\GraphQLBundle\Relay\Connection\EdgeInterface`
299
+
-`pageInfo` a PageInfo object `Overblog\GraphQLBundle\Relay\Connection\Output\PageInfo`
300
+
301
+
This callback MUST return an instance of `Overblog\GraphQLBundle\Relay\Connection\ConnectionInterface`
302
+
303
+
304
+
The edge callback will be call with the following parameters :
305
+
306
+
-`cursor` The cursor
307
+
-`value` A value returned by the paginator data fetcher
308
+
-`index` The index of the value
309
+
310
+
This callback MUST return an instance of `Overblog\GraphQLBundle\Relay\Connection\EdgeInterface`
311
+
312
+
If no callback are specified for the `ConnectionBuilder`, it'll generate instance of `Overblog\GraphQLBundle\Relay\Connection\Output\Connection` and `Overblog\GraphQLBundle\Relay\Connection\Output\Edge`
0 commit comments