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) Variation ofautoRegistrationConfigurer(List, List, CursorStrategy, ScrollSubrange)without aCursorStrategyand defaultScrollSubrange.static RuntimeWiringConfigurerautoRegistrationConfigurer(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 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>buildExample(DataFetchingEnvironment environment) Prepare anExamplefrom GraphQL request arguments.protected Collection<String>buildPropertyPaths(DataFetchingFieldSelectionSet selection, Class<?> resultType) protected ScrollSubrangebuildScrollSubrange(DataFetchingEnvironment environment) Provides shared implementation ofSelfDescribingDataFetcher.getDescription()for all subclasses.protected booleanrequiresProjection(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 anExamplefrom 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) -
buildScrollSubrange
-
toString
-
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) Variation ofautoRegistrationConfigurer(List, List, CursorStrategy, ScrollSubrange)without aCursorStrategyand defaultScrollSubrange. For default values, see the respective methods onQueryByExampleDataFetcher.BuilderandQueryByExampleDataFetcher.ReactiveBuilder. -
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 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 registrationcursorStrategy- for decoding cursors in pagination requests; ifnull, thenQueryByExampleDataFetcher.Builder.cursorStrategydefaults apply.defaultScrollSubrange- default parameters for scrolling; ifnull, thenQueryByExampleDataFetcher.Builder.defaultScrollSubrange(org.springframework.graphql.data.query.ScrollSubrange)defaults apply.- Returns:
- the created configurer
- Since:
- 1.2.0
-
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)