Commit Graph

42 Commits

Author SHA1 Message Date
Brian Clozel
dd81d72fcb Start moving testing infra as test fixtures
This commit applies the `java-test-fixtures` to the project modules and
starts moving common infrastructure to the testFixtures configuration.

See gh-217
2021-12-10 22:52:14 +01:00
Brian Clozel
cfd0403008 Make id mandatory for RequestInput
This commit is a follow up of 2e4158c and makes the following changes:

* the id is now a mandatory attribute for `WebInput` and `RequestInput`
* a consistent IdGenerator strategy is configured for all requests

Closes gh-183
2021-11-25 12:30:56 +01:00
Brian Clozel
2e4158cae8 Set ExecutionId on web requests
Prior to this commit, the `WebInput` would hold an `id` attribute that
correlate the request and response messages on a multiplexed connection.

This commit moves this concept directly to the `RequestInput` so that it
can be used as an `ExecutionId` for all types of transports, if
availble.

This id was already set on the `WebInput` in the WebFlux case with the
id coming from the exchange, but it also creates an id and set it for
the MVC case. This id is then propagated to GraphQL's `ExecutionInput`.

See gh-183
2021-11-23 20:10:53 +01:00
Rossen Stoyanchev
0df1884500 Add option for expected errors to GraphQlTester
Closes: gh-175
2021-11-16 21:43:52 +00:00
Rossen Stoyanchev
5aac81c003 Polishing contribution
Closes gh-176
2021-11-03 17:25:26 +00:00
Koen Punt
a06ebdcd9c Allow variables with null values in GraphQlTester
See gh-176
2021-11-03 17:25:26 +00:00
Rossen Stoyanchev
2c8638dd6a HTTP handlers set Locale in ExecutionInput
See gh-3
2021-11-01 18:17:44 +00: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
21d9791484 Update reference docs for access to HTTP headers
Also rename existing methods for request headers to be consistent with
those for response headers and use "Http" in the name.

Closes gh-74
2021-10-01 17:36:49 +01:00
Rossen Stoyanchev
762b9f06c2 Support query files for input in GraphQlTester
Closes gh-67
2021-10-01 17:36:49 +01:00
Rossen Stoyanchev
5a07883f6a Make TestExecutionResult package private 2021-10-01 17:36:49 +01:00
Rossen Stoyanchev
6777d7613b Make GraphQlTester builders and request strategies top level classes 2021-10-01 17:36:49 +01:00
Rossen Stoyanchev
e644e5e192 Support classes for Builder, RequestStrategy, and RequestSpec
Also separate RequestStrategy from WebRequestStrategy since those are
delegated to internally and never used as a hierarchy. The generics
required to make them extend from each other bring no benefit.
2021-10-01 17:36:49 +01:00
Rossen Stoyanchev
65b5ff9a7c WebGraphQlTester exposes HTTP response headers
Closes gh-74
2021-10-01 17:36:49 +01:00
Rossen Stoyanchev
fb8e82dcc0 Inline GraphQlTesterBuilderConfig in DefaultGraphQlTester
It's simpler to pass the config options explicitly.
2021-10-01 17:36:49 +01:00
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
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
89d89e38ff Use WebInput#toMap in DefaultWebGraphQlTester
It doesn't cause any issues but noticed from logging output that when
WebTestClient is used, we are serializing all of it, rather than just
the RequestInput properties.
2021-07-15 20:21:24 +01:00
Rossen Stoyanchev
69c2d08c71 Remove formatter-on/off comments 2021-07-06 15:51:50 +01:00
Rossen Stoyanchev
04d6a72eec Use RequestInput as the input for GraphQlService 2021-07-02 21:20:09 +01:00
Rossen Stoyanchev
bbf152a32f Deserialize errorType from extensions
The errorType field on GraphQLError is specific to GraphQL Java and when
serialized via GraphqlErrorHelper#toSpecification it becomes an
extension with the key "classification".

This commit ensures that we correctly deserialize back to errorType from
the "classification" extension but unfortunately that's limited to the
ErrorClassification enums that we know of.
2021-06-29 14:53:50 +01:00
Rossen Stoyanchev
5822f7d357 Add @Nullable to TestGraphQlError 2021-06-27 21:51:05 +01:00
Rossen Stoyanchev
0b71596aa5 Global error filter in GraphQlTester.Builder
See gh-66
2021-06-27 21:50:37 +01:00
Rossen Stoyanchev
5cd1e266b4 Parameterize GraphQlTester.RequestSpec
This ensures that the order in which inputs are provided, i.e. whether
taken from the base RequestSpec or the Web subtype doesn't matter.

See gh-64
2021-06-27 21:50:00 +01:00
Rossen Stoyanchev
56ccaf685b GraphQlTester and WebGraphQlTester builders
Closes gh-66
2021-06-27 21:49:40 +01:00
Rossen Stoyanchev
4a6c718394 WebGraphQlTester supports HTTP header input
Closes gh-64
2021-06-26 17:48:30 +01:00
Rossen Stoyanchev
410948bde3 Undo more auto-formatting changes 2021-06-26 17:48:00 +01:00
Rossen Stoyanchev
de234c94c4 Decouple GraphQlTester from Web details
Closes gh-65
2021-06-26 05:16:35 +01:00
Brian Clozel
f8b2ad552f Refactor project build
This commit refactors the project build to better share dependency
management definitions between modules.

This also upgrades the project to Spring Boot 2.5.0.

Closes gh-45
2021-06-02 15:45:51 +02:00
Brian Clozel
39937679e3 Apply Spring JavaFormat to Spring GraphQL Test
See gh-54
2021-06-02 14:30:00 +02:00
Brian Clozel
5d4c08a30b Upgrade to Gradle 7.0.2 2021-05-18 17:53:08 +02:00
Rossen Stoyanchev
484fb932ef Replace QL with Ql for consistency with Spring naming 2021-05-14 21:32:54 +01:00
Rossen Stoyanchev
44a034ef3d Refine use of "query" in type and method names
Following revisions in the spec
https://github.com/graphql/graphql-spec/pull/777, this commit applies
similar changes to type and method names where feasible.

The chief exception for now is the use of "query" for request input
since that is what it is called in the JSON for GraphQL over HTTP.
2021-05-12 09:50:03 +01:00
Rossen Stoyanchev
f93c46eee3 WebInterceptor contract revision
WebInterceptor now uses delegation, forming a chain of interceptors
followed by a GraphQLService at the end to invoke graphql.GraphQL.

Closes gh-49
2021-04-30 21:26:26 +01:00
Rossen Stoyanchev
00b01ee524 Rename package for GraphQLTester 2021-04-26 21:59:52 +01:00
Rossen Stoyanchev
403019521c Rename spring-graphql-web to spring-graphql
Re-purpose spring-graphql-web to be more general than just web and add
org.springframework.web as a top-level package for web support.
2021-04-26 21:42:36 +01:00
Rossen Stoyanchev
1e619263d2 Reactor DataFetcher support
Closes gh-47
2021-04-26 10:03:53 +01:00
Rossen Stoyanchev
a57b78e521 Improve GraphQLTester error checking API
This commit introduces a dedicated ErrorSpec with the option to filter
out expected errors through Predicates.
2021-04-20 11:08:01 +01:00
Rossen Stoyanchev
efb72c7d13 Add tests for GraphQLTester
See gh-43
2021-04-15 13:00:52 +01:00
Rossen Stoyanchev
e22d3e8ea4 Add GraphQLTester
See gh-43
2021-04-15 13:00:20 +01:00