-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Add
query
resolvers into web UI (#9182)
### Description Adds the query resolvers such as `packages` and `file` into the web UI GraphQL server. This will allow us to display repo general info in studio. You can review this commit by commit ### Testing Instructions <!-- Give a quick description of steps to test your changes. -->
- Loading branch information
1 parent
e4f73a0
commit 6d4e655
Showing
14 changed files
with
115 additions
and
97 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 @@ | ||
|
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,55 @@ | ||
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::{event::WebUIEvent, server::SharedState}; | ||
|
||
use crate::{query, query::graphiql, run::Run}; | ||
|
||
pub async fn start_web_ui_server( | ||
rx: tokio::sync::mpsc::UnboundedReceiver<WebUIEvent>, | ||
run: Arc<Run>, | ||
) -> Result<(), turborepo_ui::Error> { | ||
let state = SharedState::default(); | ||
let subscriber = turborepo_ui::wui::subscriber::Subscriber::new(rx); | ||
tokio::spawn(subscriber.watch(state.clone())); | ||
|
||
run_server(state.clone(), run).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
#[derive(MergedObject)] | ||
struct Query(turborepo_ui::wui::RunQuery, query::RepositoryQuery); | ||
|
||
async fn run_server(state: 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
Oops, something went wrong.