-
Notifications
You must be signed in to change notification settings - Fork 425
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- rework `rocket_server` example as `simple` - provide example in `GraphQLRequest` API docs - mention GET query format in `GraphQLRequest` API docs and `simple` example Additionally: - fix `operationName` query parameter handling - make `graphiql_source()` and `playground_source()` polymorphic over `subscriptions_endpoint_url` argument - provide examples in `graphiql_source()` and `playground_source()` API docs - move integration HTTP tests to a separate file - test both sync and async `juniper_rocket` in integration HTTP tests - polish `FromForm` unit tests
- Loading branch information
Showing
7 changed files
with
371 additions
and
238 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
This file was deleted.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
use juniper::{ | ||
tests::fixtures::starwars::schema::{Database, Query}, | ||
EmptyMutation, EmptySubscription, RootNode, | ||
}; | ||
use rocket::{response::content::RawHtml, routes, State}; | ||
|
||
type Schema = RootNode<'static, Query, EmptyMutation<Database>, EmptySubscription<Database>>; | ||
|
||
#[rocket::get("/")] | ||
async fn homepage() -> RawHtml<&'static str> { | ||
RawHtml( | ||
"<html><h1>juniper_rocket/simple example</h1>\ | ||
<div>visit <a href=\"/graphiql\">GraphiQL</a></div>\ | ||
<div>visit <a href=\"/playground\">GraphQL Playground</a></div>\ | ||
</html>", | ||
) | ||
} | ||
|
||
#[rocket::get("/graphiql")] | ||
fn graphiql() -> RawHtml<String> { | ||
juniper_rocket::graphiql_source("/graphql", None) | ||
} | ||
|
||
#[rocket::get("/playground")] | ||
fn playground() -> RawHtml<String> { | ||
juniper_rocket::playground_source("/graphql", None) | ||
} | ||
|
||
// GET request accepts query parameters like these: | ||
// ?query=<urlencoded-graphql-query-string> | ||
// &operationName=<optional-name> | ||
// &variables=<optional-json-encoded-variables> | ||
// See details here: https://graphql.org/learn/serving-over-http#get-request | ||
#[rocket::get("/graphql?<request..>")] | ||
async fn get_graphql( | ||
db: &State<Database>, | ||
request: juniper_rocket::GraphQLRequest, | ||
schema: &State<Schema>, | ||
) -> juniper_rocket::GraphQLResponse { | ||
request.execute(schema, db).await | ||
} | ||
|
||
#[rocket::post("/graphql", data = "<request>")] | ||
async fn post_graphql( | ||
db: &State<Database>, | ||
request: juniper_rocket::GraphQLRequest, | ||
schema: &State<Schema>, | ||
) -> juniper_rocket::GraphQLResponse { | ||
request.execute(schema, db).await | ||
} | ||
|
||
#[rocket::main] | ||
async fn main() { | ||
_ = rocket::build() | ||
.manage(Database::new()) | ||
.manage(Schema::new( | ||
Query, | ||
EmptyMutation::new(), | ||
EmptySubscription::new(), | ||
)) | ||
.mount( | ||
"/", | ||
routes![homepage, graphiql, playground, get_graphql, post_graphql], | ||
) | ||
.launch() | ||
.await | ||
.expect("server to launch"); | ||
} |
Oops, something went wrong.