Commit Graph

78 Commits

Author SHA1 Message Date
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
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
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
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
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
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
Brian Clozel
d09f371048 Add missing configuration metadata for graphql metrics 2021-07-02 14:57:25 +02:00
Brian Clozel
2be79c2c73 Remove configuration key for GraphQL schema path
Currently, the GraphQL schema is exposed under /graphql/schema (so
relative to the main graphql endpoint) and is configurable with the
`spring.graphql.schema.printer.path` configuration property.

We think we should make the schema location more consistent to help
tools and various Gateway products. Also, we don't see right now a
strong use case for such a configuration property.

This commit removes the configuration property and sets the schema
location under `/graphql/schema`(`/graphql` being the main graphql path
configured by the application).

Closes gh-79
2021-07-02 13:57:36 +02:00
Rossen Stoyanchev
f17ae9307c Extract schema handling and move into main spring-graphql module 2021-07-02 10:25:18 +01:00
Rossen Stoyanchev
4740696ebf Move GraphiQl handlers to main spring-graphql module 2021-07-02 10:01:10 +01:00
Rossen Stoyanchev
9178075da5 Return 405 "Allow:POST" for HTTP GET queries
See gh-70
2021-07-01 15:48:55 +01:00
Brian Clozel
ef0fe03fce Scan schema locations for well-known file extensions
This commit improves gh-56 to scan schema locations for more well-known
file extensions, as previously only `*.graphqls` was supported.
We're now scanning for `*.graphqls`, `*.gqls`, `*.graphql`, `*.gql`.

Closes gh-56
2021-06-30 21:06:17 +02:00
Stephane Nicoll
a1e8571853 Harmonize copyright header 2021-06-30 15:44:24 +02:00
Stephane Nicoll
9d4ebfe743 Polish 2021-06-30 15:44:24 +02:00
Stephane Nicoll
4a1ee14f88 Add default value for "spring.graphql.locations" 2021-06-30 15:44:24 +02:00
Brian Clozel
fdf446f3e6 Load multiple GraphQL schema files
Prior to this commit, the `spring.graphql.schema.location` would only
allow a single file as the source for the GraphQL schema.

This commit changes this configuration to
`spring.graphql.schema.locations` so that it accepts actual locations
(folders) and scans for `*.graphqls` files in those locations. All files
are parsed and merged as a single GraphQL `TypeDefinitionRegistry`.

Closes gh-56
2021-06-29 21:27:18 +02:00
Brian Clozel
eef61843d3 Add property for GraphiQL UI path
This commit adds a new `spring.graphql.graphiql.path` configuration
property for setting the path to the GraphiQL UI page.

This change requires updates in the static HTML page to link the
JavaScript fetcher back to the actual GraphQL API endpoint.

Closes gh-70
2021-06-29 13:52:08 +02:00
Rossen Stoyanchev
de234c94c4 Decouple GraphQlTester from Web details
Closes gh-65
2021-06-26 05:16:35 +01:00
Rossen Stoyanchev
0ce48dc978 Turn off auto-formatting in Boot starter tests 2021-06-16 10:59:28 +01:00
Rossen Stoyanchev
43f9e34c81 Turn off auto-formatting where it reduces readability 2021-06-15 14:01:52 +01:00
Brian Clozel
f8b90b592d Apply Spring JavaFormat to Spring GraphQL Boot starter
This commit applies the build conventions to the Spring Boot GraphQL
starter module and fixes all formatting issues.

See gh-54
2021-06-02 14:30:00 +02:00
Brian Clozel
847c10be27 Add GraphQlTester test auto-configuration
This commit introduces the auto-configuration infrastructure for testing
Spring GraphQL applications with mock/embedded servers.

The new `@AutoConfigureGraphQlTester` annotation can contribute a
`GraphQlTester` bean to the test context for testing the application.

Closes gh-46
2021-05-31 21:35:54 +02:00
Rossen Stoyanchev
56917d8d83 ThreadLocal context propagation for DataFetcher's
The WebMvc starter now supports propagation of ThreadLocal values
extracted at the level of the HTTP handler.

Closes gh-53
2021-05-28 19:32:48 +01:00
Rossen Stoyanchev
ca18d03244 Add builder for WebGraphQlHandler
To allow adding more options when creating a WebGraphQlHandler.

See gh-53
2021-05-28 19:32:28 +01:00
Rossen Stoyanchev
eb88697b83 Polishing 2021-05-21 15:34:58 +01:00
Rossen Stoyanchev
cd8f4b672f Fix NPE on errors without a path
Errors that originate from GraphQL itself don't seem to have a path.
2021-05-21 15:34:58 +01:00