Skip to content

Commit 0c17521

Browse files
authored
Merge pull request #57 from bvanneerven/graphiql-update
Update Playground to GraphiQL v2
2 parents 5846ade + b41f8f9 commit 0c17521

File tree

22 files changed

+187
-190
lines changed

22 files changed

+187
-190
lines changed

actix-web/error-extensions/src/main.rs

+8-5
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ extern crate thiserror;
33

44
use actix_web::{guard, web, web::Data, App, HttpResponse, HttpServer};
55
use async_graphql::{
6-
http::{playground_source, GraphQLPlaygroundConfig},
7-
EmptyMutation, EmptySubscription, ErrorExtensions, FieldError, FieldResult, Object, ResultExt,
8-
Schema,
6+
http::GraphiQLSource, EmptyMutation, EmptySubscription, ErrorExtensions, FieldError,
7+
FieldResult, Object, ResultExt, Schema,
98
};
109
use async_graphql_actix_web::{GraphQLRequest, GraphQLResponse};
1110

@@ -102,12 +101,16 @@ async fn index(
102101
async fn gql_playgound() -> HttpResponse {
103102
HttpResponse::Ok()
104103
.content_type("text/html; charset=utf-8")
105-
.body(playground_source(GraphQLPlaygroundConfig::new("/")))
104+
.body(
105+
GraphiQLSource::build()
106+
.endpoint("http://localhost:8000")
107+
.finish(),
108+
)
106109
}
107110

108111
#[actix_web::main]
109112
async fn main() -> std::io::Result<()> {
110-
println!("Playground: http://localhost:8000");
113+
println!("GraphiQL IDE: http://localhost:8000");
111114

112115
HttpServer::new(move || {
113116
App::new()

actix-web/starwars/src/main.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,20 @@
11
use actix_web::{guard, web, web::Data, App, HttpResponse, HttpServer, Result};
2-
use async_graphql::{
3-
http::{playground_source, GraphQLPlaygroundConfig},
4-
EmptyMutation, EmptySubscription, Schema,
5-
};
2+
use async_graphql::{http::GraphiQLSource, EmptyMutation, EmptySubscription, Schema};
63
use async_graphql_actix_web::{GraphQLRequest, GraphQLResponse};
74
use starwars::{QueryRoot, StarWars, StarWarsSchema};
85

96
async fn index(schema: web::Data<StarWarsSchema>, req: GraphQLRequest) -> GraphQLResponse {
107
schema.execute(req.into_inner()).await.into()
118
}
129

13-
async fn index_playground() -> Result<HttpResponse> {
14-
let source = playground_source(GraphQLPlaygroundConfig::new("/").subscription_endpoint("/"));
10+
async fn index_graphiql() -> Result<HttpResponse> {
1511
Ok(HttpResponse::Ok()
1612
.content_type("text/html; charset=utf-8")
17-
.body(source))
13+
.body(
14+
GraphiQLSource::build()
15+
.endpoint("http://localhost:8000")
16+
.finish(),
17+
))
1818
}
1919

2020
#[actix_web::main]
@@ -23,13 +23,13 @@ async fn main() -> std::io::Result<()> {
2323
.data(StarWars::new())
2424
.finish();
2525

26-
println!("Playground: http://localhost:8000");
26+
println!("GraphiQL IDE: http://localhost:8000");
2727

2828
HttpServer::new(move || {
2929
App::new()
3030
.app_data(Data::new(schema.clone()))
3131
.service(web::resource("/").guard(guard::Post()).to(index))
32-
.service(web::resource("/").guard(guard::Get()).to(index_playground))
32+
.service(web::resource("/").guard(guard::Get()).to(index_graphiql))
3333
})
3434
.bind("127.0.0.1:8000")?
3535
.run()

actix-web/subscription/src/main.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
use actix_web::{guard, web, web::Data, App, HttpRequest, HttpResponse, HttpServer, Result};
2-
use async_graphql::{
3-
http::{playground_source, GraphQLPlaygroundConfig},
4-
Schema,
5-
};
2+
use async_graphql::{http::GraphiQLSource, Schema};
63
use async_graphql_actix_web::{GraphQLRequest, GraphQLResponse, GraphQLSubscription};
74
use books::{BooksSchema, MutationRoot, QueryRoot, Storage, SubscriptionRoot};
85

96
async fn index(schema: web::Data<BooksSchema>, req: GraphQLRequest) -> GraphQLResponse {
107
schema.execute(req.into_inner()).await.into()
118
}
129

13-
async fn index_playground() -> Result<HttpResponse> {
10+
async fn index_graphiql() -> Result<HttpResponse> {
1411
Ok(HttpResponse::Ok()
1512
.content_type("text/html; charset=utf-8")
16-
.body(playground_source(
17-
GraphQLPlaygroundConfig::new("/").subscription_endpoint("/"),
18-
)))
13+
.body(
14+
GraphiQLSource::build()
15+
.endpoint("http://localhost:8000")
16+
.subscription_endpoint("ws://localhost:8000")
17+
.finish(),
18+
))
1919
}
2020

2121
async fn index_ws(
@@ -32,7 +32,7 @@ async fn main() -> std::io::Result<()> {
3232
.data(Storage::default())
3333
.finish();
3434

35-
println!("Playground: http://localhost:8000");
35+
println!("GraphiQL IDE: http://localhost:8000");
3636

3737
HttpServer::new(move || {
3838
App::new()
@@ -44,7 +44,7 @@ async fn main() -> std::io::Result<()> {
4444
.guard(guard::Header("upgrade", "websocket"))
4545
.to(index_ws),
4646
)
47-
.service(web::resource("/").guard(guard::Get()).to(index_playground))
47+
.service(web::resource("/").guard(guard::Get()).to(index_graphiql))
4848
})
4949
.bind("127.0.0.1:8000")?
5050
.run()

actix-web/token-from-header/src/main.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
use actix_web::{
22
guard, http::header::HeaderMap, web, App, HttpRequest, HttpResponse, HttpServer, Result,
33
};
4-
use async_graphql::{
5-
http::{playground_source, GraphQLPlaygroundConfig},
6-
Data, EmptyMutation, Schema,
7-
};
4+
use async_graphql::{http::GraphiQLSource, Data, EmptyMutation, Schema};
85
use async_graphql_actix_web::{GraphQLRequest, GraphQLResponse, GraphQLSubscription};
96
use token::{on_connection_init, QueryRoot, SubscriptionRoot, Token, TokenSchema};
107

11-
async fn gql_playground() -> HttpResponse {
8+
async fn graphiql() -> HttpResponse {
129
HttpResponse::Ok()
1310
.content_type("text/html; charset=utf-8")
14-
.body(playground_source(
15-
GraphQLPlaygroundConfig::new("/").subscription_endpoint("/ws"),
16-
))
11+
.body(
12+
GraphiQLSource::build()
13+
.endpoint("http://localhost:8000")
14+
.subscription_endpoint("ws://localhost:8000/ws")
15+
.finish(),
16+
)
1717
}
1818

1919
fn get_token_from_headers(headers: &HeaderMap) -> Option<Token> {
@@ -54,12 +54,12 @@ async fn index_ws(
5454
async fn main() -> std::io::Result<()> {
5555
let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot);
5656

57-
println!("Playground: http://localhost:8000");
57+
println!("GraphiQL IDE: http://localhost:8000");
5858

5959
HttpServer::new(move || {
6060
App::new()
6161
.app_data(web::Data::new(schema.clone()))
62-
.service(web::resource("/").guard(guard::Get()).to(gql_playground))
62+
.service(web::resource("/").guard(guard::Get()).to(graphiql))
6363
.service(web::resource("/").guard(guard::Post()).to(index))
6464
.service(web::resource("/ws").to(index_ws))
6565
})

actix-web/upload/src/main.rs

+7-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
use actix_web::{guard, web, web::Data, App, HttpResponse, HttpServer};
22
use async_graphql::{
3-
http::{playground_source, GraphQLPlaygroundConfig, MultipartOptions},
3+
http::{GraphiQLSource, MultipartOptions},
44
EmptySubscription, Schema,
55
};
66
use async_graphql_actix_web::{GraphQLRequest, GraphQLResponse};
@@ -13,7 +13,11 @@ async fn index(schema: web::Data<FilesSchema>, req: GraphQLRequest) -> GraphQLRe
1313
async fn gql_playgound() -> HttpResponse {
1414
HttpResponse::Ok()
1515
.content_type("text/html; charset=utf-8")
16-
.body(playground_source(GraphQLPlaygroundConfig::new("/")))
16+
.body(
17+
GraphiQLSource::build()
18+
.endpoint("http://localhost:8000")
19+
.finish(),
20+
)
1721
}
1822

1923
#[actix_web::main]
@@ -22,7 +26,7 @@ async fn main() -> std::io::Result<()> {
2226
.data(Storage::default())
2327
.finish();
2428

25-
println!("Playground: http://localhost:8000");
29+
println!("GraphiQL IDE: http://localhost:8000");
2630

2731
HttpServer::new(move || {
2832
App::new()

axum/starwars/src/main.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use async_graphql::{
2-
http::{playground_source, GraphQLPlaygroundConfig},
3-
EmptyMutation, EmptySubscription, Schema,
4-
};
1+
use async_graphql::{http::GraphiQLSource, EmptyMutation, EmptySubscription, Schema};
52
use async_graphql_axum::{GraphQLRequest, GraphQLResponse};
63
use axum::{
74
extract::Extension,
@@ -18,8 +15,12 @@ async fn graphql_handler(
1815
schema.execute(req.into_inner()).await.into()
1916
}
2017

21-
async fn graphql_playground() -> impl IntoResponse {
22-
response::Html(playground_source(GraphQLPlaygroundConfig::new("/")))
18+
async fn graphiql() -> impl IntoResponse {
19+
response::Html(
20+
GraphiQLSource::build()
21+
.endpoint("http://localhost:8000")
22+
.finish(),
23+
)
2324
}
2425

2526
#[tokio::main]
@@ -29,10 +30,10 @@ async fn main() {
2930
.finish();
3031

3132
let app = Router::new()
32-
.route("/", get(graphql_playground).post(graphql_handler))
33+
.route("/", get(graphiql).post(graphql_handler))
3334
.layer(Extension(schema));
3435

35-
println!("Playground: http://localhost:8000");
36+
println!("GraphiQL IDE: http://localhost:8000");
3637

3738
Server::bind(&"0.0.0.0:8000".parse().unwrap())
3839
.serve(app.into_make_service())

axum/subscription/src/main.rs

+10-10
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use async_graphql::{
2-
http::{playground_source, GraphQLPlaygroundConfig},
3-
Schema,
4-
};
1+
use async_graphql::{http::GraphiQLSource, Schema};
52
use async_graphql_axum::{GraphQLRequest, GraphQLResponse, GraphQLSubscription};
63
use axum::{
74
extract::Extension,
@@ -15,10 +12,13 @@ async fn graphql_handler(schema: Extension<BooksSchema>, req: GraphQLRequest) ->
1512
schema.execute(req.into_inner()).await.into()
1613
}
1714

18-
async fn graphql_playground() -> impl IntoResponse {
19-
response::Html(playground_source(
20-
GraphQLPlaygroundConfig::new("/").subscription_endpoint("/ws"),
21-
))
15+
async fn graphiql() -> impl IntoResponse {
16+
response::Html(
17+
GraphiQLSource::build()
18+
.endpoint("http://localhost:8000")
19+
.subscription_endpoint("ws://localhost:8000/ws")
20+
.finish(),
21+
)
2222
}
2323

2424
#[tokio::main]
@@ -28,11 +28,11 @@ async fn main() {
2828
.finish();
2929

3030
let app = Router::new()
31-
.route("/", get(graphql_playground).post(graphql_handler))
31+
.route("/", get(graphiql).post(graphql_handler))
3232
.route("/ws", GraphQLSubscription::new(schema.clone()))
3333
.layer(Extension(schema));
3434

35-
println!("Playground: http://localhost:8000");
35+
println!("GraphiQL IDE: http://localhost:8000");
3636

3737
Server::bind(&"0.0.0.0:8000".parse().unwrap())
3838
.serve(app.into_make_service())

axum/upload/src/main.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use async_graphql::{
2-
http::{playground_source, GraphQLPlaygroundConfig},
3-
EmptySubscription, Schema,
4-
};
1+
use async_graphql::{http::GraphiQLSource, EmptySubscription, Schema};
52
use async_graphql_axum::{GraphQLRequest, GraphQLResponse};
63
use axum::{
74
extract::Extension,
@@ -17,8 +14,12 @@ async fn graphql_handler(schema: Extension<FilesSchema>, req: GraphQLRequest) ->
1714
schema.execute(req.0).await.into()
1815
}
1916

20-
async fn graphql_playground() -> impl IntoResponse {
21-
Html(playground_source(GraphQLPlaygroundConfig::new("/")))
17+
async fn graphiql() -> impl IntoResponse {
18+
Html(
19+
GraphiQLSource::build()
20+
.endpoint("http://localhost:8000")
21+
.finish(),
22+
)
2223
}
2324

2425
#[tokio::main]
@@ -27,10 +28,10 @@ async fn main() {
2728
.data(Storage::default())
2829
.finish();
2930

30-
println!("Playground: http://localhost:8000");
31+
println!("GraphiQL IDE: http://localhost:8000");
3132

3233
let app = Router::new()
33-
.route("/", get(graphql_playground).post(graphql_handler))
34+
.route("/", get(graphiql).post(graphql_handler))
3435
.layer(Extension(schema))
3536
.layer(
3637
CorsLayer::new()

poem/starwars/src/main.rs

+9-8
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
1-
use async_graphql::{
2-
http::{playground_source, GraphQLPlaygroundConfig},
3-
EmptyMutation, EmptySubscription, Schema,
4-
};
1+
use async_graphql::{http::GraphiQLSource, EmptyMutation, EmptySubscription, Schema};
52
use async_graphql_poem::GraphQL;
63
use poem::{get, handler, listener::TcpListener, web::Html, IntoResponse, Route, Server};
74
use starwars::{QueryRoot, StarWars};
85

96
#[handler]
10-
async fn graphql_playground() -> impl IntoResponse {
11-
Html(playground_source(GraphQLPlaygroundConfig::new("/")))
7+
async fn graphiql() -> impl IntoResponse {
8+
Html(
9+
GraphiQLSource::build()
10+
.endpoint("http://localhost:8000")
11+
.finish(),
12+
)
1213
}
1314

1415
#[tokio::main]
@@ -17,9 +18,9 @@ async fn main() {
1718
.data(StarWars::new())
1819
.finish();
1920

20-
let app = Route::new().at("/", get(graphql_playground).post(GraphQL::new(schema)));
21+
let app = Route::new().at("/", get(graphiql).post(GraphQL::new(schema)));
2122

22-
println!("Playground: http://localhost:8000");
23+
println!("GraphiQL IDE: http://localhost:8000");
2324
Server::new(TcpListener::bind("0.0.0.0:8000"))
2425
.run(app)
2526
.await

poem/subscription-redis/src/main.rs

+10-13
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,4 @@
1-
use async_graphql::{
2-
http::{playground_source, GraphQLPlaygroundConfig},
3-
Context, Object, Result, Schema, Subscription,
4-
};
1+
use async_graphql::{http::GraphiQLSource, Context, Object, Result, Schema, Subscription};
52
use async_graphql_poem::{GraphQL, GraphQLSubscription};
63
use futures_util::{Stream, StreamExt};
74
use poem::{get, handler, listener::TcpListener, web::Html, IntoResponse, Route, Server};
@@ -43,10 +40,13 @@ impl SubscriptionRoot {
4340
}
4441

4542
#[handler]
46-
async fn graphql_playground() -> impl IntoResponse {
47-
Html(playground_source(
48-
GraphQLPlaygroundConfig::new("/").subscription_endpoint("/ws"),
49-
))
43+
async fn graphiql() -> impl IntoResponse {
44+
Html(
45+
GraphiQLSource::build()
46+
.endpoint("http://localhost:8000")
47+
.subscription_endpoint("ws://localhost:8000/ws")
48+
.finish(),
49+
)
5050
}
5151

5252
#[tokio::main]
@@ -58,13 +58,10 @@ async fn main() {
5858
.finish();
5959

6060
let app = Route::new()
61-
.at(
62-
"/",
63-
get(graphql_playground).post(GraphQL::new(schema.clone())),
64-
)
61+
.at("/", get(graphiql).post(GraphQL::new(schema.clone())))
6562
.at("/ws", get(GraphQLSubscription::new(schema)));
6663

67-
println!("Playground: http://localhost:8000");
64+
println!("GraphiQL IDE: http://localhost:8000");
6865
Server::new(TcpListener::bind("0.0.0.0:8000"))
6966
.run(app)
7067
.await

0 commit comments

Comments
 (0)