@@ -649,30 +649,30 @@ to send to the client.
649
649
[[execution.pagination]]
650
650
=== Pagination
651
651
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 .
656
656
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.
661
662
662
663
663
664
[[execution.pagination.types]]
664
665
==== Connection Types
665
666
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
667
668
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:
671
671
672
672
[source,graphql,indent=0,subs="verbatim,quotes"]
673
673
----
674
674
Query {
675
- books: BookConnection
675
+ books(first:Int, after:String, last:Int, before:String) : BookConnection
676
676
}
677
677
678
678
type Book {
@@ -681,7 +681,11 @@ a type declaration as follows:
681
681
}
682
682
----
683
683
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:
685
689
686
690
[source,java,indent=0,subs="verbatim,quotes"]
687
691
----
@@ -690,7 +694,7 @@ GraphQlSource.schemaResourceBuilder()
690
694
.typeDefinitionConfigurer(new ConnectionTypeDefinitionConfigurer)
691
695
----
692
696
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:
694
698
695
699
[source,graphql,indent=0,subs="verbatim,quotes"]
696
700
----
0 commit comments