@@ -382,24 +382,26 @@ type User {
382
382
}
383
383
```
384
384
385
- You can return the related models paginated by setting the `type`.
385
+ If the name of the relationship on the Eloquent model is different than the field name,
386
+ you can override it by setting `relation`.
386
387
387
388
```graphql
388
389
type User {
389
- postsPaginated : [Post ! ]! @hasMany (type : " paginator" )
390
- postsRelayConnection : [Post ! ]! @hasMany (type : " connection" )
390
+ posts : [Post ! ]! @hasMany (relation : " articles" )
391
391
}
392
392
```
393
393
394
- If the name of the relationship on the Eloquent model is different than the field name,
395
- you can override it by setting `relation`.
394
+ You can return the related models paginated by setting the `type`.
396
395
397
396
```graphql
398
397
type User {
399
- posts : [Post ! ]! @hasMany (relation : " articles" )
398
+ postsPaginated : [Post ! ]! @hasMany (type : " paginator" )
399
+ postsRelayConnection : [Post ! ]! @hasMany (type : " connection" )
400
400
}
401
401
```
402
402
403
+ Pagination for related models works just like for root fields, find out more about this in [`@paginate`](directives#paginate).
404
+
403
405
## @hasOne
404
406
405
407
Corresponds to [Eloquent's HasOne-Relationship](https ://laravel .com /docs /eloquent -relationships #one-to-one).
@@ -635,15 +637,44 @@ type Query {
635
637
636
638
## @paginate
637
639
638
- Return a paginated list . This transforms the schema definition and automatically adds
639
- additional arguments and inbetween types.
640
+ Transform a field so it returns a paginated list .
640
641
641
642
```graphql
642
643
type Query {
643
644
posts : [Post ! ]! @paginate
644
645
}
645
646
```
646
647
648
+ The schema definition is automatically transformed to this:
649
+
650
+ ```graphql
651
+ type Query {
652
+ posts (count : Int !, page : Int ): PostPaginator
653
+ }
654
+
655
+ type PostPaginator {
656
+ data : [Post ! ]!
657
+ paginatorInfo : PaginatorInfo !
658
+ }
659
+ ```
660
+
661
+ And can be queried like this :
662
+
663
+ ```graphql
664
+ {
665
+ posts (count : 10 ) {
666
+ data {
667
+ id
668
+ title
669
+ }
670
+ paginatorInfo {
671
+ currentPage
672
+ lastPage
673
+ }
674
+ }
675
+ }
676
+ ```
677
+
647
678
The ` type ` of pagination defaults to ` paginator ` , but may also be set to a Relay
648
679
compliant ` connection ` .
649
680
@@ -653,7 +684,26 @@ type Query {
653
684
}
654
685
```
655
686
656
- By default , this looks for an Eloquent model in the configured default namespace , with the same
687
+ You can supply a `defaultCount ` to set a default count for any kind of paginator .
688
+
689
+ ```graphql
690
+ type Query {
691
+ posts : [Post ! ]! @paginate (type : " connection" , defaultCount : 25 )
692
+ }
693
+ ```
694
+
695
+ This let 's you omit the `count ` argument when querying :
696
+
697
+ ```graphql
698
+ query {
699
+ posts {
700
+ id
701
+ name
702
+ }
703
+ }
704
+ ```
705
+
706
+ By default, Lighthouse looks for an Eloquent model in the configured default namespace, with the same
657
707
name as the returned type. You can overwrite this by setting the ` model ` argument.
658
708
659
709
``` graphql
@@ -664,7 +714,6 @@ type Query {
664
714
665
715
If simply querying Eloquent does not fit your use -case , you can specify a custom `builder `.
666
716
667
-
668
717
```graphql
669
718
type Query {
670
719
posts : [Post ! ]! @paginate (builder : " App\\ Blog@visiblePosts" )
0 commit comments