Skip to content

Commit

Permalink
fix(graphql_playground): use graphiql instead
Browse files Browse the repository at this point in the history
  • Loading branch information
rymnc committed Nov 21, 2024
1 parent 5e10eaa commit 7eb4acf
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 10 deletions.
49 changes: 49 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions crates/fuel-core/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ version = { workspace = true }
[dependencies]
anyhow = { workspace = true }
async-graphql = { version = "7.0.11", features = [
"graphiql",
"playground",
"tracing",
], default-features = false }
Expand Down
30 changes: 20 additions & 10 deletions crates/fuel-core/src/graphql_api/api_service.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,7 @@ use crate::{
},
};
use async_graphql::{
http::{
playground_source,
GraphQLPlaygroundConfig,
},
http::GraphiQLSource,
Request,
Response,
};
Expand Down Expand Up @@ -278,16 +275,22 @@ where
.extension(ViewExtension::new())
.finish();

let graphql_endpoint = "/v1/graphql";
let graphql_subscription_endpoint = "/v1/graphql-sub";

let graphql_playground =
|| render_graphql_playground(graphql_endpoint, graphql_subscription_endpoint);

let router = Router::new()
.route("/v1/playground", get(graphql_playground))
.route(
"/v1/graphql",
graphql_endpoint,
post(graphql_handler)
.layer(ConcurrencyLimitLayer::new(concurrency_limit))
.options(ok),
)
.route(
"/v1/graphql-sub",
graphql_subscription_endpoint,
post(graphql_subscription_handler).options(ok),
)
.route("/v1/metrics", get(metrics))
Expand Down Expand Up @@ -325,10 +328,17 @@ where
))
}

async fn graphql_playground() -> impl IntoResponse {
Html(playground_source(GraphQLPlaygroundConfig::new(
"/v1/graphql",
)))
async fn render_graphql_playground(
endpoint: &str,
subscription_endpoint: &str,
) -> impl IntoResponse {
Html(
GraphiQLSource::build()
.endpoint(endpoint)
.subscription_endpoint(subscription_endpoint)
.title("Fuel Graphql Playground")
.finish(),
)
}

async fn health() -> Json<serde_json::Value> {
Expand Down

0 comments on commit 7eb4acf

Please sign in to comment.