Skip to content

Commit 2e7b010

Browse files
committed
Show pagination args in reference docs sample
1 parent db67eb8 commit 2e7b010

File tree

1 file changed

+19
-15
lines changed

1 file changed

+19
-15
lines changed

spring-graphql-docs/src/docs/asciidoc/index.adoc

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -649,30 +649,30 @@ to send to the client.
649649
[[execution.pagination]]
650650
=== Pagination
651651

652-
The GraphQL Cursor Connection https://relay.dev/graphql/connections.htm[specification]
653-
defines a mechanism for efficient navigation of large result sets by returning a limited
654-
set of items at a time. Each item is paired with a cursor that a client can use to request
655-
the items after or before the cursor, providing a way to navigate forward and backward.
652+
The GraphQL https://relay.dev/graphql/connections.htm[Cursor Connection specification]
653+
defines a way to navigate large result sets by returning a subset of items at a time where
654+
each item is paired with a cursor that clients can use to request more items before or
655+
after the referenced item.
656656

657-
The spec calls the pattern "Connections". A schema type whose name ends on "Connection"
658-
is considered a _Connection Type_ and represents a paginated result set. A `Connection`
659-
contains "edges" where an `Edge` is a wrapper around the actual item and its cursor.
660-
There is also a `PageInfo` to indicate whether there are more items forward and backward.
657+
The specification calls the pattern _"Connections"_. A schema type with a name that ends
658+
on Connection is a _Connection Type_ that represents a paginated result set. All `~Connection`
659+
types contain an "edges" field where `~Edge` type pairs the actual item with a cursor, as
660+
well as a "pageInfo" field with boolean flags to indicate if there are more items forward
661+
and backward.
661662

662663

663664
[[execution.pagination.types]]
664665
==== Connection Types
665666

666-
`Connection` type definitions must be repeated for every type that needs pagination, adding
667+
`Connection` type definitions must be created for every type that needs pagination, adding
667668
boilerplate and noise to the schema. Spring for GraphQL provides
668-
`ConnectionTypeDefinitionConfigurer` to generate these types on startup, if not already
669-
present in the parsed schema files. That means you can have a `Connection` field without
670-
a type declaration as follows:
669+
`ConnectionTypeDefinitionConfigurer` to add these types on startup, if not already
670+
present in the parsed schema files. That means in the schema you only need this:
671671

672672
[source,graphql,indent=0,subs="verbatim,quotes"]
673673
----
674674
Query {
675-
books: BookConnection
675+
books(first:Int, after:String, last:Int, before:String): BookConnection
676676
}
677677
678678
type Book {
@@ -681,7 +681,11 @@ a type declaration as follows:
681681
}
682682
----
683683

684-
Configure `ConnectionTypeDefinitionConfigurer` as follows:
684+
Note the spec-defined forward pagination arguments `first` and `after` that clients can use
685+
to request the first N items after the given cursor, while `last` and `before` are backward
686+
pagination arguments to request the last N items before the given cursor.
687+
688+
Next, configure `ConnectionTypeDefinitionConfigurer` as follows:
685689

686690
[source,java,indent=0,subs="verbatim,quotes"]
687691
----
@@ -690,7 +694,7 @@ GraphQlSource.schemaResourceBuilder()
690694
.typeDefinitionConfigurer(new ConnectionTypeDefinitionConfigurer)
691695
----
692696

693-
The following type definitions will be added to the schema on startup:
697+
and the following type definitions will be transparently added to the schema:
694698

695699
[source,graphql,indent=0,subs="verbatim,quotes"]
696700
----

0 commit comments

Comments
 (0)