Commit Graph

105 Commits

Author SHA1 Message Date
Rossen Stoyanchev
a514704b3f Add missing autoconfig for Query By Example
See gh-191
2021-12-13 10:24:50 +00:00
Brian Clozel
3e29e71a6e Add support for Bean Validation
This commit adds support for validating handler method inputs after
binding from the data fetching environment and before invoking the
handler method.

This support is based on Bean Validation and is enabled only if the
application context contains a `Validator` bean.

Closes gh-110
2021-12-10 15:50:16 +01:00
Brian Clozel
b78808d54d Scan nested locations for GraphQL schema files
This commit changes the default value for the `spring.graphql.locations`
configuration property to `classpath:/graphql/**/`. By default, this
will scan nested locations for GraphQL schema files.

Fixes gh-210
2021-12-06 10:47:22 +01:00
Rossen Stoyanchev
6b1d5ebf64 Move graphiql index.html to spring-graphql
Closes gh-209
2021-12-02 15:53:36 +00:00
Rossen Stoyanchev
4d99d2ab31 Refactoring in query package
Increase sharing between QBE and Querydsl:
- shared GraphQLTypeVisitor for auto-registration
- utility methods for repository info
2021-11-26 19:19:08 +00:00
Rossen Stoyanchev
38f9f987e4 Combine querydsl and querybyexample into one package
Following the addition of Query By Example, it makes sense to
consolidate the two that mirror each other, are closely related, and
can share package private support.

See gh-191
2021-11-26 19:19:08 +00:00
Brian Clozel
201c828b38 Polish 2021-11-25 10:55:37 +01:00
Brian Clozel
b9932735db Revert "Auto-configure DataLoaderRegistrar components"
This reverts commit 36a84f58bd.
2021-11-25 10:55:20 +01:00
Brian Clozel
36a84f58bd Auto-configure DataLoaderRegistrar components
This commit configures all `DataLoaderRegistrar` application components
with the `GraphQlService`. This allows applications to contribute
`DataLoader` instances without using the annotated-controller
programming model.

Closes gh-189
2021-11-24 16:18:40 +01:00
Brian Clozel
d0adceee4b Configure GraphQlProperties even if GraphQlSource is defined
Prior to this commit, the main GraphQL auto-configuration would be
guarded with a condition on a `GraphQlSource` bean being missing. While
we want to prevent the auto-configuration from registering such a bean
if the user configuration already did so, we should still contribute the
`GraphQlProperties` bean to the context, as it is required for other
purposes.

This commit moves the condition directly on the bean method to avoid
this.

Fixes gh-186
2021-11-24 10:16:38 +01:00
Brian Clozel
02089a8542 Upgrade to Spring Boot 2.6.0-RC1
This commit upgrades the experimental starter to Spring Boot 2.6.0-RC1
and aligns all dependency versions to the Spring Boot dependency
management in 2.6.

This commit also removes temporary workarounds in the testing support or
in declared dependencies now that we've moved to 2.6.

While we're now using Spring Boot 2.6 as a reference version for this
project, the baseline didn't change and this commit documents the
requirements for this project; the Spring Data version, for our QueryDSL
support, is a specific example of that.

Fixes gh-181
2021-11-09 09:39:14 +01:00
Rossen Stoyanchev
dbf0fd704e Update GraphQlTest Javadoc 2021-10-28 14:17:04 +01:00
Brian Clozel
02d6cb1c59 Refine GraphQL testing infrastructure
After the introduction of the `@GraphQlTest` annotation, this commit
adds further refinements to the testing infrastructure.

Now, `@GraphQlTest` is completely independent of any web framework and
contributes a `GraphQlTester` component.

`@SpringBootTest` integration tests with mock servers only require an
`@AutoConfigureWebGraphQlTest` to get a `WebGraphQlTester` component.

Closes gh-75
2021-10-27 21:16:03 +02:00
Brian Clozel
e053e14158 Add GraphQlTest annotation
Prior to this commit, we could only test Spring GraphQL applications
with a complete application - all application and infrastructure
components were involved. While using `@SpringBootTest` is often useful
for complete integration tests (with or without a live running server),
we often want to write lean integration tests and test slices of our
application.

Just like `@WebMvcTest` or `@WebFluxTest`, this commit introduces the
support for `@GraphQlTest`. This annotation helps us to test a
particular slice of our application: a hand-picked selection of
`@Controller`, plus `RuntimeWiringConfigurer` and `WebInterceptor`
beans.

Other `@Component` must be imported or mocked for those tests.

This commit also refactors the existing auto-configuration to enable
this use case. The `WebGraphQlHandlerAutoConfiguration` now holds the
required components for `@GraphQlTest`, while other web-related
auto-configurations bring the web framework and transport
infrastructures.

Closes gh-75
2021-10-22 22:00:02 +02:00
Rossen Stoyanchev
20bae75ed8 Add WebSocketInterceptor
See gh-162
2021-10-20 21:21:31 +01:00
Rossen Stoyanchev
5a07883f6a Make TestExecutionResult package private 2021-10-01 17:36:49 +01:00
Brian Clozel
6975e6c37b Configure ConversionService for argument conversion
This commit configures a `FormattingConversionService` into the argument
resolution infrastructure, using the expected conversion service for
both MVC and WebFlux.

