From 58f2afebb5d4d70c7fc91b477f74d9203a3a09a4 Mon Sep 17 00:00:00 2001 From: Rossen Stoyanchev Date: Thu, 9 Dec 2021 21:23:37 +0000 Subject: [PATCH] Polishing contribution Closes gh-215 --- .../src/docs/asciidoc/index.adoc | 21 +++++++++---------- .../data/query/QueryByExampleDataFetcher.java | 4 ++-- .../QueryByExampleDataFetcherJpaTests.java | 2 +- ...QueryByExampleDataFetcherMongoDbTests.java | 2 +- ...xampleDataFetcherReactiveMongoDbTests.java | 2 +- 5 files changed, 15 insertions(+), 16 deletions(-) diff --git a/spring-graphql-docs/src/docs/asciidoc/index.adoc b/spring-graphql-docs/src/docs/asciidoc/index.adoc index 591a869e..fd12569b 100644 --- a/spring-graphql-docs/src/docs/asciidoc/index.adoc +++ b/spring-graphql-docs/src/docs/asciidoc/index.adoc @@ -538,12 +538,11 @@ detects `@GraphQlRepository` beans and applies the `GraphQLTypeVisitor`. === Query by Example Spring Data supports the use of -https://docs.spring.io/spring-data/commons/docs/current/reference/html/#query-by-example[Query by Example] as a means to -fetch data. -Query by Example provides a flexible approach to express queries by allowing the user to define what fields are vital -and what are not. +https://docs.spring.io/spring-data/commons/docs/current/reference/html/#query-by-example[Query by Example] +to fetch data. Query by Example (QBE) is a simple querying technique that does not require +you to write queries through store-specific query languages. -For example, declare a repository as `QueryByExampleExecutor`: +Start by declaring a repository that is `QueryByExampleExecutor`: [source,java,indent=0,subs="verbatim,quotes"] ---- @@ -552,7 +551,7 @@ public interface AccountRepository extends Repository, } ---- -Then use it to create a `DataFetcher`: +Use `QueryByExampleDataFetcher` to turn the repository into a `DataFecher`: [source,java,indent=0,subs="verbatim,quotes"] ---- @@ -565,9 +564,9 @@ Then use it to create a `DataFetcher`: QueryByExampleDataFetcher.builder(repository).many(); ---- -The `DataFetcher` builds a Query by Example `Example` from GraphQL request parameters, and -uses it to fetch data. Spring Data supports `QueryByExampleDataFetcher` for JPA, -MongoDB, Neo4j, and Redis. +The `DataFetcher` uses the GraphQL arguments map to create the domain type of the +repository and use that as the example object to fetch data with. Spring Data supports +`QueryByExampleDataFetcher` for JPA, MongoDB, Neo4j, and Redis. If the repository is `ReactiveQueryByExampleExecutor`, the builder returns `DataFetcher>` or `DataFetcher>`. Spring Data supports this @@ -577,8 +576,8 @@ variant for MongoDB, Neo4j, Redis, and R2dbc. [[data-querybyexample-build]] ==== Build Setup -Query by Example is already included in the Spring Data modules that support it. -No extra setup is required to enable it. +Query by Example is already included in the Spring Data modules for the data stores where +it is supported, so no extra setup is required to enable it. [[data-querybyexample-customizations]] diff --git a/spring-graphql/src/main/java/org/springframework/graphql/data/query/QueryByExampleDataFetcher.java b/spring-graphql/src/main/java/org/springframework/graphql/data/query/QueryByExampleDataFetcher.java index 8eb257be..2f82e226 100644 --- a/spring-graphql/src/main/java/org/springframework/graphql/data/query/QueryByExampleDataFetcher.java +++ b/spring-graphql/src/main/java/org/springframework/graphql/data/query/QueryByExampleDataFetcher.java @@ -70,7 +70,7 @@ import org.springframework.util.Assert; * {@link QueryByExampleDataFetcher.ReactiveBuilder} for further options on * result projections and sorting. * - *

{@code QueryByExampleDataFetcher} {@link #registrationTypeVisitor(List, List) exposes} + *

{@code QueryByExampleDataFetcher} {@link #autoRegistrationTypeVisitor(List, List) exposes} * a {@link GraphQLTypeVisitor} that can auto-register repositories annotated with * {@link GraphQlRepository @GraphQlRepository}. * @@ -161,7 +161,7 @@ public abstract class QueryByExampleDataFetcher { * @param reactiveExecutors reactive repositories to consider for registration * @return the created visitor */ - public static GraphQLTypeVisitor registrationTypeVisitor( + public static GraphQLTypeVisitor autoRegistrationTypeVisitor( List> executors, List> reactiveExecutors) { diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/jpa/QueryByExampleDataFetcherJpaTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/jpa/QueryByExampleDataFetcherJpaTests.java index 941ba955..caad7186 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/jpa/QueryByExampleDataFetcherJpaTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/jpa/QueryByExampleDataFetcherJpaTests.java @@ -179,7 +179,7 @@ class QueryByExampleDataFetcherJpaTests { private static GraphQlSetup initGraphQlSetup(@Nullable QueryByExampleExecutor executor) { - GraphQLTypeVisitor visitor = QueryByExampleDataFetcher.registrationTypeVisitor( + GraphQLTypeVisitor visitor = QueryByExampleDataFetcher.autoRegistrationTypeVisitor( executor != null ? Collections.singletonList(executor) : Collections.emptyList(), Collections.emptyList()); diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/QueryByExampleDataFetcherMongoDbTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/QueryByExampleDataFetcherMongoDbTests.java index ceeb1ef6..ec972827 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/QueryByExampleDataFetcherMongoDbTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/QueryByExampleDataFetcherMongoDbTests.java @@ -177,7 +177,7 @@ class QueryByExampleDataFetcherMongoDbTests { private static GraphQlSetup initGraphQlSetup(@Nullable QueryByExampleExecutor executor) { - GraphQLTypeVisitor visitor = QueryByExampleDataFetcher.registrationTypeVisitor( + GraphQLTypeVisitor visitor = QueryByExampleDataFetcher.autoRegistrationTypeVisitor( (executor != null ? Collections.singletonList(executor) : Collections.emptyList()), Collections.emptyList()); diff --git a/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/QueryByExampleDataFetcherReactiveMongoDbTests.java b/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/QueryByExampleDataFetcherReactiveMongoDbTests.java index 7744d0f6..e2b76d3a 100644 --- a/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/QueryByExampleDataFetcherReactiveMongoDbTests.java +++ b/spring-graphql/src/test/java/org/springframework/graphql/data/query/mongo/QueryByExampleDataFetcherReactiveMongoDbTests.java @@ -149,7 +149,7 @@ class QueryByExampleDataFetcherReactiveMongoDbTests { private static GraphQlSetup initGraphQlSetup(@Nullable ReactiveQueryByExampleExecutor executor) { - GraphQLTypeVisitor visitor = QueryByExampleDataFetcher.registrationTypeVisitor( + GraphQLTypeVisitor visitor = QueryByExampleDataFetcher.autoRegistrationTypeVisitor( Collections.emptyList(), (executor != null ? Collections.singletonList(executor) : Collections.emptyList()));