Commit Graph

318 Commits

Author SHA1 Message Date
Rossen Stoyanchev
f0f883cc39 Inline RequestSpecDelegate in DefaultGraphQlTester
The delegate has almost no logic, simply holding fields and calling the
RequestStrategy, so it adds cognitive overhead without benefit.
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
a66b49540b Polishing docs and removing unused code 2021-09-29 18:25:24 +01: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
0f37af1b25 Update default extensions in reference docs
See gh-134
2021-09-29 15:59:52 +01:00
Rossen Stoyanchev
5109a1195f Update documentation for @BatchMapping
Closes gh-130
2021-09-28 15:09:39 +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
Rossen Stoyanchev
56ca50e6f3 Support for @BatchMapping methods
See gh-130
2021-09-27 09:22:32 +01:00
Rossen Stoyanchev
fbe87359ac Extract InvocableHandlerMethodSupport
This prepares the way to invoke handler methods other than those
adapted to a DataFetcher with DataFetcherEnvironment as input.

See gh-130
2021-09-27 09:21:28 +01:00
Rossen Stoyanchev
f8f6a3ed9f Register batch load function by name
This is an alternative to providing the key and value types, which are
only used to form the DataLoader name.

See gh-130
2021-09-27 09:20:42 +01:00
Rossen Stoyanchev
d68edb47c9 Polishing annotated DataFetcher tests
See gh-130
2021-09-27 09:20:05 +01:00
Rossen Stoyanchev
5a8a99aea2 Refactoring in AnnotatedDataFetcherConfigurer
Introduce MappingInfo to allow passing additional mapping metadata up
the stack. In preparation for @BatchMapping methods.

See gh-130
2021-09-27 09:19:21 +01:00
Brian Clozel
b03097ad47 Remove attributes from Argument annotation
Prior to this commit, the `@Argument` annotation would support two
attributes: `required` and `defaultValue`, specifying whether arguments
should be considered as required and default values to use if they're
not present.

This can be problematic as this can already be specified at the schema
level.

To avoid duplication and invalid setups betweens schema and Controllers,
this commit removes those attributes in favor of the schema definition.

Closes gh-150
2021-09-24 13:47:56 +02:00
Rossen Stoyanchev
e0952a2791 Dependency upgrades for the Boot 2.5.5 release 2021-09-23 16:31:58 +01:00
Brian Clozel
b0dedbeb64 Polish "Recursively instantiate arguments"
Closes gh-147
2021-09-22 19:51:52 +02:00
Koen Punt
77f5875eac Recursively instantiate input arguments
Prior to this commit, the `GraphQlArgumentInstantiator` would not
instantiate and bind properly types with a list attribute that has
elements which need to be instantiated with a primary constructor.

This commit ensures that every list that is encountered is
recursively passed to the instantiator, instead of trying to
convert the list using the databinder.

This also fixes gh-145, by directly accessing the arguments from
the arguments map, instead of the mapped propertyvalues used for
the DataBinder.

See gh-147
2021-09-22 19:03:00 +02: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
Brian Clozel
b830fe9f3a Fix NPE for non-required missing input arguments
Prior to this commit, a missing, non-required input argument would throw
an NullPointerException instead of returning `null` or
`Optional.empty()`.

Fixes gh-144
2021-09-22 11:06:46 +02:00
Brian Clozel
17ce7b4838 Simplify asciidoctor setup for reference docs 2021-09-21 22:08:15 +02: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
Brian Clozel
543be8429f Introduce version attributes in asciidoctor docs
This commit introduces versions as dynamic attributes in the reference
docs. This also fixes a few incomplete references that were logging
warnings during the documentation build.
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
02b16bdc65 Polish "Support contructor binding for input arguments"
Prior to this commit, only default constructors were supported for
instantiating input argument types. This commit adds a new
`GraphQlInstantiator` class that manages the instantiation and binding
of data fetching environment arguments. Default constructors and
primary constructors are now handled.

Also, List-like properties were not bound from the data fetching
environment arguments to the `MutablePropertyValues` used for binding.
This commit ensures that List elements are bound to the property values
with array-like property paths.

Fixes gh-139
Fixes gh-141
2021-09-21 09:45:45 +02:00
Koen Punt
2f5aa588ef Support contructor binding for input arguments
See gh-139
2021-09-21 09:44:34 +02: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
Rossen Stoyanchev
94809537cb Upgrade GraphQL Java 17.2 -> 17.3 2021-09-20 07:39:46 +01:00
Brian Clozel
4dfb662669 Refactor input argument binding
Prior to this commit, `@Argument`-annotated controller method parameters
were bound from the environment by serializing the environment argument
map to JSON and deserialized back to the target parameter type.

This allowed to cover a large spectrum of cases but showed some
limitations: performance could be improved and custom scalars could be
overridden in the process.

This commit removes the (de)serialization process and instead:

* runs through the environment argument map to collect all properties in
  a `MutablePropertyValues` map
* instantiate the target type if necessary
* binds properties to the target type using a `DataBinder`

With this change, scalar types should not be erased and arguments now
support a wider range of Collection types.

Closes gh-122
2021-09-17 14:00:37 +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
Brian Clozel
5c5554b6b1 Add compiler conventions in Gradle build
This commit configures a CompilerConventions Gradle Plugin that
configures the compiler for main and test sources.
2021-09-16 17:37:49 +02:00
Rossen Stoyanchev
9e8682ff8c Polishing contribution
See gh-132
2021-09-16 11:41:59 +01:00
Koen Punt
3ef86492e3 Filter out Kotlin Continuation when resolving arguments
The `kotlin.coroutines.Continuation` argument that is passed for
suspended function was parsed erroneously as a GraphQL "source"
argument. This commit adds a resolver for Continuation that resolves
it  to `null`, which allows suspended functions to work.

Closes gh-132
2021-09-16 11:39:10 +01: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
b021663f5b Update docs for batch loading
Closes gh-63
2021-09-15 15:54:00 +01:00
Koen Punt
e24943ac70 docblock update 2021-09-14 17:55:55 +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
Rossen Stoyanchev
9228872f44 Improve exception logging 2021-09-13 10:54:39 +01:00
Rossen Stoyanchev
a056d5ba06 Add Exceptions section to Boot starter ref docs
See gh-121
2021-09-03 14:01:10 +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
Brian Clozel
771c42bfbe Fix missing GitHub credentials in release pipeline 2021-08-31 18:06:37 +02:00
Brian Clozel
0c17ad59bf Upgrade JDK versions 2021-08-31 17:39:49 +02:00
Brian Clozel
d3316d7a72 Upgrade Ubuntu in CI image 2021-08-31 17:39:31 +02:00
Rossen Stoyanchev
4bfe85e6b3 Fix package cycle 2021-08-31 14:58:13 +01:00
Rossen Stoyanchev
a98ca42981 Add resolver for @Argument Map<String, Object>
Closes gh-113
2021-08-31 14:44:47 +01:00
Rossen Stoyanchev
60e65078c2 Fix outdated links in README files 2021-08-31 07:44:10 +01:00
Rossen Stoyanchev
8cebe20a56 Defensively build GraphQLError
GraphqlErrorBuilder expects a non-null error message so we need to
check if the exception has one, or otherwise the resulting assert
error masks the original one.
2021-08-30 16:49:28 +01:00
Rossen Stoyanchev
cae12820e4 Replace @GraphQlController in documentation snippets 2021-08-30 16:44:56 +01:00