-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
### Description We need the `currentRun` field to exist on `turbo query` to easily generate types from the GraphQL server. This adds the field and also deduplicates the server code so both `wui` and `query` use the same `run_server` code ### Testing Instructions
- Loading branch information
1 parent
672218b
commit c793376
Showing
7 changed files
with
69 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
use std::sync::Arc; | ||
|
||
use async_graphql::{EmptyMutation, EmptySubscription, MergedObject, Schema}; | ||
use async_graphql_axum::GraphQL; | ||
use axum::{http::Method, routing::get, Router}; | ||
use tokio::net::TcpListener; | ||
use tower_http::cors::{Any, CorsLayer}; | ||
use turborepo_ui::wui::query::SharedState; | ||
|
||
use crate::{query, query::graphiql, run::Run}; | ||
|
||
#[derive(MergedObject)] | ||
struct Query(turborepo_ui::wui::RunQuery, query::RepositoryQuery); | ||
|
||
pub async fn run_server( | ||
state: Option<SharedState>, | ||
run: Arc<Run>, | ||
) -> Result<(), turborepo_ui::Error> { | ||
let cors = CorsLayer::new() | ||
// allow `GET` and `POST` when accessing the resource | ||
.allow_methods([Method::GET, Method::POST]) | ||
.allow_headers(Any) | ||
// allow requests from any origin | ||
.allow_origin(Any); | ||
|
||
let web_ui_query = turborepo_ui::wui::RunQuery::new(state.clone()); | ||
let turbo_query = query::RepositoryQuery::new(run); | ||
let combined_query = Query(web_ui_query, turbo_query); | ||
|
||
let schema = Schema::new(combined_query, EmptyMutation, EmptySubscription); | ||
let app = Router::new() | ||
.route("/", get(graphiql).post_service(GraphQL::new(schema))) | ||
.layer(cors); | ||
|
||
axum::serve( | ||
TcpListener::bind("127.0.0.1:8000") | ||
.await | ||
.map_err(turborepo_ui::wui::Error::Server)?, | ||
app, | ||
) | ||
.await | ||
.map_err(turborepo_ui::wui::Error::Server)?; | ||
|
||
Ok(()) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters