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

Commit 6e8ebfa

Browse files
georgebootspawnia
authored andcommitted
Document the defaultCount argument for @paginate and @hasmany(#89)
nuwave/lighthouse#428
1 parent 4749d13 commit 6e8ebfa

File tree

1 file changed

+59
-10
lines changed

1 file changed

+59
-10
lines changed

docs/api-directives.md

+59-10
Original file line numberDiff line numberDiff line change
@@ -382,24 +382,26 @@ type User {
382382
}
383383
```
384384

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`.
386387

387388
```graphql
388389
type User {
389-
postsPaginated: [Post!]! @hasMany(type: "paginator")
390-
postsRelayConnection: [Post!]! @hasMany(type: "connection")
390+
posts: [Post!]! @hasMany(relation: "articles")
391391
}
392392
```
393393

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`.
396395

397396
```graphql
398397
type User {
399-
posts: [Post!]! @hasMany(relation: "articles")
398+
postsPaginated: [Post!]! @hasMany(type: "paginator")
399+
postsRelayConnection: [Post!]! @hasMany(type: "connection")
400400
}
401401
```
402402

403+
Pagination for related models works just like for root fields, find out more about this in [`@paginate`](directives#paginate).
404+
403405
## @hasOne
404406

405407
Corresponds to [Eloquent's HasOne-Relationship](https://laravel.com/docs/eloquent-relationships#one-to-one).
@@ -635,15 +637,44 @@ type Query {
635637

636638
## @paginate
637639

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.
640641

641642
```graphql
642643
type Query {
643644
posts: [Post!]! @paginate
644645
}
645646
```
646647

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+
647678
The `type` of pagination defaults to `paginator`, but may also be set to a Relay
648679
compliant `connection`.
649680

@@ -653,7 +684,26 @@ type Query {
653684
}
654685
```
655686

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
657707
name as the returned type. You can overwrite this by setting the `model` argument.
658708

659709
```graphql
@@ -664,7 +714,6 @@ type Query {
664714

665715
If simply querying Eloquent does not fit your use-case, you can specify a custom `builder`.
666716

667-
668717
```graphql
669718
type Query {
670719
posts: [Post!]! @paginate(builder: "App\\Blog@visiblePosts")

0 commit comments

Comments
 (0)