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:
-
GraphQlRepositoryQueryByExampleExecutorReactiveQueryByExampleExecutorExample- Spring Data Query By Example extension
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classBuilder for a Query by Example-basedDataFetcher.static interfaceCallback interface that can be used to customize QueryByExampleDataFetcherQueryByExampleDataFetcher.Builderto change its configuration.static classBuilder for a reactive Query by Example-basedDataFetcher.static interfaceCallback interface that can be used to customize QueryByExampleDataFetcherQueryByExampleDataFetcher.ReactiveBuilderto change its configuration. -
Method Summary
Modifier and TypeMethodDescriptionstatic RuntimeWiringConfigurerautoRegistrationConfigurer(List<org.springframework.data.repository.query.QueryByExampleExecutor<?>> executors, List<org.springframework.data.repository.query.ReactiveQueryByExampleExecutor<?>> reactiveExecutors) Return aRuntimeWiringConfigurerthat installs aWiringFactoryto find queries with a return type whose name matches to the domain type name of the given repositories and registersDataFetchers for them.static GraphQLTypeVisitorautoRegistrationTypeVisitor(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.BuilderacceptingQueryByExampleExecutorto build aDataFetcher.static <T> QueryByExampleDataFetcher.ReactiveBuilder<T,T> builder(org.springframework.data.repository.query.ReactiveQueryByExampleExecutor<T> executor) Create a newQueryByExampleDataFetcher.ReactiveBuilderacceptingReactiveQueryByExampleExecutorto build aDataFetcher.protected org.springframework.data.domain.Example<T>Prepare anExamplefrom GraphQL request arguments.protected Collection<String>buildPropertyPaths(DataFetchingFieldSelectionSet selection, Class<?> resultType) protected booleanrequiresProjection(Class<?> resultType)
-
Method Details
-
buildExample
protected org.springframework.data.domain.Example<T> buildExample(DataFetchingEnvironment env) throws BindException Prepare anExamplefrom 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.BuilderacceptingQueryByExampleExecutorto 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.ReactiveBuilderacceptingReactiveQueryByExampleExecutorto 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 aRuntimeWiringConfigurerthat installs aWiringFactoryto find queries with a return type whose name matches to the domain type name of the given repositories and registersDataFetchers 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 aGraphQLTypeVisitorthat finds queries with a return type whose name matches to the domain type name of the given repositories and registersDataFetchers 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)