Closes gh-148
2021-09-30 15:26:22 +02:00
Rossen Stoyanchev
440b123cc4 Minor refactoring
Rename AnnotatedDataFetcherConfigurer -> AnnotatedControllerConfigurer,
since handler methods are now not only data fetchers but also
batch loaders.

Move DataFetcherHandlerMethod and BatchLoaderHandlerMethod into the
support package next to AnnotatedControllerConfigurer where they're used.

See gh-130
2021-09-29 17:56:08 +01:00
Rossen Stoyanchev
0bb8f58008 BatchLoaderRegistry extends DataLoaderRegistrar
Given that BatchLoaderRegistry is declared as a bean and injected into
ExecutionGraphQlService as a DataLoaderRegistrar, it makes sense to
have be a DataLoaderRegistrar vs declaring the bean as the
implementation type. A BatchLoaderRegistry is supposed to result in
DataLoader registrations so this makes sense in any case.
2021-09-27 09:23:01 +01:00
Brian Clozel
552c4f72d0 Add distribution summary metric for datafetcher calls
This commit adds a new `"graphql.request.datafetch.count"` distribution
summary metric for counting the number of data fetching calls per
request.

Closes gh-146
2021-09-22 16:53:08 +02:00
Rossen Stoyanchev
74ba9061d5 Polishing CORS support 2021-09-22 13:41:39 +01:00
Koen Punt
d550d384d8 Enable GraphiQL header editor
This commit enables a new tab in the GraphiQL UI that allows editing
request headers.

Closes gh-142
2021-09-21 21:06:57 +02:00
Brian Clozel
93c696f9bc Allow CORS configuration using config properties
Prior to this commit, a Spring GraphQL application would need to
implement `WebMvcConfigurer` or `WebFluxConfigurer` to register a
specific CORS configuration and map it to the GraphQL endpoint.

This commit adds new configuration properties under the
`spring.graphql.cors.*` namespace that helps configuring CORS for the
GraphQL endpoint.

Closes gh-26
2021-09-21 20:28:48 +02:00
Rossen Stoyanchev
ea37c3b5a7 Simplify AnnotatedDataFetcherConfigurer config
Now that we don't use JSON conversion for input arguments, we can
declare AnnotatedDataFetcherConfigurer in shared config.

See gh-122
2021-09-21 12:52:07 +01:00
Brian Clozel
f69aa39211 Only scan for *.graphqls and *.gqls schema files
Prior to this commit, the auto-configuration was scanning for
`"*.graphql,*.gql,*.graphqls,*.gqls"` files in the configured locations.
This was not flexible enough, as developers could not customize the
considered file extensions when scanning for files.

This commit provides a new `spring.graphql.schema.file-extensions`
configuration property that enables such customizations.

Because `"*.graphql,*.gql"` extensions seem to be tied to queries
(and not schemas), this commit also changes the default value to only
consider the `"*.graphqls,*.gqls"` file extensions by default.

Closes gh-134
Closes gh-135
2021-09-20 10:29:41 +02:00
Brian Clozel
762f59b2f3 Configure compiler conventions in modules
This commit applies the Compiler Conventions Gradle plugin to the
project modules and fix the issues raised by the compiler linter.

This commit also moves version management to the main build file for a
few dependencies, aligning the versions in the process.
2021-09-16 19:54:25 +02:00
Rossen Stoyanchev
892d2bd344 Use properties for Boot and GraphQL Java versions 2021-09-16 11:15:47 +01:00
Rossen Stoyanchev
1b72e8107d Update Spring Boot version 2.5.0 -> 2.5.4 2021-09-16 10:21:45 +01:00
Rossen Stoyanchev
1bdcb8afe8 Add DataLoaderMethodArgumentResolver
This commit adds support for DataLoader<K,V> arguments on annotated
handler methods, where the key for the lookup is the class name of the
value type or the parameter name.

See gh-63
2021-09-14 09:15:41 +01:00
Rossen Stoyanchev
ddafc93c6c Add BatchLoaderRegistry
The registry is an application API for registering batch loading
functions along with DataLoaderOption's.

See gh-63
2021-09-14 09:09:44 +01:00
Brian Clozel
0587913ccb Allow configuring schema through GraphQlSource customizer
As of gh-117, the GraphQlAutoConfiguration throws an exception if no
schema file was found while scanning configured locations.
This prevents developers from manually configuring the schema using
`GraphQlSourceBuilderCustomizer` instances.

This commit ensures that a `MissingSchemaException` is only raised if no
schema was configured at the time we're building the actual
GraphQlSource.

This exception is later wrapped by the GraphQlAutoConfiguration to raise
an `InvalidSchemaLocationsException` with useful information about
configured schema locations.

