Skip to content

Commit b64104f

Browse files
committed
Deprecate HTTP-specific handlers in favor of query and mutation
1 parent b705720 commit b64104f

1 file changed

Lines changed: 23 additions & 8 deletions

File tree

  • crates/rapid-web-codegen/src

crates/rapid-web-codegen/src/lib.rs

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -51,14 +51,24 @@ struct Handler {
5151
is_nested: bool,
5252
}
5353

54-
// Currently, the rapid file-based router will only support GET, POST, DELETE, and PUT request formats (we could support patch if needed)
54+
// Route handler enum for different HTTP methods
55+
// Note: The Get, Post, Delete, Put, and Patch handlers are deprecated.
56+
// Only Query and Mutation should be used going forward.
5557
enum RouteHandler {
56-
Query(Handler),
57-
Mutation(Handler),
58+
// Preferred handlers
59+
Query(Handler), // For read operations (replaces Get)
60+
Mutation(Handler), // For write operations (replaces Post, Put, Delete, Patch)
61+
62+
// Deprecated handlers - will be removed in a future release
63+
#[deprecated(since = "next", note = "Use `Query` instead")]
5864
Get(Handler),
65+
#[deprecated(since = "next", note = "Use `Mutation` instead")]
5966
Post(Handler),
67+
#[deprecated(since = "next", note = "Use `Mutation` instead")]
6068
Delete(Handler),
69+
#[deprecated(since = "next", note = "Use `Mutation` instead")]
6170
Put(Handler),
71+
#[deprecated(since = "next", note = "Use `Mutation` instead")]
6272
Patch(Handler),
6373
}
6474

@@ -390,9 +400,9 @@ fn generate_handler_tokens(route_handler: Handler, parsed_path: &str, handler_ty
390400

391401
// Output our idents based on the handler types
392402
match handler_type {
393-
// Check if we got a query or mutation..
403+
// Recommended handler types - these should be used going forward
394404
"query" => {
395-
// If we got a query type we want to generate routes for `get` request types (`delete` could get moved to here too...?)
405+
// If we got a query type we want to generate routes for `get` request types
396406
quote!(
397407
.route(#rapid_routes_path, web::get().to(#handler::#parsed_handler_type)#(#middleware_idents)*)
398408
)
@@ -407,8 +417,8 @@ fn generate_handler_tokens(route_handler: Handler, parsed_path: &str, handler_ty
407417
.route(#rapid_routes_path, web::delete().to(#handler::#parsed_handler_type)#(#middleware_idents)*)
408418
)
409419
}
410-
// Currently we still support declaring handlers with a very specific HTTP type (ex: `get` or `post` etc)
411-
// ^^^ Eventually, what was described above should get deprecated
420+
// Deprecated handler types - these will be removed in a future release
421+
// Use `query` instead of `get` and `mutation` instead of `post`, `put`, `delete`, and `patch`
412422
_ => quote!(.route(#rapid_routes_path, web::#parsed_handler_type().to(#handler::#parsed_handler_type)#(#middleware_idents)*)),
413423
}
414424
}
@@ -417,16 +427,21 @@ fn generate_handler_tokens(route_handler: Handler, parsed_path: &str, handler_ty
417427
/// If it does, we want to push the valid handler to the handlers array
418428
/// Note: no need to support HEAD and OPTIONS requests
419429
fn parse_handlers(route_handlers: &mut Vec<RouteHandler>, file_contents: String, handler: Handler) {
420-
// TODO: we need to depricate everything except for `query` and `mutation`
430+
// Process the HTTP-specific handlers with deprecation warnings
421431
if file_contents.contains("async fn get") && validate_route_handler(&file_contents) {
432+
eprintln!("Warning: 'get' handler is deprecated and will be removed in a future release. Please use 'query' instead.");
422433
route_handlers.push(RouteHandler::Get(handler))
423434
} else if file_contents.contains("async fn post") && validate_route_handler(&file_contents) {
435+
eprintln!("Warning: 'post' handler is deprecated and will be removed in a future release. Please use 'mutation' instead.");
424436
route_handlers.push(RouteHandler::Post(handler))
425437
} else if file_contents.contains("async fn delete") && validate_route_handler(&file_contents) {
438+
eprintln!("Warning: 'delete' handler is deprecated and will be removed in a future release. Please use 'mutation' instead.");
426439
route_handlers.push(RouteHandler::Delete(handler))
427440
} else if file_contents.contains("async fn put") && validate_route_handler(&file_contents) {
441+
eprintln!("Warning: 'put' handler is deprecated and will be removed in a future release. Please use 'mutation' instead.");
428442
route_handlers.push(RouteHandler::Put(handler))
429443
} else if file_contents.contains("async fn patch") && validate_route_handler(&file_contents) {
444+
eprintln!("Warning: 'patch' handler is deprecated and will be removed in a future release. Please use 'mutation' instead.");
430445
route_handlers.push(RouteHandler::Patch(handler))
431446
} else if file_contents.contains("async fn query") && validate_route_handler(&file_contents) {
432447
route_handlers.push(RouteHandler::Query(handler))

0 commit comments

Comments
 (0)