|
1 | 1 | use actix_web::{ |
2 | 2 | guard, http::header::HeaderMap, web, App, HttpRequest, HttpResponse, HttpServer, Result, |
3 | 3 | }; |
4 | | -use async_graphql::{ |
5 | | - http::{playground_source, GraphQLPlaygroundConfig}, |
6 | | - Data, EmptyMutation, Schema, |
7 | | -}; |
| 4 | +use async_graphql::{http::GraphiQLSource, Data, EmptyMutation, Schema}; |
8 | 5 | use async_graphql_actix_web::{GraphQLRequest, GraphQLResponse, GraphQLSubscription}; |
9 | 6 | use token::{on_connection_init, QueryRoot, SubscriptionRoot, Token, TokenSchema}; |
10 | 7 |
|
11 | | -async fn gql_playground() -> HttpResponse { |
| 8 | +async fn graphiql() -> HttpResponse { |
12 | 9 | HttpResponse::Ok() |
13 | 10 | .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 | + ) |
17 | 17 | } |
18 | 18 |
|
19 | 19 | fn get_token_from_headers(headers: &HeaderMap) -> Option<Token> { |
@@ -54,12 +54,12 @@ async fn index_ws( |
54 | 54 | async fn main() -> std::io::Result<()> { |
55 | 55 | let schema = Schema::new(QueryRoot, EmptyMutation, SubscriptionRoot); |
56 | 56 |
|
57 | | - println!("Playground: http://localhost:8000"); |
| 57 | + println!("GraphiQL IDE: http://localhost:8000"); |
58 | 58 |
|
59 | 59 | HttpServer::new(move || { |
60 | 60 | App::new() |
61 | 61 | .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)) |
63 | 63 | .service(web::resource("/").guard(guard::Post()).to(index)) |
64 | 64 | .service(web::resource("/ws").to(index_ws)) |
65 | 65 | }) |
|
0 commit comments