Class QueryByExampleDataFetcher<T>
java.lang.Object
org.springframework.graphql.data.query.QueryByExampleDataFetcher<T>
- Type Parameters:
T
- returned result type
Main class to create a
DataFetcher
from a Query By Example repository.
To create an instance, use one of the following:
For example:
interface BookRepository extends Repository<Book, String>, QueryByExampleExecutor<Book>{} TypeRuntimeWiring wiring = … ; BookRepository repository = … ; DataFetcher<?> forMany = wiring.dataFetcher("books", QueryByExampleDataFetcher.builder(repository).many()); DataFetcher<?> forSingle = wiring.dataFetcher("book", QueryByExampleDataFetcher.builder(repository).single());
See methods on QueryByExampleDataFetcher.Builder
and
QueryByExampleDataFetcher.ReactiveBuilder
for further options on
result projections and sorting.
QueryByExampleDataFetcher
exposes
a RuntimeWiringConfigurer
that can auto-register repositories
annotated with @GraphQlRepository
.
- Since:
- 1.0.0
- Author:
- Greg Turnquist, Rossen Stoyanchev
- See Also:
-
GraphQlRepository
QueryByExampleExecutor
ReactiveQueryByExampleExecutor
Example
- Spring Data Query By Example extension
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic class
Builder for a Query by Example-basedDataFetcher
.static interface
Callback interface that can be used to customize QueryByExampleDataFetcherQueryByExampleDataFetcher.Builder
to change its configuration.static class
Builder for a reactive Query by Example-basedDataFetcher
.static interface
Callback interface that can be used to customize QueryByExampleDataFetcherQueryByExampleDataFetcher.ReactiveBuilder
to change its configuration. -
Method Summary
Modifier and TypeMethodDescriptionstatic RuntimeWiringConfigurer
autoRegistrationConfigurer
(List<org.springframework.data.repository.query.QueryByExampleExecutor<?>> executors, List<org.springframework.data.repository.query.ReactiveQueryByExampleExecutor<?>> reactiveExecutors) Variation ofautoRegistrationConfigurer(List, List, CursorStrategy, ScrollSubrange)
without aCursorStrategy
and defaultScrollSubrange
.static RuntimeWiringConfigurer
autoRegistrationConfigurer
(List<org.springframework.data.repository.query.QueryByExampleExecutor<?>> executors, List<org.springframework.data.repository.query.ReactiveQueryByExampleExecutor<?>> reactiveExecutors, CursorStrategy<org.springframework.data.domain.ScrollPosition> cursorStrategy, ScrollSubrange defaultScrollSubrange) Return aRuntimeWiringConfigurer
that installs aWiringFactory
to find queries with a return type whose name matches to the domain type name of the given repositories and registersDataFetcher
s for them.static <T> QueryByExampleDataFetcher.Builder<T,
T> builder
(org.springframework.data.repository.query.QueryByExampleExecutor<T> executor) Create a newQueryByExampleDataFetcher.Builder
acceptingQueryByExampleExecutor
to build aDataFetcher
.static <T> QueryByExampleDataFetcher.ReactiveBuilder<T,
T> builder
(org.springframework.data.repository.query.ReactiveQueryByExampleExecutor<T> executor) Create a newQueryByExampleDataFetcher.ReactiveBuilder
acceptingReactiveQueryByExampleExecutor
to build aDataFetcher
.protected org.springframework.data.domain.Example<T>
buildExample
(DataFetchingEnvironment environment) Prepare anExample
from GraphQL request arguments.protected Collection<String>
buildPropertyPaths
(DataFetchingFieldSelectionSet selection, Class<?> resultType) Provides shared implementation ofSelfDescribingDataFetcher.getDescription()
for all subclasses.protected boolean
requiresProjection
(Class<?> resultType) toString()
-
Method Details
-
getDescription
Provides shared implementation ofSelfDescribingDataFetcher.getDescription()
for all subclasses.- Since:
- 1.2.0
-
buildExample
protected org.springframework.data.domain.Example<T> buildExample(DataFetchingEnvironment environment) throws BindException Prepare anExample
from GraphQL request arguments.- Parameters:
environment
- contextual info for the GraphQL request- Returns:
- the resulting example
- Throws:
BindException
-
requiresProjection
-
buildPropertyPaths
protected Collection<String> buildPropertyPaths(DataFetchingFieldSelectionSet selection, Class<?> resultType) -
toString
-
builder
public static <T> QueryByExampleDataFetcher.Builder<T,T> builder(org.springframework.data.repository.query.QueryByExampleExecutor<T> executor) Create a newQueryByExampleDataFetcher.Builder
acceptingQueryByExampleExecutor
to build aDataFetcher
.- Type Parameters:
T
- the domain type of the repository- Parameters:
executor
- the QBE repository object to use- Returns:
- a new builder
-
builder
public static <T> QueryByExampleDataFetcher.ReactiveBuilder<T,T> builder(org.springframework.data.repository.query.ReactiveQueryByExampleExecutor<T> executor) Create a newQueryByExampleDataFetcher.ReactiveBuilder
acceptingReactiveQueryByExampleExecutor
to build aDataFetcher
.- Type Parameters:
T
- the domain type of the repository- Parameters:
executor
- the QBE repository object to use- Returns:
- a new builder
-
autoRegistrationConfigurer
public static RuntimeWiringConfigurer autoRegistrationConfigurer(List<org.springframework.data.repository.query.QueryByExampleExecutor<?>> executors, List<org.springframework.data.repository.query.ReactiveQueryByExampleExecutor<?>> reactiveExecutors) Variation ofautoRegistrationConfigurer(List, List, CursorStrategy, ScrollSubrange)
without aCursorStrategy
and defaultScrollSubrange
. For default values, see the respective methods onQueryByExampleDataFetcher.Builder
andQueryByExampleDataFetcher.ReactiveBuilder
.- Parameters:
executors
- repositories to consider for registrationreactiveExecutors
- reactive repositories to consider for registration
-
autoRegistrationConfigurer
public static RuntimeWiringConfigurer autoRegistrationConfigurer(List<org.springframework.data.repository.query.QueryByExampleExecutor<?>> executors, List<org.springframework.data.repository.query.ReactiveQueryByExampleExecutor<?>> reactiveExecutors, @Nullable CursorStrategy<org.springframework.data.domain.ScrollPosition> cursorStrategy, @Nullable ScrollSubrange defaultScrollSubrange) Return aRuntimeWiringConfigurer
that installs aWiringFactory
to find queries with a return type whose name matches to the domain type name of the given repositories and registersDataFetcher
s for them.Note: This applies only to top-level queries and repositories annotated with
@GraphQlRepository
.- Parameters:
executors
- repositories to consider for registrationreactiveExecutors
- reactive repositories to consider for registrationcursorStrategy
- for decoding cursors in pagination requests; ifnull
, thenQueryByExampleDataFetcher.Builder.cursorStrategy
defaults apply.defaultScrollSubrange
- default parameters for scrolling; ifnull
, thenQueryByExampleDataFetcher.Builder.defaultScrollSubrange(int, java.util.function.Function<java.lang.Boolean, org.springframework.data.domain.ScrollPosition>)
defaults apply.- Returns:
- the created configurer
- Since:
- 1.2.0
-