Update documentation

See gh-201
This commit is contained in:
Rossen Stoyanchev
2021-11-26 14:26:50 +00:00
parent 46d4d3d648
commit cc5a8427a8
2 changed files with 66 additions and 27 deletions

View File

@@ -423,8 +423,14 @@ If the repository is `ReactiveQuerydslPredicateExecutor`, the builder returns
`DataFetcher<Mono<Account>>` or `DataFetcher<Flux<Account>>`. Spring Data supports this
variant for MongoDB.
You will also need to configure Querydsl in your build
(see https://querydsl.com/static/querydsl/latest/reference/html/ch02.html[the official reference documentation]):
[[data-querydsl-build]]
==== Build Setup
To configure Querydsl in your build, follow the
https://querydsl.com/static/querydsl/latest/reference/html/ch02.html[official reference documentation]:
For example:
[source,groovy,indent=0,subs="verbatim,quotes,attributes",role="primary"]
.Gradle
@@ -485,17 +491,21 @@ compileJava {
</plugins>
----
The {github-main-branch}/samples/webmvc-http[webmvc-http] sample in the Spring GraphQL repository
uses Querydsl to fetch `artifactRepositories`.
The {github-main-branch}/samples/webmvc-http[webmvc-http] sample uses Querydsl for
`artifactRepositories`.
[[data-querydsl-customizations]]
==== Customizations
The Querydsl integration allows customizing the request parameters binding onto a
`Predicate` by accepting a `QuerydslBinderCustomizer`. Request parameters are bound
by default as "is equal to" for each available property in the request.
`QuerydslDataFetcher` supports customizing how GraphQL arguments are bound onto properties
to create a Querydsl `Predicate`. By default, arguments are bound as "is equal to" for
each available property. To customize that, you can use `QuerydslDataFetcher` builder
methods to provide a `QuerydslBinderCustomizer`.
A repository may itself be an instance of `QuerydslBinderCustomizer`. This is auto-detected
and transparently applied during <<data-querydsl-registration>>. However, when manually
building a `QuerydslDataFetcher` you will need to use builder methods to apply it.
`QuerydslDataFetcher` supports
https://docs.spring.io/spring-data/commons/docs/current/reference/html/#projections[interface and DTO projections]
@@ -505,17 +515,21 @@ to transform query results before returning these for further GraphQL processing
[[data-querydsl-registration]]
==== Auto Registration
`QuerydslDataFetcher` exposes a `GraphQLTypeVisitor` that finds top-level queries whose
return type matches the domain type of one or more Querydsl repositories, and registers
a `DataFetcher` for each matching query. This includes both queries that return a single
value and queries that return a list of values.
If a repository is annotated with `@GraphQlRepository`, it is automatically registered
for queries that do not already have a registered `DataFetcher` and whose return type
matches that of the repository domain type. This includes both single value and multi-value
queries.
The repository must be annotated with `@GraphQlRepository`. By default, the name of the
GraphQL type returned by the query must match the simple name of the repository domain
type. Of if they don't match, you can use the `typeName` attribute of
`@GraphQlRepository` to set the GraphQL type name.
By default, the name of the GraphQL type returned by the query must match the simple name
of the repository domain type. If needed, you can use the `typeName` attribute of
`@GraphQlRepository` to specify the target GraphQL type name.
Such repositories are auto-detected in the <<boot-repositories-querydsl,Boot starter>>.
Auto-registration detects if a given repository implements `QuerydslBinderCustomizer` and
transparently applies that through `QuerydslDataFetcher` builder methods.
Auto-registration is performed through a `GraphQLTypeVisitor` which can be obtained from
`QuerydslDataFetcher`. The <<boot-repositories-querydsl,Boot starter>> automatically
detects `@GraphQlRepository` beans and applies the `GraphQLTypeVisitor`.

View File

@@ -94,13 +94,18 @@ import org.springframework.util.StringUtils;
* wiring.dataFetcher("book", QuerydslDataFetcher.builder(repository).single());
* </pre>
*
* <p>See methods on {@link Builder} and {@link ReactiveBuilder} for further
* options on GraphQL Query argument to Querydsl Predicate bindings, result
* projections, and sorting.
* <p>See {@link Builder} and {@link ReactiveBuilder} methods for further
* options on GraphQL Query argument to Querydsl Predicate binding customizations,
* result projections, and sorting.
*
* <p>{@code QuerydslDataFetcher} {@link #registrationTypeVisitor(List, List) exposes}
* a {@link GraphQLTypeVisitor} that can auto-register repositories annotated with
* {@link GraphQlRepository @GraphQlRepository}.
*
* @param <T> returned result type
* @author Mark Paluch
* @since 1.0.0
* @see GraphQlRepository
* @see QuerydslPredicateExecutor
* @see ReactiveQuerydslPredicateExecutor
* @see Predicate
@@ -188,11 +193,17 @@ public abstract class QuerydslDataFetcher<T> {
}
/**
* Create a {@link GraphQLTypeVisitor} that finds queries with a return type
* whose name matches to the domain type name of the given repositories and
* registers {@link DataFetcher}s for those queries.
* <p><strong>Note:</strong> currently, this method will match only to
* queries under the top-level "Query" type in the GraphQL schema.
* Return a {@link GraphQLTypeVisitor} that auto-registers the given
* Querydsl repositories for queries that do not already have a registered
* {@code DataFetcher} and whose return type matches the simple name of the
* repository domain type.
*
* <p><strong>Note:</strong> Auto-registration applies only to
* {@link GraphQlRepository @GraphQlRepository}-annotated repositories.
* If a repository is also an instance of {@link QuerydslBinderCustomizer},
* this is transparently detected and applied through the
* {@code QuerydslDataFetcher} builder methods.
*
* @param executors repositories to consider for registration
* @param reactiveExecutors reactive repositories to consider for registration
* @return the created visitor
@@ -296,7 +307,14 @@ public abstract class QuerydslDataFetcher<T> {
/**
* Apply a {@link QuerydslBinderCustomizer}.
* @param customizer to customize the GraphQL query to Querydsl Predicate binding
*
* <p>If a Querydsl repository implements {@link QuerydslBinderCustomizer}
* itself, this is automatically detected and applied during
* {@link #registrationTypeVisitor(List, List) auto-registration}.
* For manual registration, you will need to use this method to apply it.
*
* @param customizer to customize the GraphQL query to Querydsl
* Predicate binding with
* @return a new {@link Builder} instance with all previously configured
* options and {@code QuerydslBinderCustomizer} applied
*/
@@ -392,7 +410,14 @@ public abstract class QuerydslDataFetcher<T> {
/**
* Apply a {@link QuerydslBinderCustomizer}.
* @param customizer to customize the GraphQL query to Querydsl Predicate binding
*
* <p>If a Querydsl repository implements {@link QuerydslBinderCustomizer}
* itself, this is automatically detected and applied during
* {@link #registrationTypeVisitor(List, List) auto-registration}.
* For manual registration, you will need to use this method to apply it.
*
* @param customizer to customize the GraphQL query to Querydsl
* Predicate binding with
* @return a new {@link Builder} instance with all previously configured
* options and {@code QuerydslBinderCustomizer} applied
*/