Commit Graph

69 Commits

Author SHA1 Message Date
rstoyanchev
bb4ebf6cb8 Correct names of AbstractDirectTransport and subclasses
See gh-332
2022-03-21 04:24:26 +00:00
rstoyanchev
91e7f285fa Shorten GraphQlResponse[Field|Error] and rename GraphQlService
Rename GraphQlService to ExecutionGraphQlService following the renaming
of the request and response to ExecutionGraphQl[Request|Response].

See gh-332
2022-03-21 04:23:59 +00:00
rstoyanchev
67711f7331 Rename Web[Input|Output] to WebGraphQl[Request|Response]
See gh-332
2022-03-21 04:23:34 +00:00
rstoyanchev
182e9e66f0 Extract ExecutionGraphQl[Request|Response] interfaces
Rename the implementation classes Request[Input|Output] accordingly to
match the interfaces, and move them into the support package.

Create AbstractGraphQlResponse in the support package that
pre-implements response field access.

This leaves mainly contracts in the top-level package.

See gh-332
2022-03-21 04:22:01 +00:00
rstoyanchev
be05b031d6 Extract GraphQlRequest interface
See gh-332
2022-03-21 04:21:33 +00:00
rstoyanchev
db24c8f62b Replace GraphQLError with GraphQlResponseError
This allows exposing additional conveniences for inspecting errors.

See gh-10
2022-03-18 18:19:08 +00:00
rstoyanchev
96135183f5 Refactor MapGraphQlResponse
MapGraphQlResponse is a simple wrapper around the response map exposing
it as GraphQlResponse. It is now package private and made accessible
through a static factory method on GraphQlTransport.

See gh-10
2022-03-17 19:56:31 +00:00
rstoyanchev
38a9eb1b3c Align client with GraphQL Java error paths
DefaultClientGraphQlResponse now parses the path to a field and creates
the same parsed representation as GraphQL Java does and uses for
GraphQLError paths. This makes it easier to correlate fields to field
errors and eliminates the need for a dependency on JSONPath in the
client.

See gh-10
2022-03-15 09:00:28 +00:00
rstoyanchev
dcb752dde4 Introduce ClientGraphQlResponse
Extends GraphQlResponse with a subtype that exposes further options to
handle data and errors in the response from a client perspective.

See gh-10
2022-03-15 09:00:28 +00:00
rstoyanchev
15238072bb Introduce GraphQlResponse
Replace the use of ExecutionResult on the client side where we are
dealing with a response map rather, and also incorporate it into the
server-side hierarchy where it wraps an ExecutionResult instead.

See gh-10
2022-03-15 09:00:28 +00:00
rstoyanchev
f6b9fdfe7c Fix issue with matchesJson when JSONPath is a String
GraphQlTransport returns ExecutionResult with parsed JSON so for the
most part having MappingProvider is enough. However, when a JSONPath
evaluates to String (vs Map or List), the JsonSmartJsonProvider used by
default, throws UnsupportedOperationException from toJson.
2022-03-09 12:47:26 +00:00
rstoyanchev
71881f5e47 Expose convenience String url methods
See gh-317
2022-03-09 08:49:56 +00:00
Brian Clozel
c6d10d3ab8 Check for missing errors in GraphQlTester#executeAndVerify
Prior to this commit, the `GraphQlTester#executeAndVerify` method would
check that an `"$.errors"` JSON path exists within the response and
contains no value.

This should fail with valid GraphQL responses, as the spec says that a
response with no error should not contain the errors map at all:
http://spec.graphql.org/draft/#sec-Errors

This commit changes the assertion and instead checks for the absence of
the errors map in the response.

Fixes gh-318
2022-03-07 22:42:36 +01:00
rstoyanchev
1559c5989e Adapt CodecConfigurer to JSONPath MappingProvider
The JSON Encoder and Decoder implementations configured via
CodecConfigurer for HTTP and WebSocket are adapted to a JSONPath
MappingProvider and now automatically registered in JSONPath
configuration.

See gh-10, see gh-317
2022-03-07 10:39:59 +00:00
rstoyanchev
50c71d03fc Move TestWebSocketClient to testFixtures 2022-03-07 10:39:59 +00:00
rstoyanchev
d063eb760a Simplify filtered error handling in GraphQlTester
See gh-317
2022-03-07 10:39:59 +00:00
rstoyanchev
6480ab7e9f Polishing in GraphQlClient and GraphQlTester
See gh-10, see gh-317
2022-03-07 10:39:59 +00:00
rstoyanchev
e67cb5885e Rename ~Spec in GraphQlClient and GraphQlTester
As these are expected to be used as local variables, "Spec" reduces
readability and the IDE creates variables called "spec", which
increases that effect. Given those are nested within `GraphQlClient`
and `GraphQlTester`, it makes sense to drop the spec part and local
variable names such as request and response make sense.

See gh-10, see gh-317
2022-03-07 10:39:59 +00:00
rstoyanchev
53fb1d4dc0 Update and expand GraphQlTester tests
See gh-317
2022-03-07 10:39:59 +00:00
rstoyanchev
29b1aa2cc7 Introduce transport specific GraphQlTester extensions
See gh-317
2022-03-07 10:39:59 +00:00
rstoyanchev
1ae7eb742f Replace RequestStrategy with GraphQlTransport hierarchy
See gh-317
2022-03-07 10:39:59 +00:00
rstoyanchev
087202d9cb Simplify creation of RequestInput in tests
Introduce a TestRequestInput subclass to make the creation of
RequestInput in tests convenient.

See gh-310
2022-03-07 10:39:59 +00:00
rstoyanchev
b49c63f376 Extract GraphQlRequest and rename "query" to "document"
Extract GraphQlRequest, as a parent of RequestInput, that holds the
actual request inputs sent from the client side. RequestInput then
adds server-side transport details and ExecutionInput support.

Also replace "query" with "document" in GraphQlRequest and in
GraphQlClient.

Closes gh-310
2022-03-07 10:39:59 +00:00
rstoyanchev
2095e1795f Refine valueIsEmpty check 2022-02-08 17:02:30 +00:00
rstoyanchev
22985efe6a Expose ExecutionInput in WebOutput
WebOutput now exposes the ExecutionInput prepared for the request and
no longer provides access to the WebInput which is already available
to a WebInterceptor.

Closes gh-229
2022-01-10 10:10:49 +00:00
rstoyanchev
c84f342daf Extract RequestOutput base class
See gh-229
2022-01-10 10:10:49 +00:00
rstoyanchev
c9d41ce955 WebGraphQlTester allows charset in response MediaType
Closes gh-247
2022-01-10 10:10:49 +00:00
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