Fixes gh-124
2021-09-02 11:36:49 +02:00
Rossen Stoyanchev
4bfe85e6b3 Fix package cycle 2021-08-31 14:58:13 +01:00
Brian Clozel
7c58fb90af Fix configuration metadata for schema location property
Fixes gh-118
2021-08-27 20:39:46 +02:00
Brian Clozel
625f0b685b Add FailureAnalyzer for schema location issues
Prior to this commit, the schema locations configured with
`spring.graphql.schema.locations` could fail in several cases:
* one of the provided locations cannot be resolved as a Resource
* none of the provided locations holds an actual schema file

The latter can happen if several classpath locations match a given
location and the wrong one is considered first.

This commit introduces a new `MissingSchemaException` that holds the
locations information. We're adding the relevant FailureAnalyzer to help
developers troubleshoot such configurations issues.

Fixes gh-117
2021-08-27 20:36:05 +02:00
Rossen Stoyanchev
60b0684d80 Minor refactoring and polishing 2021-08-13 04:48:49 +01:00
Rossen Stoyanchev
020303d0fd Dependency upgrades
GraphQL Java 17.0 -> 17.1
Reactor -> 2020.0.7 -> 2020.0.9
Spring Framework 5.3.7 -> 5.3.9
Spring Data 2021.0.1 -> 2021.0.3
Jackson 2.12.3 -> 2.12.4
2021-08-10 08:15:30 +01:00
Rossen Stoyanchev
3567a062ab Add RuntimeWiringConfigurer
Closes gh-107
2021-08-09 16:36:18 +01:00
Rossen Stoyanchev
8db2bf9680 Move querydsl support into sub-package
Following the addition of annotated DataFetcher's the `~.data.method`
with #90, it makes sense to have querydsl support at the same level
in a sibling package.
2021-08-09 12:49:36 +01:00
Rossen Stoyanchev
0d0b84dc8a Support for annotated DataFetcher's
Closes gh-61, gh-90
2021-08-09 12:37:47 +01:00
Rossen Stoyanchev
317d75cc8a Upgrade to GraphQL Java 17.0
Closes gh-84
2021-08-03 10:25:57 +01:00
Rossen Stoyanchev
15e2e6c271 Minor refactoring in GraphQlSource.Builder
Rename runtimeWiring to configureRuntimeWiring for consistency with
the configureGraphQl methods that's also Consumer based.
2021-07-26 16:50:12 +01:00
Brian Clozel
5c7b809aa3 Simplify GraphQlSource auto-configuration
This commit simplifies the `GraphQL` configuration by focusing the
infrastructure around the `GraphQlSource` auto-configuration.

With this commit, the auto-configuration contributes a single
`GraphQlSource` bean and removes the previoulsy contributed beans:
`GraphQlSource.Builder` and `RuntimeWiring`.

If a developer wants to take full control over the GraphQL setup, then
contributing a `GraphQlSource` bean is the easiest solution.

This commit also improves the `GraphQlSource.Builder` and allows for
customizing the `RuntimeWiring.Builder` instead of providing a direct
instance. This aligns well with the `RuntimeWiringBuilderCustomizer`
interface provided by the starter.

Closes gh-101
2021-07-23 10:00:29 +02:00
Rossen Stoyanchev
759b83ffa8 Upgrade to GraphQL Java 0.0.0-2021-07-21T06-48-56-713bb637
Use more efficient way to update the code registry in GraphQLSchema.

See gh-84
2021-07-21 13:52:49 +01:00
Rossen Stoyanchev
4078799e34 Auto-register Querydsl DataFetcher's only for top-level queries
Closes gh-93
2021-07-20 13:42:26 +01:00
Rossen Stoyanchev
c148eb40b4 Auto registration of Querydsl DataFetcher's
See gh-93
2021-07-19 16:26:44 +01:00
Rossen Stoyanchev
873ecd6b29 Add GraphQlSourceBuilderCustomizer
See gh-93, gh-85
2021-07-19 16:26:44 +01:00
Rossen Stoyanchev
706766536d Upgrade to GraphQL Java pre-17 version
See gh-84
2021-07-08 21:24:18 +01:00
Brian Clozel
f1bc239b57 Add Spring Security auto-configuration
This commit adds two new auto-configuration classes that provide the
relevant Spring Security infrastructure for GraphQL applications:

* a `ThreadLocalAccessor` that propagates the security context in
Spring MVC applications
* `DataFetcherExceptionResolver` implementations that resolve security
  exception from data fetchers, for both MVC and WebFlux

Closes gh-81
2021-07-06 16:58:34 +02:00
Brian Clozel
58d65d7a4c Refine auto-configurations conditions
Prior to this commit, auto-configurations were only checking for the
presence of GraphQL Java classes as guards, assuming that Spring
GraphQL classes were always on the classpath.

Auto-configurations are meant to be moved to the Spring Boot project in
the future, so this commit adds the relevant condition class checks to
reflect that spring-graphql might not be on the classpath.
2021-07-06 16:57:05 +02:00
Rossen Stoyanchev
69c2d08c71 Remove formatter-on/off comments 2021-07-06 15:51:50 +01:00