Class QuerydslDataFetcher<T>

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

public abstract class QuerydslDataFetcher<T> extends Object
Main class to create a DataFetcher from a Querydsl repository. To create an instance, use one of the following:

For example:

 interface BookRepository extends
         Repository<Book, String>, QuerydslPredicateExecutor<Book>{}

 TypeRuntimeWiring wiring = … ;
 BookRepository repository = … ;

 DataFetcher<?> forMany =
         wiring.dataFetcher("books", QuerydslDataFetcher.builder(repository).many());

 DataFetcher<?> forSingle =
         wiring.dataFetcher("book", QuerydslDataFetcher.builder(repository).single());
 

See QuerydslDataFetcher.Builder and QuerydslDataFetcher.ReactiveBuilder methods for further options on GraphQL Query argument to Querydsl Predicate binding customizations, result projections, and sorting.

QuerydslDataFetcher exposes a RuntimeWiringConfigurer that can auto-register repositories annotated with @GraphQlRepository.

Since:
1.0.0
Author:
Mark Paluch, Rossen Stoyanchev
See Also:
  • Method Details

    • buildPredicate

      protected com.querydsl.core.types.Predicate buildPredicate(DataFetchingEnvironment environment)
      Prepare a Predicate from GraphQL request arguments, also applying any QuerydslBinderCustomizer that may have been configured.
      Parameters:
      environment - contextual info for the GraphQL request
      Returns:
      the resulting predicate
    • requiresProjection

      protected boolean requiresProjection(Class<?> resultType)
    • buildPropertyPaths

      protected Collection<String> buildPropertyPaths(DataFetchingFieldSelectionSet selection, Class<?> resultType)
    • builder

      public static <T> QuerydslDataFetcher.Builder<T,T> builder(org.springframework.data.querydsl.QuerydslPredicateExecutor<T> executor)
      Create a new QuerydslDataFetcher.Builder accepting QuerydslPredicateExecutor to build a DataFetcher.
      Type Parameters:
      T - result type
      Parameters:
      executor - the repository object to use
      Returns:
      a new builder
    • builder

      public static <T> QuerydslDataFetcher.ReactiveBuilder<T,T> builder(org.springframework.data.querydsl.ReactiveQuerydslPredicateExecutor<T> executor)
      Create a new QuerydslDataFetcher.ReactiveBuilder accepting ReactiveQuerydslPredicateExecutor to build a reactive DataFetcher.
      Type Parameters:
      T - result type
      Parameters:
      executor - the repository object to use
      Returns:
      a new builder
    • autoRegistrationConfigurer

      public static RuntimeWiringConfigurer autoRegistrationConfigurer(List<org.springframework.data.querydsl.QuerydslPredicateExecutor<?>> executors, List<org.springframework.data.querydsl.ReactiveQuerydslPredicateExecutor<?>> 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. If a repository is also an instance of QuerydslBinderCustomizer, this is transparently detected and applied through the QuerydslDataFetcher builder methods.

      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.querydsl.QuerydslPredicateExecutor<?>> executors, List<org.springframework.data.querydsl.ReactiveQuerydslPredicateExecutor<?>> reactiveExecutors)
      Return a GraphQLTypeVisitor that auto-registers the given Querydsl repositories for queries that do not already have a registered DataFetcher and whose return type matches the simple name of the repository domain type.

      Note: Auto-registration applies only to @GraphQlRepository-annotated repositories. If a repository is also an instance of QuerydslBinderCustomizer, this is transparently detected and applied through the QuerydslDataFetcher builder methods.

      Parameters:
      executors - repositories to consider for registration
      reactiveExecutors - reactive repositories to consider for registration
      Returns:
      the created visitor