Add TestHarness, and assorted API breaking changes#1487
Conversation
|
For now CI will fail for (at least) two reasons:
|
|
Not sure if it's in the scope of this pr, but it would be great if we tested our plugins against a yaml! configuration instead of let config = serde_json::json!({
"plugins": {
"my_example.catch_query_planner_error": {
"enabled": true ,
}
}
});
apollo_router::TestHarness::builder()
.configuration_json(config)
.unwrap()
.build()
.await
.unwrap();
}This would allow us to catch yml related issues earlier |
@SimonSapin you spoiled me! I was expecting |
|
Any chance we can fix the requirement of an alias while we're at it ? use apollo_router::layers::ServiceExt;
use tower::{ServiceExt as _}; |
|
We could definitely add Renaming |
|
We could have a convenience builder method for |
501574b to
fe7b712
Compare
The `Router` type already implements `Service` and `Clone`.
They alias Result<Response, BoxError>
88790c6 to
56690db
Compare
o0Ignition0o
left a comment
There was a problem hiding this comment.
LGTM!
I'd like to take a moment to acknowledge the HUGE amount of work you had to do to come up with such a big, and so well documented PR.
This one touches everything, and the same level of care and attention to detail has been given to each file, and each function.
I know I have suffered review fatigue while reading this, so I can't imagine the amount of work and concentration preparing such a changeset required. And I won't even mention the number of rebases and merge conflicts you had to go through.
Again kudos for the very nice modules and functions documentation. This is really great work!
NEXT_CHANGELOG.md
Outdated
There was a problem hiding this comment.
tremendous effort on the changelog, that's really GREAT WORK 🎉
NIT: you can now update the PR #
apollo-router/src/executable.rs
Outdated
apollo-router/src/layers/mod.rs
Outdated
apollo-router/src/plugin/mod.rs
Outdated
There was a problem hiding this comment.
oh that s a leftover from the apollo-router apollo-router-core split!
apollo-router/src/plugins/csrf.rs
Outdated
| //! Utilities which make it easy to test with [`crate::plugin`]. | ||
|
|
||
| mod mock; | ||
| #[macro_use] |
There was a problem hiding this comment.
why do we need this ? 🤔
There was a problem hiding this comment.
Because we removed #[macro_export] elsewhere
| /// On the subgraph side, this test harness never makes network requests to subgraphs | ||
| /// unless [`with_subgraph_network_requests`][Self::with_subgraph_network_requests] is called. |
| *body = stream | ||
| .map(move |mut resp| { | ||
| resp.data = mock_data.clone(); | ||
| resp | ||
| }) | ||
| .boxed(); |
There was a problem hiding this comment.
is this why we need futures::StreamExt?
This feels a bit inconvenient, I m not sure I would assume plugin writers to be able to wield this, especially when learning rust :/
There was a problem hiding this comment.
Yes, this was an ugly way to get this test to compile. I’ve added a helper in #1525
| /// Returns a builder to start an HTTP server in a separate Tokio task. | ||
| /// | ||
| /// Builder methods: | ||
| /// | ||
| /// * `.schema(impl Into<`[`SchemaSource`]`>)` | ||
| /// Required. | ||
| /// Specifies where to find the supergraph schema definition. | ||
| /// Some sources support hot-reloading. | ||
| /// | ||
| /// * `.configuration(impl Into<`[`ConfigurationSource`]`>)` | ||
| /// Optional. | ||
| /// Specifies where to find the router configuration. | ||
| /// If not provided, the default configuration as with an empty YAML file. | ||
| /// | ||
| /// * `.shutdown(impl Into<`[`ShutdownSource`]`>)` | ||
| /// Optional. | ||
| /// Specifies when the server should gracefully shut down. | ||
| /// If not provided, the default is [`ShutdownSource::CtrlC`]. | ||
| /// | ||
| /// * `.start()` | ||
| /// Finishes the builder, | ||
| /// starts an HTTP server in a separate Tokio task, | ||
| /// and returns a `RouterHttpServer` handle. | ||
| /// | ||
| /// The server handle can be used in multiple ways. | ||
| /// As a [`Future`], it resolves to `Result<(), `[`ApolloRouterError`]`>` | ||
| /// either when the server has finished gracefully shutting down | ||
| /// or when it encounters a fatal error that prevents it from starting. | ||
| /// | ||
| /// If the handle is dropped before being awaited as a future, | ||
| /// a graceful shutdown is triggered. | ||
| /// In order to wait until shutdown finishes, | ||
| /// use the [`shutdown`][Self::shutdown] method instead. |
|
@SimonSapin I didn't see you enabled automerge, let's followup on the comment's I ve written next week! |
Follows up on #1487 (comment) Related to #1219
Follows up on #1487 (comment) Related to #1219
This PR makes a number of changes, many of them breaking. Each commit should be self-contained, though. The highlights are:
TestHarnessAPI that replaces bothPluginTestHarness(which is removed) andPluggableRouterServiceBuilder(which becomes private)servicesmodule was also made private. It is replaced in the public API by a newstagesmodule that contains sub-modules for each pipeline stage (query_planner,execution, etc) which in turn contain items likeRequest,BoxService, etc.For more details, see
NEXT_CHANGELOG.md,apollo-router/src/test_harness.rs, andapollo-router/src/stages.rs. Much of the other changes are very mechanical.Many choices proposed in this PR are opinionated but everything is open to discussion.
It should probably have been multiple smaller PRs. I got a bit carried away, sorry. For review I suggest going commit-by-commit.