Skip to content

Commit

Permalink
Returns a valid GQL response #30
Browse files Browse the repository at this point in the history
  • Loading branch information
rimutaka committed Feb 9, 2022
1 parent c85ad6e commit bb9df83
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 5 deletions.
1 change: 1 addition & 0 deletions stm_graphql/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ This lambda looks for a JWT in `Authorization` header and returns HTTP 401 error
* ANY /{proxy+}
* `stm_graphql` Lambda
* `$default` stage
* CORS: configure all fields / headers in the form

## Debugging

Expand Down
10 changes: 6 additions & 4 deletions stm_graphql/src/handler.rs
Original file line number Diff line number Diff line change
Expand Up @@ -57,9 +57,7 @@ pub(crate) async fn my_handler(event: LambdaEvent<Value>) -> Result<Value, lambd

// log_memory_use(&mut sys, "Config init");

log_memory_use(&mut sys, "Tera init");

// decode possible URL path and query string
// decode possible URL path and query string
info!("Raw path: {}, Query: {}", &api_request.raw_path, &api_request.raw_query_string);
let url_path = decode(&api_request.raw_path).unwrap_or_default().trim().to_string();
let url_query = decode(&api_request.raw_query_string)
Expand All @@ -73,7 +71,11 @@ pub(crate) async fn my_handler(event: LambdaEvent<Value>) -> Result<Value, lambd
info!("Decoded path: {}, query: {}, dev: {:?}", url_path, url_query, dev);

// send the user request downstream for processing
let gql_data = r#"{"test":"some text"}"#;
let gql_data = r#"{
"data": {
"test": "Hello Vue!"
}
}"#;

log_memory_use(&mut sys, "GQL data returned");

Expand Down
4 changes: 3 additions & 1 deletion stm_graphql/src/http_options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ use std::collections::HashMap;
use crate::types::{ApiGatewayRequest, ApiGatewayResponse};
use tracing::info;

/// Returns an HTTP response specific to the OPTIONS request passed in.
/// Returns a dummy HTTP response regardless of the OPTIONS request passed in.
/// CORS headers are handled by the API Gateway and will overwrite what is prepared here if configured in the API GW.
///
/// See https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/OPTIONS
pub(crate) fn http_options_response(req: ApiGatewayRequest) -> ApiGatewayResponse {
info!("OPTIONS: {:?}", req);
Expand Down

0 comments on commit bb9df83

Please sign in to comment.