Class QueryByExampleDataFetcher<T>

java.lang.Object
org.springframework.graphql.data.query.QueryByExampleDataFetcher<T>
Type Parameters:
T - returned result type

public abstract class QueryByExampleDataFetcher<T> extends Object
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:
  • Method Details

    • buildExample

      protected org.springframework.data.domain.Example<T> buildExample(DataFetchingEnvironment env) throws BindException
      Prepare an Example from GraphQL request arguments.
      Parameters:
      env - contextual info for the GraphQL request
      Returns:
      the resulting example
      Throws:
      BindException
    • requiresProjection

      protected boolean requiresProjection(Class<?> resultType)
    • 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 new QueryByExampleDataFetcher.Builder accepting QueryByExampleExecutor to build a DataFetcher.
      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 new QueryByExampleDataFetcher.ReactiveBuilder accepting ReactiveQueryByExampleExecutor to build a DataFetcher.
      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 a RuntimeWiringConfigurer that installs a WiringFactory to find queries with a return type whose name matches to the domain type name of the given repositories and registers DataFetchers for them.

      Note: This applies only to top-level queries and repositories annotated with @GraphQlRepository.

      Parameters:
      executors - repositories to consider for registration
      reactiveExecutors - 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)
      Create a GraphQLTypeVisitor that finds queries with a return type whose name matches to the domain type name of the given repositories and registers DataFetchers 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 registration
      reactiveExecutors - reactive repositories to consider for registration
      Returns:
      the created visitor