Support latest Rocket master

This commit is contained in:
tyranron 2021-05-11 18:04:31 +03:00
parent e998457c0e
commit 9c9639e8f0
No known key found for this signature in database
GPG key ID: 762E144FB230A4F0
2 changed files with 18 additions and 18 deletions

View file

@ -13,20 +13,20 @@ fn graphiql() -> content::Html<String> {
#[rocket::get("/graphql?<request>")] #[rocket::get("/graphql?<request>")]
fn get_graphql_handler( fn get_graphql_handler(
context: State<Database>, context: &State<Database>,
request: juniper_rocket_async::GraphQLRequest, request: juniper_rocket_async::GraphQLRequest,
schema: State<Schema>, schema: &State<Schema>,
) -> juniper_rocket_async::GraphQLResponse { ) -> juniper_rocket_async::GraphQLResponse {
request.execute_sync(&schema, &context) request.execute_sync(&*schema, &*context)
} }
#[rocket::post("/graphql", data = "<request>")] #[rocket::post("/graphql", data = "<request>")]
fn post_graphql_handler( fn post_graphql_handler(
context: State<Database>, context: &State<Database>,
request: juniper_rocket_async::GraphQLRequest, request: juniper_rocket_async::GraphQLRequest,
schema: State<Schema>, schema: &State<Schema>,
) -> juniper_rocket_async::GraphQLResponse { ) -> juniper_rocket_async::GraphQLResponse {
request.execute_sync(&schema, &context) request.execute_sync(&*schema, &*context)
} }
#[rocket::main] #[rocket::main]

View file

@ -170,16 +170,16 @@ impl GraphQLResponse {
/// #[rocket::get("/graphql?<request..>")] /// #[rocket::get("/graphql?<request..>")]
/// fn get_graphql_handler( /// fn get_graphql_handler(
/// cookies: &CookieJar, /// cookies: &CookieJar,
/// context: State<Database>, /// context: &State<Database>,
/// request: juniper_rocket_async::GraphQLRequest, /// request: juniper_rocket_async::GraphQLRequest,
/// schema: State<Schema>, /// schema: &State<Schema>,
/// ) -> juniper_rocket_async::GraphQLResponse { /// ) -> juniper_rocket_async::GraphQLResponse {
/// if cookies.get("user_id").is_none() { /// if cookies.get("user_id").is_none() {
/// let err = FieldError::new("User is not logged in", Value::null()); /// let err = FieldError::new("User is not logged in", Value::null());
/// return juniper_rocket_async::GraphQLResponse::error(err); /// return juniper_rocket_async::GraphQLResponse::error(err);
/// } /// }
/// ///
/// request.execute_sync(&schema, &context) /// request.execute_sync(&*schema, &*context)
/// } /// }
/// ``` /// ```
pub fn error(error: FieldError) -> Self { pub fn error(error: FieldError) -> Self {
@ -528,20 +528,20 @@ mod tests {
#[get("/?<request..>")] #[get("/?<request..>")]
fn get_graphql_handler( fn get_graphql_handler(
context: State<Database>, context: &State<Database>,
request: super::GraphQLRequest, request: super::GraphQLRequest,
schema: State<Schema>, schema: &State<Schema>,
) -> super::GraphQLResponse { ) -> super::GraphQLResponse {
request.execute_sync(&schema, &context) request.execute_sync(&*schema, &*context)
} }
#[post("/", data = "<request>")] #[post("/", data = "<request>")]
fn post_graphql_handler( fn post_graphql_handler(
context: State<Database>, context: &State<Database>,
request: super::GraphQLRequest, request: super::GraphQLRequest,
schema: State<Schema>, schema: &State<Schema>,
) -> super::GraphQLResponse { ) -> super::GraphQLResponse {
request.execute_sync(&schema, &context) request.execute_sync(&*schema, &*context)
} }
struct TestRocketIntegration { struct TestRocketIntegration {
@ -585,12 +585,12 @@ mod tests {
async fn test_operation_names() { async fn test_operation_names() {
#[post("/", data = "<request>")] #[post("/", data = "<request>")]
fn post_graphql_assert_operation_name_handler( fn post_graphql_assert_operation_name_handler(
context: State<Database>, context: &State<Database>,
request: super::GraphQLRequest, request: super::GraphQLRequest,
schema: State<Schema>, schema: &State<Schema>,
) -> super::GraphQLResponse { ) -> super::GraphQLResponse {
assert_eq!(request.operation_names(), vec![Some("TestQuery")]); assert_eq!(request.operation_names(), vec![Some("TestQuery")]);
request.execute_sync(&schema, &context) request.execute_sync(&*schema, &*context)
} }
let rocket = make_rocket_without_routes() let rocket = make_rocket_without_routes()