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) 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 GraphQLTypeVisitor
autoRegistrationTypeVisitor
(List<org.springframework.data.repository.query.QueryByExampleExecutor<?>> executors, List<org.springframework.data.repository.query.ReactiveQueryByExampleExecutor<?>> reactiveExecutors) Deprecated.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>
Prepare anExample
from GraphQL request arguments.protected Collection<String>
buildPropertyPaths
(DataFetchingFieldSelectionSet selection, Class<?> resultType) protected boolean
requiresProjection
(Class<?> resultType)
-
Method Details
-
buildExample
protected org.springframework.data.domain.Example<T> buildExample(DataFetchingEnvironment env) throws BindException Prepare anExample
from GraphQL request arguments.- Parameters:
env
- contextual info for the GraphQL request- Returns:
- the resulting example
- Throws:
BindException
-
requiresProjection
-
buildPropertyPaths
protected Collection<String> buildPropertyPaths(DataFetchingFieldSelectionSet selection, Class<?> resultType) -
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) 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 registration- Returns:
- the created configurer
-
autoRegistrationTypeVisitor
@Deprecated public static GraphQLTypeVisitor autoRegistrationTypeVisitor(List<org.springframework.data.repository.query.QueryByExampleExecutor<?>> executors, List<org.springframework.data.repository.query.ReactiveQueryByExampleExecutor<?>> reactiveExecutors) Deprecated.in favor ofautoRegistrationConfigurer(List, List)
Create aGraphQLTypeVisitor
that finds queries with a return type whose name matches to the domain type name of the given repositories and registersDataFetcher
s for those queries.Note: currently, this method will match only to queries under the top-level "Query" type in the GraphQL schema.
- Parameters:
executors
- repositories to consider for registrationreactiveExecutors
- reactive repositories to consider for registration- Returns:
- the created visitor
-
autoRegistrationConfigurer(List, List)